mbed library sources
Fork of mbed-src by
Diff: targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/i2c_api.c
- Revision:
- 208:4557f4bb2dd5
- Parent:
- 181:a4cbdfbbd2f4
- Child:
- 227:7bd0639b8911
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/i2c_api.c Fri May 23 08:45:06 2014 +0100 +++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/i2c_api.c Fri May 23 10:30:07 2014 +0100 @@ -181,7 +181,7 @@ I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); int timeout; int count; - + i2c_start(obj); // Send slave address for write @@ -245,7 +245,7 @@ I2C_SendData(i2c, (uint8_t)data); // Wait until the byte is transmitted - timeout = FLAG_TIMEOUT; + timeout = FLAG_TIMEOUT; while ((I2C_GetFlagStatus(i2c, I2C_FLAG_TXE) == RESET) && (I2C_GetFlagStatus(i2c, I2C_FLAG_BTF) == RESET)) { timeout--; @@ -299,10 +299,9 @@ uint32_t event; I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); - event = I2C_GetLastEvent( i2c ); - if(event != 0) - { - switch(event){ + event = I2C_GetLastEvent(i2c); + if (event != 0) { + switch (event) { case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED: retValue = WriteAddressed; break; @@ -317,24 +316,24 @@ break; } - // clear ADDR - if((retValue == WriteAddressed) || (retValue == ReadAddressed)){ + // clear ADDR + if ((retValue == WriteAddressed) || (retValue == ReadAddressed)) { // read SR to clear ADDR flag i2c->SR1; i2c->SR2; } // clear stopf - if(I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) { + if (I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) { // read SR1 and write CR1 to clear STOP flag i2c->SR1; - I2C_Cmd(i2c, ENABLE); + I2C_Cmd(i2c, ENABLE); } // clear AF - if(I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) { + if (I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) { I2C_ClearFlag(i2c, I2C_FLAG_AF); - } + } } - return(retValue); + return (retValue); } int i2c_slave_read(i2c_t *obj, char *data, int length) {