2019-01-13 09:05 AM
Hi all.
I'm working on my own board and using 3 separate I2C devices. MPU sensor, current sensor, and an IO expander, all having their own bus. For testing purposes, I've relied on the CubeMX code to generate the base code for me. Only one of the I2C (I2C4) busses work. My oscilloscope confirms nothing is sent out of I2C1 and I2C2. HAL returns HAL_TIMEOUT too
Has anyone had else had similar issues with this?
Thanks
2019-01-13 09:33 AM
>>Has anyone had else had similar issues with this?
The forum is full of people who have problems with CubeMx, the numbers with problems tends to outweigh those with solutions.
Check all the clocks are enabled for GPIO, and I2C peripherals.
Check all the pins are correctly configured and associated with each peripheral/bus.
Check that each has its own instance/handle.
Check that each has its own interrupt handle and associated callback and dispatch.
Use the debugger to probe the peripheral registers, and instance structures.
Add instrumentation to understand flow and interaction.
2019-01-13 11:02 AM
you still need to initialize your I2C, you need the right code, in Keil you can give a try to see if LED blinks
if(HAL_I2C_IsDeviceReady(&hi2c1, 0xD8, 2, 10) == HAL_OK)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
0xDB is sample slave address, it tries 2 times and the timeout is 10 ms, the LED is ofcourse on port A pin 5 in this case.
The probelm with STM is that they do not give you any sample codes to learn. In Arduino you can program right away THE IDE is very simple and there tons of some progmram to learn. Here is nothing.
2019-01-13 12:14 PM
If you need to get something working fast, have a look at my shared I2C bus shared activity in this forum. It provides SW I2C Bus on any GPIO of STM32. Once you get things working, you can replace the SW I2C by HW I2C.