cancel
Showing results for 
Search instead for 
Did you mean: 

I2C MASTER TRANSMIT IS NOT WORKING

WM_IR
Senior

I have tested the  

HAL_I2C_Master_Transmit(&hi2c1, 0x68, some_data, 10, HAL_MAX_DELAY);

in my nucleo stm32f302r8. But, It is not working, when I go to debug, the program retun HAL error at checking the NACK is detected or not. below is picture:

0693W00000NsjHCQAZ.jpg 

Here is my simple basic code:

0693W00000NsjHHQAZ.jpg 

Can someone help me on this problem?

6 REPLIES 6
MM..1
Chief III

In command

HAL_I2C_Master_Transmit(&hi2c1, 0x68, some_data, 10, HAL_MAX_DELAY);

10 mean 10 bytes and your some data have only 5. Maybe memory protection halt you.

Second mistake is HAL_MAX_DELAY, better is use real delay value for situation with bus problem.

Plus your I2C init maybe is fail, other pins etc.

Al​

Already changed to 5 bytes..and the time i just put 10. Is it ok? But still not working. And about the i2c init pin, im using the cubemx where it automatically generate the code. I dont see the initialization is the problem.​

CubeMX set I2C pins on selection I2C to default pins, but exist alternate positions and Nucleo boards dont use alltime defaults.

Then, how should i configure the pin?​

MM..1
Chief III

I only write you need check if pins in CubeMX is real pins you connect to I2C on Nucleo plus on this pins pull ups external. Without this your code dont work.

And ofcourse on address 0x68 you need real function device for Acknowledge.