7 years, 9 months ago.

I2C not functioning Nucleo L476RG

Im trying to connect a Nucleo L476RG to a PCF 16x2 LCD

Connections aside I cant seem to setup the I2C whatsoever.

Using an I2C Scanner sketch with or without external pull-up resistors the SDA and SCL lines just sit at 3v3

Scanner code 1

#include "mbed.h"
I2C i2c(I2C_SDA, I2C_SCL);        // sda, scl
Serial pc(USBTX, USBRX); // tx, rx
 
int main()
{
    pc.printf("RUN\r\n");
    for(int i = 0; i < 128 ; i++) {
        i2c.start();
        if(i2c.write(i << 1)) pc.printf("0x%x ACK \r\n",i); // Send command string
        i2c.stop();
    }
}

Scanner code 2

char data = 0x00;
 
int main() {
  for (int i = 0; i<128;i++) {
    if (i2c.write(i,&data,1) == 0)
      pc.printf("0x%02x ACK\r\n",i);
  }
}

I am new to MBed and so far I seem to be struggling.

Any help appreciated

Andy

1 Answer

7 years, 9 months ago.

Hi Andy,

Please remove the calls to "i2c.start()" and "i2c.stop()" in "Scanner code 1". "i2c.write()" will take care of the start and stop steps for you. Do you see any data after making that change?

Also, not sure if "Scanner code 2" is the thing receiving the data or the second block of code you tried. It looks better but it's also missing the declarations of I2C and Serial. Though it wouldn't build at that point.

Let me know what you find!

Thanks, Brian

Accepted Answer

Hi Brian, thanks for that, have a look here at a later posted question of mine for the solution I found https://developer.mbed.org/questions/77345/TextLCD-PCF8574-Backpack-Nucleo-L476RG/

posted by Andrew West 18 Mar 2017