Skip to content

Commit 4eee8a6

Browse files
diegosueiroMaureenHelm
authored andcommitted
drivers/i2c/i2c_imx: Check for I2C bus busy before starting transaction
In some cases the minimum time between Stop and Start was not being considered when starting a new transfer. This patches adds a checking on the I2C Bus Busy flag before starting a new transaction. Signed-off-by: Diego Sueiro <[email protected]>
1 parent a25c273 commit 4eee8a6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/i2c/i2c_imx.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,21 @@ static int i2c_imx_transfer(struct device *dev, struct i2c_msg *msgs,
179179
struct i2c_imx_data *data = DEV_DATA(dev);
180180
struct i2c_master_transfer *transfer = &data->transfer;
181181
u8_t *buf, *buf_end;
182+
u16_t timeout = UINT16_MAX;
182183
int result = -EIO;
183184

184185
if (!num_msgs) {
185186
return 0;
186187
}
187188

189+
/* Wait until bus not busy */
190+
while ((I2C_I2SR_REG(base) & i2cStatusBusBusy) && (--timeout)) {
191+
}
192+
193+
if (timeout == 0) {
194+
return result;
195+
}
196+
188197
/* Make sure we're in a good state so slave recognises the Start */
189198
I2C_SetWorkMode(base, i2cModeSlave);
190199
transfer->currentMode = i2cModeSlave;

0 commit comments

Comments
 (0)