Skip to content

Commit

Permalink
Merge pull request #250 from boramonideep/wire_fix
Browse files Browse the repository at this point in the history
added wait for ACK after a I2C transaction
  • Loading branch information
boramonideep committed Aug 30, 2023
2 parents 70b950a + 95b1f0e commit 901967a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres
XMC_I2C_CH_MasterStart(XMC_I2C_config->channel, (txAddress << 1), XMC_I2C_CH_CMD_READ);
}

timeout = WIRE_COMMUNICATION_TIMEOUT;
// wait for ACK or timeout incase no ACK is received, a time-based wait-state is added since XMC devices run at variable frequencies
while(((XMC_I2C_CH_GetStatusFlag(XMC_I2C_config->channel) & XMC_I2C_CH_STATUS_FLAG_ACK_RECEIVED) == 0U) || timeout == 0)
{
delay(1);
timeout--;
}

for (uint8_t count = 0; count < (quantity - 1); count ++)
{
XMC_I2C_CH_MasterReceiveAck(XMC_I2C_config->channel);
Expand Down

0 comments on commit 901967a

Please sign in to comment.