STM32F407 I2C not Acknowledging

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Kunal Gupta
Posts: 10
Joined: Tue Jul 20, 2021 6:31 pm
Has thanked: 1 time

STM32F407 I2C not Acknowledging

Postby Kunal Gupta » Tue Aug 17, 2021 7:13 am

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.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F407 I2C not Acknowledging

Postby Giovanni » Tue Aug 17, 2021 7:16 am

Hi,

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

Giovanni

Kunal Gupta
Posts: 10
Joined: Tue Jul 20, 2021 6:31 pm
Has thanked: 1 time

Re: STM32F407 I2C not Acknowledging

Postby Kunal Gupta » Tue Aug 17, 2021 7:47 am

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.

Kunal Gupta
Posts: 10
Joined: Tue Jul 20, 2021 6:31 pm
Has thanked: 1 time

Re: STM32F407 I2C not Acknowledging

Postby Kunal Gupta » Tue Aug 17, 2021 7:49 am

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 ????

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F407 I2C not Acknowledging

Postby Giovanni » Tue Aug 17, 2021 10:40 am

I don't see i2cStart() called in there.

Enable assertions in chconf.h

Giovanni

Kunal Gupta
Posts: 10
Joined: Tue Jul 20, 2021 6:31 pm
Has thanked: 1 time

Re: STM32F407 I2C not Acknowledging

Postby Kunal Gupta » Tue Aug 17, 2021 11:21 am

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??

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F407 I2C not Acknowledging

Postby Giovanni » Tue Aug 17, 2021 1:19 pm

Look at the stack trace up to the assert, the wrong condition is your problem.

Giovanni

psyco
Posts: 21
Joined: Fri May 22, 2020 1:40 am
Been thanked: 11 times

Re: STM32F407 I2C not Acknowledging

Postby psyco » Wed Aug 18, 2021 2:38 am

In addition, you need to add PAL_STM32_OTYPE_OPENDRAIN to your I2C pad mode calls.

Kunal Gupta
Posts: 10
Joined: Tue Jul 20, 2021 6:31 pm
Has thanked: 1 time

Re: STM32F407 I2C not Acknowledging

Postby Kunal Gupta » Tue Aug 24, 2021 7:20 am

where is this macro defined???

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32F407 I2C not Acknowledging

Postby Giovanni » Tue Aug 24, 2021 8:18 am

Hi,

It is defined in the PAL driver.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 10 guests