Page 2 of 2
Re: I2C No ack error
Posted: Thu Jul 06, 2017 1:21 am
by caheo
steved wrote:On a quick look, the code looks sensible (and, yes, strip the code down to the minimum which shows the problem).
Two hardware things to check:
1. Do you have pullups on the I2C lines? (Typically in the region of 2K2 to 4K7; higher should work if lines are short and speed is low)
2. Are other pins assigned to the same I2C functions (perhaps in the board file)?
Does the problem arise on the first attempt to communicate with the EEPROM?
You might need to put a scope on the lines to see what's going on.
1. I used 10K, I tried 4.7K but it doesn't work as well.
2. I don't think so cause my code use OLIMEX_STM32_P103 board.c for STM32F103C8T6 chinese module.
Interesting that the code didn't hang for 1st time communication but 2nd time did.
I used logic analyzer but couldn't see any I2C signal sent out, check my screenshot below. It works fine on I2C on Arduino.

Re: I2C No ack error
Posted: Thu Jul 06, 2017 5:26 am
by caheo
I got it working with following modification:
Code: Select all
// main function
...
palSetPadMode(GPIOB, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); /* SCL */
palSetPadMode(GPIOB, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); /* SDA */
i2cStart(&I2CD1, &i2cfg1);
chThdCreateStatic(waEEPROM, sizeof(waEEPROM), NORMALPRIO, Thread_EEPROM, NULL);
...
//Thread
...
i2cAcquireBus(&I2CD1);
tx_data[0] = 0x00;
tx_data[1] = 0x01;
status = i2cMasterTransmitTimeout(&I2CD1, EEPROM_ADD, tx_data, 2, rx_data, 2, TIME_INFINITE);
if(status == MSG_TIMEOUT) i2cStart(&I2CD1, &i2cfg1);
i2cReleaseBus(&I2CD1);
...
if(status == MSG_TIMEOUT) i2cStart(&I2CD1, &i2cfg1);
does the trick but now it comes to problem without ACK.
Write to EEPROM works with following I2C signal

But it's supposed to have CONTROL CODE is 1010 as stated in the datasheet. It's a bit weird to me, any idea why?


Re: I2C No ack error
Posted: Thu Jul 06, 2017 8:12 am
by steved
It sounds as if your EEPROM isn't responding - when that happens the I2C (intentionally) locks up in a 'not ready' state, and you have to reset it as you have done.
ChibiOS expects a 7-bit I2C address - the 'Slave Address' field in your diagram (other people use 8-bit, with bit 0 set to zero). So your
is correct.
Re: I2C No ack error
Posted: Thu Jul 06, 2017 9:47 am
by caheo
steved wrote:It sounds as if your EEPROM isn't responding - when that happens the I2C (intentionally) locks up in a 'not ready' state, and you have to reset it as you have done.
ChibiOS expects a 7-bit I2C address - the 'Slave Address' field in your diagram (other people use 8-bit, with bit 0 set to zero). So your
is correct.
The EEPROM isn't responding because wrong I2C signal I guess. Weird thing is that I2C signal from Wire's library of Arduino send diffents signal from what its in datasheet but it works

Re: I2C No ack error
Posted: Thu Jul 06, 2017 12:33 pm
by Giovanni
If the driver is locked you need restart it. See the driver state machine here:
http://chibios.sourceforge.net/docs3/ha ... _i2_c.htmlGiovanni
Re: I2C No ack error
Posted: Thu Jul 06, 2017 2:56 pm
by caheo
Thanks, do you have any idea why I2C doesn't work with 24LC512 EEPROM? I'm looking at
https://github.com/barthess/24aa I think it works the same way?
Re: I2C No ack error
Posted: Thu Jul 06, 2017 3:29 pm
by Giovanni
Hi,
Barthess condensed his suggestions regarding I2C in this article:
http://wiki.chibios.org/dokuwiki/doku.p ... e_shootingAlso try setting I2C IRQ priority to 3 and see if it makes a difference.
Giovanni
Re: I2C No ack error
Posted: Thu Jul 06, 2017 6:30 pm
by caheo
I got it working now, and the root cause was that I ignored PULL-UP resistor on SCL line cause I think PULL-UP resistor on SDA is enough. I have been warned and it's my stupid mistake.
Thank you @Giovanni and @steved for your valuable time to look into!