From fab5d2236464075de3f34bb945bbba2d5ed357a0 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 17 Dec 2023 13:20:48 +0000 Subject: [PATCH] Arduino: Use readBytes for cart read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Arduino/SendCart/SendCart.ino | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Arduino/SendCart/SendCart.ino b/Arduino/SendCart/SendCart.ino index 6bb0292..f617563 100644 --- a/Arduino/SendCart/SendCart.ino +++ b/Arduino/SendCart/SendCart.ino @@ -75,9 +75,7 @@ void loop() { // Arduino I2C buffer is 32 bytes, so we need multiple requests per page. for (int j = 0; j < i2c_buff_per_page; j++) { Wire.requestFrom(eeprom_addr, i2c_buff_size); - for (int k = 0; k < i2c_buff_size; k++) { - pageData[i2c_buff_size*j + k] = Wire.read(); - } + Wire.readBytes(pageData + i2c_buff_size*j, i2c_buff_size); } // Try to send the full page via serial until the recipient ACKs.