Skip to content

Commit 0d6720c

Browse files
authored
I2C slave: enable matching any configured slave address (#1801)
1 parent 08334ff commit 0d6720c

File tree

1 file changed

+14
-16
lines changed
  • libraries/Wire/src/utility

1 file changed

+14
-16
lines changed

Diff for: libraries/Wire/src/utility/twi.c

+14-16
Original file line numberDiff line numberDiff line change
@@ -1074,24 +1074,22 @@ void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, ui
10741074
obj->slaveRxNbData = 0;
10751075
}
10761076

1077-
if (AddrMatchCode == hi2c->Init.OwnAddress1) {
1078-
if (TransferDirection == I2C_DIRECTION_RECEIVE) {
1079-
obj->slaveMode = SLAVE_MODE_TRANSMIT;
1077+
if (TransferDirection == I2C_DIRECTION_RECEIVE) {
1078+
obj->slaveMode = SLAVE_MODE_TRANSMIT;
10801079

1081-
if (obj->i2c_onSlaveTransmit != NULL) {
1082-
obj->i2cTxRxBufferSize = 0;
1083-
obj->i2c_onSlaveTransmit(obj);
1084-
}
1085-
HAL_I2C_Slave_Seq_Transmit_IT(hi2c, (uint8_t *) obj->i2cTxRxBuffer,
1086-
obj->i2cTxRxBufferSize, I2C_LAST_FRAME);
1087-
} else {
1088-
obj->slaveRxNbData = 0;
1089-
obj->slaveMode = SLAVE_MODE_RECEIVE;
1090-
/* We don't know in advance how many bytes will be sent by master so
1091-
* we'll fetch one by one until master ends the sequence */
1092-
HAL_I2C_Slave_Seq_Receive_IT(hi2c, (uint8_t *) & (obj->i2cTxRxBuffer[obj->slaveRxNbData]),
1093-
1, I2C_NEXT_FRAME);
1080+
if (obj->i2c_onSlaveTransmit != NULL) {
1081+
obj->i2cTxRxBufferSize = 0;
1082+
obj->i2c_onSlaveTransmit(obj);
10941083
}
1084+
HAL_I2C_Slave_Seq_Transmit_IT(hi2c, (uint8_t *) obj->i2cTxRxBuffer,
1085+
obj->i2cTxRxBufferSize, I2C_LAST_FRAME);
1086+
} else {
1087+
obj->slaveRxNbData = 0;
1088+
obj->slaveMode = SLAVE_MODE_RECEIVE;
1089+
/* We don't know in advance how many bytes will be sent by master so
1090+
* we'll fetch one by one until master ends the sequence */
1091+
HAL_I2C_Slave_Seq_Receive_IT(hi2c, (uint8_t *) & (obj->i2cTxRxBuffer[obj->slaveRxNbData]),
1092+
1, I2C_NEXT_FRAME);
10951093
}
10961094
}
10971095

0 commit comments

Comments
 (0)