Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 3 months ago.
Nucleo F091RC and i2c problem
After many hours on trying to manage an eeprom attached to i2c bus, we have did some tests with oscilloscope. The problem seems related to the i2c bus and the Nucleo demo board. We have ever the same signal. If we send the start signal, or a byte, or something else, the oscilloscopre returns every time the same signal!
Have you got any idea on qhat it is happening? Does somenoe use Nucleo board and i2c?
1 Answer
8 years, 3 months ago.
Hi Denis. Can you share more details on your project ? Perhaps post your (formatted) source code for others to review. Do you have the required pull-up resistors on the I2C lines since I2C is an open-drain interface and the pull-up resistors are necessary to define the logic high state. Some developers are noting some issues with the nucleo line of boards and mbed I2C library use but there appear to be work arounds. Before going there, please share more details of your project, I2C eeprom (I2C address ?) and wiring diagram, etc.
update
Hi Denis. You are using the wrong I2C address (0x50) for the EEprom access. The EEprom I2C address should be 0x50 << 1 = 0xa0. Please use the referenced project which is complete and concise for your testing. It should work as noted. We have coded similar projects on FPGA and low cost micros and if required, can test the same against our Total Phase I2C bus analyzer. While we do not own the exact ST Nucleo board as yours - we have many others here in the lab. Please post your results for future readers.
Reference on the I2C addressing (Arduino vs. mbed use):
https://developer.mbed.org/questions/4064/i2c-on-Nucleo-F401RE/
Quote:
2 years, 2 months ago.
Post courtesy of Wim Huiskamp
This is the old problem again: I2C addresses on the arduino are given in the 7bit format. The mbed libs uses the 8 bit format. You must shift the arduino address (0x50) to the left by one bit. So the correct mbed address is 0xA0. Also make sure you have the pull up resistors in place. Use 4k7 on SDA and on SCL.
Hi and many thanks for your reply. Yes, I have the pullup resistor. I try to use a Microchip eeprom
Please have a look at the code below.
include the mbed library with this snippet
#include "mbed.h" Serial Serial0(USBTX, USBRX); I2C i2c(I2C_SDA, I2C_SCL); //I2C i2c(PTB4, PTB3); //I2C i2c(PB_9, PB_8); int main() { Serial0.baud(19200); Serial0.format(8, SerialBase::None, 1); i2c.frequency(100 * 1000); while (true) { i2c.start(); // <---------------- (1) Serial0.putc(i2c.write(0x50)); // <---------------- (2) Serial0.putc(i2c.write(0x0)); // <---------------- (3) Serial0.putc(i2c.write(0x1)); // <---------------- (4) Serial0.putc(i2c.write('d')); // <---------------- (5) i2c.stop(); // <---------------- (6) wait_ms(1); //break; } }
The problem seems to be not only on the Nucleo F091RC but on many other demo boards such as FRDM-KL05Z. As you can see in the code, I send a start condition, some bytes and then a stop condition. If I build the code with the stop condition I never see nothing in the oscilloscope. If I send only a start condition, or a start condition followed by some bytes, I see every time the same data. To insert wait_ms() between each operation does not have any effect. Change the frequency does not have any effect. Change i2c bus does not have any effect. Comment out the serial section does not have any effect.
The eeprom works perfectly with am Arduino board.
Now I thinking that the i2c bus does not works properly with mbed. Is there someone that uses a Microchip eeprom with mbed?
posted by 21 Sep 2016Hi Denis. Thanks for your code post. Believe your I2C address for the EE may be incorrect as expected by the mbed library. Please import this I2C EEprom example and post your results.
https://developer.mbed.org/users/kuldipmaharjan/code/24LC256/
posted by 21 Sep 2016Many thanks for your reply but I think you haven't read carefully my question. The i2c interface seems to be unusable with mbed and the Nucleo F091RC demo board. The i2c example is unusable and if you do a test with a oscilloscope you will have a incompresible result. I can use without any problem the an i2c eeprom attached to Arduino i2c interface.
posted by 22 Sep 2016Several platforms have problems with the I2C single byte read or write operations. You should always use the I2C blockread or writes unless you have special reasons to apply the byte operations and the tools to verify that they work as intended. To use the block operation you declare and populate a char array, then send the array using the number of bytes as parameter: i2c.write (slaveaddress, array, length). Note that you dont use the i2c.start and i2c.stop in this case. They are taken care of by the blockread and blockwrite operations.
posted by 23 Sep 2016