Skip to content

Commit 8293f88

Browse files
committed
Fix I2C slave issue: return correct size
Fix stm32duino#212 Signed-off-by: Frederic.Pillon <[email protected]>
1 parent d5ef001 commit 8293f88

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Diff for: cores/arduino/stm32/twi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
539539

540540
if((obj->i2c_onSlaveReceive != NULL) &&
541541
(obj->slaveMode == SLAVE_MODE_RECEIVE)) {
542-
nbData = I2C_TXRX_BUFFER_SIZE - obj->handle.XferCount;
542+
nbData = I2C_TXRX_BUFFER_SIZE - obj->handle.XferSize;
543543
if(nbData != 0) {
544544
obj->i2c_onSlaveReceive(obj->i2cTxRxBuffer, nbData);
545545
}

Diff for: libraries/Wire/src/Wire.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,12 @@ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
381381
return;
382382
}
383383

384+
allocateRxBuffer(numBytes);
385+
// error if no memory block available to allocate the buffer
384386
if(rxBuffer == nullptr){
385-
allocateRxBuffer(numBytes);
386-
// error if no memory block available to allocate the buffer
387-
if(rxBuffer == nullptr){
388-
Error_Handler();
389-
}
387+
Error_Handler();
390388
}
389+
391390
// copy twi rx buffer into local read buffer
392391
// this enables new reads to happen in parallel
393392
memcpy(rxBuffer, inBytes, numBytes);

0 commit comments

Comments
 (0)