Arduino: Use readBytes for cart read
The Wire documentation only shows read() to get data from the I²C stream. However, Wire inherits from Stream, so it gets access to all the same functions, like readBytes(), which can read more than one character. Replace the innermost loop of the cartridge load by readBytes instead of calling read() in a loop.
This commit is contained in:
parent
610ccc630a
commit
fab5d22364
1 changed files with 1 additions and 3 deletions
|
@ -75,9 +75,7 @@ void loop() {
|
||||||
// Arduino I2C buffer is 32 bytes, so we need multiple requests per page.
|
// Arduino I2C buffer is 32 bytes, so we need multiple requests per page.
|
||||||
for (int j = 0; j < i2c_buff_per_page; j++) {
|
for (int j = 0; j < i2c_buff_per_page; j++) {
|
||||||
Wire.requestFrom(eeprom_addr, i2c_buff_size);
|
Wire.requestFrom(eeprom_addr, i2c_buff_size);
|
||||||
for (int k = 0; k < i2c_buff_size; k++) {
|
Wire.readBytes(pageData + i2c_buff_size*j, i2c_buff_size);
|
||||||
pageData[i2c_buff_size*j + k] = Wire.read();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to send the full page via serial until the recipient ACKs.
|
// Try to send the full page via serial until the recipient ACKs.
|
||||||
|
|
Loading…
Add table
Reference in a new issue