6 years, 4 months ago.

Mbed revision and i2c bus

I have a very strange problem with mbed revision 130. Using a Nucleo SMT32F446 The i2c bus does not work. If I downgrade mbed to revision 129 all works perfectly. Does someone have an idea on where is the problem?

2 Answers

6 years, 4 months ago.

i have the same problem, with 2 i2c ports enable. this is the serial feedback : mbed assertation failed: (hz > 0) && (hz <= 400000), file: C:\Jenkins\workspace\mbed-2-build-library\targets\TARGET_STM\TARGET_STM32F4\i2c_api.c, line 154

Hi I just switched to mbed_lib_rev130 and it looks like the assert line is located on line 285, not 154. MBED_ASSERT((hz > 0) && (hz <= 400000)) In any case, are you trying to use a 1MHz i2c clock ?

I agree there is an issue here - so I have submitted a correction to mbed: part of https://github.com/ARMmbed/mbed-os/pull/3324

posted by Laurent Meunier 28 Nov 2016
6 years, 3 months ago.

Hello - thanks for reporting this. I will have a look at your problem - can you please explain the application or test that you are running ?

Hi. I have a eeprom and a ds3231 circuit in my i2c bus. The bus is defined like this: I2C i2c(PB_9, PB_8); If I try to get something from the i2c bus I obtain NACK using the last mbed version.

posted by Denis Gottardello 28 Nov 2016

Thanks for the quick answer . And more precisely, can you share the I2C API you are using or a extract of code like a few lines where you do the i2c.read( ...); ?

posted by Laurent Meunier 28 Nov 2016

also one more question: is it NUCLEO_F446RE or NUCLEO_F446ZE ?

posted by Laurent Meunier 28 Nov 2016

The i2c bus (mbed 130) works in an empty project but not in my project. Now it is very hard to find the problem. My project works only with mbed 129.

posted by Denis Gottardello 29 Nov 2016

mbed_130 contains modifications that were added to get I2C_ASYNCH mbed support in F4 family. There are more modifications ongoing to have I2C_ASYNCH supported on all families, maybe the issue can be solved in the next version.

I really would like to reproduce your issue and help solving it - can you just tell me which i2c APIs you're using so that I try the same or share with me some extract of your project where the i2c is called ?

posted by Laurent Meunier 29 Nov 2016

Ok, this is a tipical function:

<<code>>#define SlaveAddress 0xa0

bool EEPROMStore::EEPROMStoreRadioCodes(long &Value) { Value= 0; int EEPROMPointer= EEPROM_RADIOCODES_BEGIN; unsigned char Buffer[EEPROM_RADIOCODE_RECORD_SIZE]; while (EEPROMPointer< EEPROM_RADIOCODES_LENGTH) { Buffer[0]= EEPROMPointer >> 8; Buffer[1]= EEPROMPointer & 0xff;

  1. ifdef MBED if (!i2c->write(SlaveAddress, (char*)Buffer, 2)== 0) return false; if (!i2c->read(SlaveAddress, (char*)Buffer, sizeof(Buffer))== 0) return false; while(i2c->write(SlaveAddress, NULL, 0));
  2. elif defined AVR Wire.beginTransmission(SlaveAddress); Wire.write((int)Buffer[0]); Wire.write((int)Buffer[1]); Wire.endTransmission(); Wire.requestFrom(SlaveAddress, EEPROM_RADIOCODE_RECORD_SIZE); for (int count= 0; count< EEPROM_RADIOCODE_RECORD_SIZE; count++) { if (Wire.available()) Buffer[count]= Wire.read(); else return false; }
  3. endif bool Finded= false; for (int count_2= 0; count_2< sizeof(Buffer); count_2++) { if (Buffer[count_2]!= 0xff) { Finded= true; break; } } if (Finded) Value++; else break; EEPROMPointer+= sizeof(Buffer); } return true; }<</code>>
posted by Denis Gottardello 29 Nov 2016

Hi could you try to remove the below code which should not be required ? while(i2c->write(SlaveAddress, NULL, 0));

posted by Laurent Meunier 29 Nov 2016

Hi again, I will later send a Pull Request to be able to cope with calls like i2c->write(SlaveAddress, NULL, 0); But may you check whether removing those lines can solve your issue?

posted by Laurent Meunier 01 Dec 2016