2023-10-20 03:14 PM
Hello,
I have a discovery board with stm32f407vg-t6.There is a mems sensor on it and I am trying to read sensor values via I2C. However, my code is not working. I also upload my code.
I checked my code 4 times and couldn't find any mistake. I even messed up the code a little bit to be sure all the parameters were set correctly.
I connected physically the pins on the board like this below:
Please help me to find the problem in this code.
2023-10-24 04:33 AM
Hello @electrovanga ,
You can configure the I2C from STM32CubeMx then you can generate the code and manage it, it's easier.
Also, could you please check the STM32F4-Discovery_FW package.
It offers the BSP appropriate drivers and the Mems accelerometer component that can help you to develop your application based on F4Cube FW :
https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Drivers/BSP/Components/lis302dl
https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Drivers/BSP/STM32F4-Discovery
You can try also to read data from sensor via HAL drivers.
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-10-24 04:46 AM
Hi @Foued_KH,
I am learning bare metal programming with STM32. I will not use HALlibrary. I will also use bare metal programming after I learnt it in my job. Therefore, It is so critical me to undertstand the issue here. Could you help me, please?
2023-10-26 12:40 PM
Any help from your side, please? I feel like my question just answered to be answered only. I hope ST's attidute is not like this way and more supporting.
2023-10-26 01:41 PM
This is primarily a user-to-user forum, if you expect ST and other engineers to parachute in you're probably going to be disappointed.
Part of Bare Metal is to Read The Manual and Figure It Out. The reference manuals do describe the HW adequately. Part of the curve here is learning how to read and interpret the manual, and how to observe what's happening inside the peripherals.
One of the routes to understand how something works, is to take something that does work (HAL / Cube Examples), and contrast it to how yours does or doesn't work. You can't on one hand dismiss that as a valid course of action because you don't want to do it, and on the other hand expect people to pick through your code to figure out why it's not working the way you want it too.
You can take parts of the code and swap them out, bisect, figure out if it's an initialization thing.
I will note that doing dozens of RMW (Load/Store) actions on a peripheral register is not efficient, if that's the purpose of using bare metal over other paths.
2023-10-26 04:31 PM
@electrovanga If you want urgent help with your project, you can look here.
2023-10-27 12:07 AM
Dear So Smart @Pavel A.,
Thanks for your answer. First of all, I didn't write it is urgent. Second, if you read my post, you can easily see that I am learning Bare metal programming to improve myself and do some hobby stuff. I am stucked at this point for 3 weeks already and searching on the web. If you want to help, please help. Otherwise, don't write unnecessary comment here like how I have to do now because of you. The time is wasted.
You're right. I agree about what you say. I am stucked here and can't go further since 3 weeks. I need a guidance about fix that part or that part. This is missing and so on. Otherwise, I can't learn if I don't get feedback.
If the ST support is like this than I go with Texas Instrument and try it. I am learning and even in this phase for non urgent stuff if the community is not supportive, I can't imagine when I use this in professional environment. I don't wonder why my friends are using TI boards now.
2023-10-30 02:37 AM
Hello @electrovanga ,
Could you please read the section 27.3 I2C functional description in the Reference Manual : st.com/resource/en/reference_manual/rm0090-stm32f405415-stm32f407417-stm32f427437-and-stm32f429439-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
For I2C read you should :
1. Enable I2C and GPIO clocks ( RCC_AHBxENR & RCC_APBxENR )
2. Configure the I2C pins (GPIOx registers )
3. manage the I2C periph ( I2C_CR1 )
4. I2C clock ( I2C_CR2 )
5. I2C write ( I2C_DR ) + clear ADDR bit
6. Wait for RxNE to set ( I2C_SR1) + clear ACK bit
6. I2C read ( I2C_DR )
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-10-30 01:20 PM
Hi Fouded,
Thanks for your answer. I have no issue with my I2C function. However, I can't find the issue.
Some fellows said that I can't use gyro sensor on discovery board with I2C as it is connected to the SPI. Is this correct? I have rectengular mems sensor on board.