STM32F4 I2C Not Recognizing Ack

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

raphaelchang
Posts: 6
Joined: Sat Jul 23, 2016 7:50 am
Been thanked: 1 time

STM32F4 I2C Not Recognizing Ack

Post by raphaelchang »

I am developing code for an STM32F405 controller to communicate with a Wireless Wii Nunchuk through I2C (I2CD1). I am unable to get ChibiOS to report a successful transaction; I2CGetErrors keeps returning 4 for No Ack. Scoping the lines, everything is getting sent as expected, and the ACK bit is low on the 9th rising edge of SCL, so I think the slave is responding. The microcontroller does not recognize the ACK bit.

Relevant initialization code:
#define I2C_DEV I2CD1
#define I2C_GPIO GPIOB
#define I2C_SCL_PIN 6
#define I2C_SDA_PIN 7
static i2caddr_t addr = 0x52;

static const I2CConfig i2ccfg = {
OPMODE_I2C,
100000,
STD_DUTY_CYCLE,
};

void comm_nunchuk_init(void)
{
i2cAcquireBus(&I2C_DEV);
palSetPadMode(I2C_GPIO, I2C_SCL_PIN,
PAL_MODE_ALTERNATE(4) |
PAL_STM32_OTYPE_OPENDRAIN |
PAL_STM32_OSPEED_MID1);
palSetPadMode(I2C_GPIO, I2C_SDA_PIN,
PAL_MODE_ALTERNATE(4) |
PAL_STM32_OTYPE_OPENDRAIN |
PAL_STM32_OSPEED_MID1);
i2cStart(&I2C_DEV, &i2ccfg);
i2cReleaseBus(&I2C_DEV);
}

Sending code:
txbuf[0] = 0xF0;
txbuf[1] = 0x55;
i2cAcquireBus(&I2C_DEV);
status = i2cMasterTransmitTimeout(&I2C_DEV, addr, txbuf, 2, rxbuf, 0, tmo);
i2cReleaseBus(&I2C_DEV);

Status is always -2 and the error code is 4. I have 4.7k pullup resistors on each line.

I also noticed that if there was actually no ACK bit (i.e. the slave is disconnected) the I2C bus would stop after sending the slave address. However, in my case, it sends the address and both bytes (three sets of 9 SCL clocks), all with ACK bits being low on the 9th clock, but still returns a No Ack error. Why would it report no ack when SDA is low on the 9th rising edge of SCL? Any guidance would be appreciated.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 I2C Not Recognizing Ack

Post by Giovanni »

steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: STM32F4 I2C Not Recognizing Ack

Post by steved »

Looking at your code, shouldn't the field for receive data length be > 0?

Somewhere in these forums I posted updated I2C routines which add slave mode; while I don't remember changing anything in master mode, they might handle your situation differently.
raphaelchang
Posts: 6
Joined: Sat Jul 23, 2016 7:50 am
Been thanked: 1 time

Re: STM32F4 I2C Not Recognizing Ack

Post by raphaelchang »

I checked everything on the checklist and it seems to be correct. The receive data length is 0 because I am only sending data to the slave, not receiving any. Everything looks correct on the scope (I can attach an image later) but the code is not recognizing that the ACK bit is low.

The only difference I could find so far between my code and the example code is that i2cStart (as well as the entire init function) is called in a different thread than the transmit functions, but I thought it would be fine because it is initialized before the other (sending) thread starts. Could this be the problem?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 I2C Not Recognizing Ack

Post by Giovanni »

Hi,

Calling i2cStart() in another thread is not a problem if the sequence of operations is correct.

Are debug options enabled in chconf.h? assertions and state checker would catch out-of-order operations.

Giovanni
raphaelchang
Posts: 6
Joined: Sat Jul 23, 2016 7:50 am
Been thanked: 1 time

Re: STM32F4 I2C Not Recognizing Ack

Post by raphaelchang »

Here is what the signals look like on a scope:
IMG_20160727_230632.jpg


The top is SCL and the bottom is SDA. At every 9 SCL rising edge, it is clear that SDA is low, but the microcontroller still returns a no ack error.
RedEyer
Posts: 3
Joined: Sun Aug 07, 2016 4:16 pm
Has thanked: 1 time

Re: STM32F4 I2C Not Recognizing Ack

Post by RedEyer »

Hello all,

I have the same issue on STM32Discovery + gy-521(mini board with MPU6050 Gyro + Accelerometer).

Has anyone solved this problem?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 I2C Not Recognizing Ack

Post by Giovanni »

Hi,

I don't have any way to test this, hopefully somebody else already used those devices.

What ChibiOS version are you using?

Giovanni
RedEyer
Posts: 3
Joined: Sun Aug 07, 2016 4:16 pm
Has thanked: 1 time

Re: STM32F4 I2C Not Recognizing Ack

Post by RedEyer »

The latest(16.1.0) one from github.

I start thinking that my sensor is broken, so I will replace old sensor to the new one at the nearest future.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 I2C Not Recognizing Ack

Post by Giovanni »

Hi,

Note that 16.1.0 is not latest, it is 16.1.5, you can download it from the sourceforge page.

That driver has not been modified since May 2014 so it is unlikely it would change the problem anyway.

Giovanni
Post Reply