cancel
Showing results for 
Search instead for 
Did you mean: 

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

harinath
Associate III
Posted on October 31, 2012 at 13:25

Hi

I have written code for communicating with two I2C devices which are connected to I2C1 of STM32F The code works fine. The connection diagram & code can be seen on another thread :

/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/I2C2 hangs at while(!I2C_CheckEvent(LSM_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); 8113&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=441

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

http://dekar.wc3edit.net/st website/an28zip

�?

described 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);

Thanks #optimized-i2c-example #stm32
1 REPLY 1
harinath
Associate III
Posted on October 31, 2012 at 14:21

I have found some links which point to the newer libraries from ST: [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AN2824 STM32F10xxx I%C2%B2C optimized examples&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=130]click here

It says that

Application Note AN2824

 is OLD. Newer I2C libraries are located here:   

There is also an example when three I2C devices connected to same I2C of STM32 as below.

0690X00000604xIQAQ.png

I will post here if i get any problems in using the new library. 

Thanks