@@ -68,22 +68,15 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
6868 rxBuffer.store_char (sercom->readDataWIRE ());
6969
7070 // Connected to slave
71- // while(toRead--)
72- for (byteRead = 0 ; byteRead < quantity; ++byteRead)
71+ for (byteRead = 1 ; byteRead < quantity; ++byteRead)
7372 {
74- if ( byteRead == quantity - 1 ) // Stop transmission
75- {
76- sercom->prepareNackBitWIRE (); // Prepare NACK to stop slave transmission
77- // sercom->readDataWIRE(); // Clear data register to send NACK
78- sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP); // Send Stop
79- }
80- else // Continue transmission
81- {
82- sercom->prepareAckBitWIRE (); // Prepare Acknowledge
83- sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_READ); // Prepare the ACK command for the slave
84- rxBuffer.store_char ( sercom->readDataWIRE () ); // Read data and send the ACK
85- }
73+ sercom->prepareAckBitWIRE (); // Prepare Acknowledge
74+ sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_READ); // Prepare the ACK command for the slave
75+ rxBuffer.store_char (sercom->readDataWIRE ()); // Read data and send the ACK
8676 }
77+ sercom->prepareNackBitWIRE (); // Prepare NACK to stop slave transmission
78+ // sercom->readDataWIRE(); // Clear data register to send NACK
79+ sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP); // Send Stop
8780 }
8881
8982 return byteRead;
@@ -134,12 +127,8 @@ uint8_t TwoWire::endTransmission(bool stopBit)
134127 sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP);
135128 return 3 ; // Nack or error
136129 }
137-
138- if (txBuffer.available () == 0 )
139- {
140- sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP);
141- }
142130 }
131+ sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP);
143132
144133 return 0 ;
145134}
0 commit comments