Page 1 of 2

STM32F407 I2C not Acknowledging

Posted: Tue Aug 17, 2021 7:13 am
by Kunal Gupta
I have written a simple I2C Code for stm32f407 using the chibios HAL for interfacing mag QMC5883.
It's a Basic Single thread code, just trying to understand the Chibios HAL API for different peripherals.
Code is this: https://github.com/gkunalupta/RTOS-Chib ... OVERY2-I2C

But on running the code, it always gives Error +4, meaning Slave address Not ack, on checking in logic anal;yzer too, it shows as shown in below pic.
I have checked Connection many times and verified the API I am using from documentation, but I am not able to make out why is it still not working.
WhatsApp Image 2021-08-17 at 11.23.55.jpeg

WhatsApp Image 2021-08-17 at 11.18.45.jpeg


Any kind of inputs or insights will be very valuable.
I am guessing Maybe I am using the wrong API or some fault is in the firmware end only which I am not able to mark out.

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 17, 2021 7:16 am
by Giovanni
Hi,

A common error is to give the wrong address, the ChibiOS API requires the numeric address value (without the RW bit).

Giovanni

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 17, 2021 7:47 am
by Kunal Gupta
I know and have checked that thing, as you can see in the logic analyzer,
MAG I2C 7 bit slave address is 0b0001101
and that is what I am sending from code and its reflected in Logic Analyzer output.

I even tried with another I2C slave device, but it every time shows this, I2C slave address not Ack.

I am not getting what is the error I am making, stuck on it since past 3-4 days.

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 17, 2021 7:49 am
by Kunal Gupta
What I mark out just know is that in logic analyzer output, as you can see
after the start signal both SCL and SDA lines are kept low for a period of time,
can that be the reason ????

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 17, 2021 10:40 am
by Giovanni
I don't see i2cStart() called in there.

Enable assertions in chconf.h

Giovanni

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 17, 2021 11:21 am
by Kunal Gupta
Well, i2cstart() is called, it is not visible in the pic you can checkout main.c from git repo which I shared.

And when I enable the Debug assertion in chconf.h, I got following thing
WhatsApp Image 2021-08-17 at 15.50.27.jpeg


does this mean my i2c clock is not ser properly??
what I can interpret from thus??

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 17, 2021 1:19 pm
by Giovanni
Look at the stack trace up to the assert, the wrong condition is your problem.

Giovanni

Re: STM32F407 I2C not Acknowledging

Posted: Wed Aug 18, 2021 2:38 am
by psyco
In addition, you need to add PAL_STM32_OTYPE_OPENDRAIN to your I2C pad mode calls.

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 24, 2021 7:20 am
by Kunal Gupta
where is this macro defined???

Re: STM32F407 I2C not Acknowledging

Posted: Tue Aug 24, 2021 8:18 am
by Giovanni
Hi,

It is defined in the PAL driver.

Giovanni