Skip to content

Wire fixes for repeated start(slave) and multiple .write in onRequestEvent() #1221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions libraries/Wire/src/utility/twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,10 @@ i2c_status_e i2c_slave_write_IT(i2c_t *obj, uint8_t *data, uint16_t size)
} else {
// Check the communication status
for (i = 0; i < size; i++) {
obj->i2cTxRxBuffer[i] = *(data + i);
obj->i2cTxRxBuffer[obj->i2cTxRxBufferSize + i] = *(data + i);
}

obj->i2cTxRxBufferSize = size;
obj->i2cTxRxBufferSize += size;
}
return ret;
}
Expand Down Expand Up @@ -980,12 +980,18 @@ void i2c_attachSlaveTxEvent(i2c_t *obj, void (*function)(i2c_t *))
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode)
{
i2c_t *obj = get_i2c_obj(hi2c);
if ((obj->slaveMode == SLAVE_MODE_RECEIVE) && (obj->slaveRxNbData != 0)) {
obj->i2c_onSlaveReceive(obj);
obj->slaveMode = SLAVE_MODE_LISTEN;
obj->slaveRxNbData = 0;
}

if (AddrMatchCode == hi2c->Init.OwnAddress1) {
if (TransferDirection == I2C_DIRECTION_RECEIVE) {
obj->slaveMode = SLAVE_MODE_TRANSMIT;

if (obj->i2c_onSlaveTransmit != NULL) {
obj->i2cTxRxBufferSize = 0;
obj->i2c_onSlaveTransmit(obj);
}
#if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F2xx) || defined(STM32F3xx) ||\
Expand Down