Problem with i2c EEPROM

Post here first, or if you can't find a relevant section!
Post Reply
heretop
Posts: 39
Joined: Sun Jun 20, 2021 2:09 pm

Problem with i2c EEPROM

Post by heretop »

I try to use 24LC32 (http://ww1.microchip.com/downloads/en/D ... 21072G.pdf) i2c EEPROM with Nucleo F411RE and wire.h. I connect SCL pin 6 of EEPROM to D15 and SDA pin 5 of EEPROM to D14 as shown in the picture:
Image

The code first is trying to print the output of Wire.endTransmission() after Wire.beginTransmission(address) with address: 0b1010000 (should be the correct one as 24LC32 slave address is 1010, and I connect A0 A1 A2 all to GND), 0b1010001 and 0b1000000 (to see if there is any difference). Then the code will scan through address from 0 to 127 to check any device with the i2c:

Code: Select all

#include <Wire.h>

//            SDA  SCL
// TwoWire Wire2(PB9, PB8);

void eepromInit()
{
    Serial.begin(9600);
    // Wire.setSDA(PB_9); // using pin name PY_n
    // Wire.setSCL(PB8); // using pin number PYn
    Wire.begin();
    delay(100);

    byte error, address;
    int nDevices;
    Wire.beginTransmission(0b1000000);
    error = Wire.endTransmission();
    Serial.print(error);
    Serial.print("\n");
    Wire.beginTransmission(0b1010001);
    error = Wire.endTransmission();
    Serial.print(error);
    Serial.print("\n");
    Wire.beginTransmission(0b1010000);
    error = Wire.endTransmission();
    Serial.print(error);
    Serial.print("\n");

    nDevices = 0;
    for (address = 1; address < 127; address++)
    {
        // The i2c_scanner uses the return value of
        // the Write.endTransmisstion to see if
        // a device did acknowledge to the address.
        Wire.beginTransmission(address);
        error = Wire.endTransmission();

        if (error == 0)
        {
            Serial.print("I2C device found at address 0x");
            if (address < 16)
                Serial.print("0 ");
            Serial.println(address);

            nDevices++;
        }
        else if (error == 4)
        {
            Serial.print("Unknown error at address 0x");
            if (address < 16)
                Serial.print("0");
            Serial.println(address);
        }
    }
    if (nDevices == 0)
        Serial.print("No I2C devices found\n");
    else
        Serial.print("done\n");
}

void setup(void)
{
    eepromInit();
}

void loop()
{

}
The output of this code is always:

Code: Select all

2
2
2
No I2C devices found
Where 2 is the output of Wire.endTransmission() with three different address, it means I2C_NACK_ADDR
(maybe not acknowledged address?) as shown in the code at https://github.com/stm32duino/Arduino_C ... #L247-L248, and `No I2C devices found` means it cannot find any device with address 0 to 127.

I also tried use `TwoWire Wire2(PB9, PB8);` and change Wire to Wire2, or `Wire.setSDA(PB9); Wire.setSCL(PB8);`. None of it works. May I know anyone know what wrong with this? Thanks a lot!

My computer development environment is: Windows 10 19042.1052, arduino IDE 1.8.16, core 2.2.0, upload method SWD
Capture.PNG
Capture.PNG (9.07 KiB) Viewed 1631 times
by fpiSTM » Wed Mar 16, 2022 8:42 pm
Have you wired pull up resistors on each i2c line?
Go to full post
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Problem with i2c EEPROM

Post by fpiSTM »

Have you wired pull up resistors on each i2c line?
heretop
Posts: 39
Joined: Sun Jun 20, 2021 2:09 pm

Re: Problem with i2c EEPROM

Post by heretop »

fpiSTM wrote: Wed Mar 16, 2022 8:42 pm Have you wired pull up resistors on each i2c line?
Thanks for the help! Yeah, after add 10k pull up, it works!
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Problem with i2c EEPROM

Post by fpiSTM »

Great. Welcome ;)
Post Reply

Return to “General discussion”