mirror of https://github.com/ARMmbed/mbed-os.git
Fix I2C byte transfer API to enable Master/Slave test on F411RE
i2c_byte_write could be used to send byte and address. In case used for address, ADDR Flag should be reset.pull/2852/head
parent
ee0f0e5464
commit
9b204f8be2
|
@ -213,8 +213,19 @@ inline int i2c_start(i2c_t *obj) {
|
|||
|
||||
inline int i2c_stop(i2c_t *obj) {
|
||||
|
||||
int timeout;
|
||||
struct i2c_s *obj_s = I2C_S(obj);
|
||||
I2C_TypeDef *i2c = (I2C_TypeDef *)obj_s->i2c;
|
||||
I2C_HandleTypeDef *handle = &(obj_s->handle);
|
||||
|
||||
//Wait Byte transfer finished before sending stop
|
||||
timeout = FLAG_TIMEOUT;
|
||||
while (__HAL_I2C_GET_FLAG(handle, I2C_FLAG_BTF) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the STOP condition
|
||||
i2c->CR1 |= I2C_CR1_STOP;
|
||||
|
@ -350,15 +361,21 @@ int i2c_byte_write(i2c_t *obj, int data) {
|
|||
|
||||
handle->Instance->DR = (uint8_t)data;
|
||||
|
||||
// Wait until the byte is transmitted
|
||||
// Wait until the byte (might be the adress) is transmitted
|
||||
timeout = FLAG_TIMEOUT;
|
||||
while ((__HAL_I2C_GET_FLAG(handle, I2C_FLAG_TXE) == RESET) &&
|
||||
(__HAL_I2C_GET_FLAG(handle, I2C_FLAG_BTF) == RESET)) {
|
||||
(__HAL_I2C_GET_FLAG(handle, I2C_FLAG_BTF) == RESET) &&
|
||||
(__HAL_I2C_GET_FLAG(handle, I2C_FLAG_ADDR) == RESET)) {
|
||||
if ((timeout--) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (__HAL_I2C_GET_FLAG(handle, I2C_FLAG_ADDR) != RESET)
|
||||
{
|
||||
__HAL_I2C_CLEAR_ADDRFLAG(handle);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
// pull-up resistors on both lines
|
||||
// ********************************************************
|
||||
|
||||
#if defined(TARGET_NUCLEO_F411RE)
|
||||
I2C master(PB_9, PB_8); // I2C_1 (Arduino: D14/D15)
|
||||
I2CSlave slave(PB_3, PB_10); // I2C_2 (Arduino: D3/D6)
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
|
@ -87,6 +87,7 @@ Wiring:
|
|||
|
||||
* i2c_loop:
|
||||
* LPC1768: (p28 <-> p9), (p27 <-> p10)
|
||||
* NUCLEO_F411RE: (PB_9 <-> PB_3), (PB_8 <-> PB_10)
|
||||
|
||||
* i2c_eeprom:
|
||||
* LPC1*: (SDA=p28 , SCL=p27)
|
||||
|
@ -264,7 +265,7 @@ TESTS = [
|
|||
"id": "MBED_A20", "description": "I2C master/slave test",
|
||||
"source_dir": join(TEST_DIR, "mbed", "i2c_master_slave"),
|
||||
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB,],
|
||||
"mcu": ["LPC1768", "RZ_A1H"],
|
||||
"mcu": ["LPC1768", "RZ_A1H", "NUCLEO_F411RE"],
|
||||
"peripherals": ["i2c_loop"]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue