Skip to content

Commit 5adc40a

Browse files
authored
Merge pull request #1055 from pennam/i2c-slave
I2CSlave: fix slave write regression
2 parents 9db78f9 + 6231980 commit 5adc40a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

libraries/Wire/Wire.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ size_t arduino::MbedI2C::write(const uint8_t* data, int len) {
124124
int arduino::MbedI2C::read() {
125125
int rv = -1;
126126
core_util_critical_section_enter();
127-
128127
if (rxBuffer.available()) {
129128

130129
rv = rxBuffer.read_char();
@@ -160,9 +159,12 @@ void arduino::MbedI2C::receiveThd() {
160159
}
161160
if (usedTxBuffer != 0) {
162161
core_util_critical_section_enter();
163-
slave->write((const char *) txBuffer, usedTxBuffer);
164-
core_util_critical_section_exit();
162+
uint8_t tempTxBuffer[256];
163+
uint8_t usedTempTxBuffer = usedTxBuffer;
164+
memcpy(tempTxBuffer, txBuffer, usedTempTxBuffer);
165165
usedTxBuffer = 0;
166+
core_util_critical_section_exit();
167+
slave->write((const char *) tempTxBuffer, usedTempTxBuffer);
166168
}
167169
//slave->stop();
168170
break;

0 commit comments

Comments
 (0)