mirror of https://github.com/ARMmbed/mbed-os.git
Fix I2C issue with test mbed_hal_fpga_ci_test_shield
On last case #5 there was a last unexpected read. It happened when stop condition was generatedpull/11334/head
parent
7910de2f38
commit
de121a308a
|
@ -598,8 +598,6 @@ int i2c_stop(i2c_t *obj)
|
|||
return 0;
|
||||
}
|
||||
#endif
|
||||
// Disable reload mode
|
||||
handle->Instance->CR2 &= (uint32_t)~I2C_CR2_RELOAD;
|
||||
|
||||
// Ensure the transmission is started before sending a stop
|
||||
if ((handle->Instance->CR2 & (uint32_t)I2C_CR2_RD_WRN) == 0) {
|
||||
|
@ -612,7 +610,7 @@ int i2c_stop(i2c_t *obj)
|
|||
}
|
||||
|
||||
// Generate the STOP condition
|
||||
handle->Instance->CR2 |= I2C_CR2_STOP;
|
||||
handle->Instance->CR2 = I2C_CR2_STOP;
|
||||
|
||||
timeout = FLAG_TIMEOUT;
|
||||
while (!__HAL_I2C_GET_FLAG(handle, I2C_FLAG_STOPF)) {
|
||||
|
@ -665,9 +663,16 @@ int i2c_byte_read(i2c_t *obj, int last)
|
|||
}
|
||||
}
|
||||
|
||||
/* Enable reload mode as we don't know how many bytes will be sent */
|
||||
/* and set transfer size to 1 */
|
||||
tmpreg |= I2C_CR2_RELOAD | (I2C_CR2_NBYTES & (1 << 16));
|
||||
if (last) {
|
||||
/* Disable Address Acknowledge */
|
||||
tmpreg = tmpreg & (~I2C_CR2_RELOAD);
|
||||
tmpreg |= I2C_CR2_NACK | (I2C_CR2_NBYTES & (1 << 16));
|
||||
} else {
|
||||
/* Enable reload mode as we don't know how many bytes will be sent */
|
||||
/* and set transfer size to 1 */
|
||||
tmpreg |= I2C_CR2_RELOAD | (I2C_CR2_NBYTES & (1 << 16));
|
||||
}
|
||||
|
||||
/* Set the prepared configuration */
|
||||
handle->Instance->CR2 = tmpreg;
|
||||
|
||||
|
@ -681,11 +686,6 @@ int i2c_byte_read(i2c_t *obj, int last)
|
|||
/* Then Get Byte */
|
||||
data = handle->Instance->RXDR;
|
||||
|
||||
if (last) {
|
||||
/* Disable Address Acknowledge */
|
||||
handle->Instance->CR2 |= I2C_CR2_NACK;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue