AnsweredAssumed Answered

Using STM32 "Optimized I2C examples" when two I2C devices connected to one I2C port.

Question asked by Reddy.Harinadha on Oct 31, 2012
Latest reply on Oct 31, 2012 by Reddy.Harinadha
I have written code for communicating with two I2C devices which are connected to I2C1 of STM32F103. The code works fine. The connection diagram & code can be seen on another thread : Click here This code uses standard peripheral libraries v3.3.0.

Though the present version of my code works fine, It is not recommendable to use in Multi threaded application when using RTOS (has while loops, Enter/Exit Critical sections, etc..).
Now I want to use STM32F10xxx optimized I2C examplesdescribed in Application note: AN2824 . But problem is the examples doesn't have functions when two devices connected on same I2C port. This optimized I2C example has only two functions to read from/write to one fixed register or slave ( when two Microcontrollers connected via their I2C), but when we are communicating with a I2C chip, it will have several registers to access for example in this situation.
The optimized I2C library function prototypes are as below:
Status I2C_Master_BufferRead(I2C_TypeDef* I2Cx, uint8_t* pBuffer,  uint32_t NumByteToRead, I2C_ProgrammingModel Mode, uint8_t SlaveAddress);
Status I2C_Master_BufferWrite(I2C_TypeDef* I2Cx, uint8_t* pBuffer,  uint32_t NumByteToWrite, I2C_ProgrammingModel Mode, uint8_t SlaveAddress );

Would someone suggest how to develop functions like below, but using Optimized I2C library ?
void MPU6050_I2C_BufferRead(u8 slaveAddr, u8* pBuffer, u8 ReadAddr, u16 NumByteToRead);
void MPU6050_I2C_ByteWrite(u8 slaveAddr, u8* pBuffer, u8 writeAddr);