@@ -68,22 +68,15 @@ uint8_t TwoWire::requestFrom(uint8_t address, size_t quantity, bool stopBit)
68
68
rxBuffer.store_char (sercom->readDataWIRE ());
69
69
70
70
// Connected to slave
71
- // while(toRead--)
72
- for (byteRead = 0 ; byteRead < quantity; ++byteRead)
71
+ for (byteRead = 1 ; byteRead < quantity; ++byteRead)
73
72
{
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
86
76
}
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
87
80
}
88
81
89
82
return byteRead;
@@ -134,12 +127,8 @@ uint8_t TwoWire::endTransmission(bool stopBit)
134
127
sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP);
135
128
return 3 ; // Nack or error
136
129
}
137
-
138
- if (txBuffer.available () == 0 )
139
- {
140
- sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP);
141
- }
142
130
}
131
+ sercom->prepareCommandBitsWire (WIRE_MASTER_ACT_STOP);
143
132
144
133
return 0 ;
145
134
}
0 commit comments