2022-02-01 07:10 AM
Hi team,
I am trying to generate I2C driver code using STM32CubeIDE, to understand perpheral functions. I was successful in generating the code but i cant find the functions which I am looking for like I2C_Init(), I2C_cmd, I2C_GetFlagStatus() ...
Could you guys please help me in locating these function on generated code. I am attaching the generated i2c source and header files. I am intrested in low level (LL) program.
I would be greatful, if you can suggest me with good tutorial videos on the same.
Please consider me as a beginner in the coding environment.
Regards,
Irine C Jose
2022-02-01 08:23 AM
Hello @IJose.1 and welcome to the Community :)
I advise you to get inspired from the working I2C example available under the STM32CubeF4 MCU package:
\STM32Cube_FW_F4_V1.26.2\Projects\
\STM32Cube_FW_F4_V1.26.2\Projects\STM32F411RE-Nucleo\Examples_LL\I2C\
Have a look also at this FAQ: STM32 I2C does not work, which describes few tips related to I2C on STM32 devices.
Hope this helps you!
When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.
Imen
2022-02-01 08:43 AM
In addition to the advice from @Imen DAHMEN:
I2C_Init(), I2C_cmd and I2C_GetFlagStatus() are functions as they were used with the SPL (Standard Peripheral Library) in good ol' times and you still had to configure and check many things by hand. In the meantime, STM32CubeMX and STM32CubeIDE are tools that do a lot of the work for you and provide the basic configuration.
If you are still a beginner in programming, you should start with STM32CubeIDE and create a project in which you select the desired STM32, enable I2C and if you absolutely want to use LL, then switch from HAL to LL in the Project Manager (click on HAL).
Good luck!
Regards
/Peter
2022-02-01 09:41 AM
LL will only give you the init routine.
HAL is very complicated, hard to read, And this is definitely not the place to study a low level driver.
Il you want a low level driver for I2C have a look to
https://stm32f4-discovery.net/2014/05/library-09-i2c-for-stm32f4xx/
This is only for F4, but you don't indicate which MCU you are using.
For L4, G4, G0, H7 have a look to: http://adastra-soft.com/an-easy-to-use-i2c-library-for-stm32h7xx/
2022-02-02 02:15 AM
Hi @Imen DAHMEN
Thank you for your response.
Let me go through this and will let you know if I have any more doubts.
2022-02-02 02:17 AM
Thank you all for your responses.
2022-02-10 08:28 AM
Thank you for the help.
The library was really useful.
STM32F411VE this is the board i am using and i want to learn about i2c. so i considered the connection with LSM303DLHC.
I want to develope a test case the dut. SO while going through the library file, i came across a function:
extern uint8_t TM_I2C_ReadNoRegister(I2C_TypeDef* I2Cx, uint8_t address);
I have doubt here. If we donot specify the register, is there any default register address value to which data will be writter to or read from.
Also if there any material to learn in detail about the test cases of the i2c communication and testing agent kindly let me know.
2022-02-10 10:51 AM
Some devices has an auto register address increment. So you can specify the register address at the 1st access, then read/write next registers without specifying the address.
If you want to learn and test I2C start with a simple device like an EEPROM. When you will be confident wityh your I2C skill, then switch to more complex device.
The LSM303DLHC is a complex device, and the difficuly is not with the I2C bus but the chip config/use.
There is many resources on the WEB to start with I2C.
2022-02-10 10:59 AM
Thank you for your response. Can you please help me with any resources if possible.
Also can you please suggest what will be the better option other than LM303DLHC for the i2c communication.
2022-02-10 11:27 AM
Try something like the ST24C02: M24C02-W - 2 Kbit serial I2C bus EEPROM - STMicroelectronics
Or one from another supplier(Beware select a 3.3V device!).