Close

Raspberry Pi ID EEPROM Read Working

A project log for Not Quite Useless Raspberry Pi Replacement

Make a Raspberry Pi replacement using a Cypress Semiconductor Programmable System on a Chip (PSOC 5)

land-boardscomland-boards.com 10/18/2019 at 13:220 Comments

The functions to read the ID EEPROM on the Raspberry Pi Hat are now working. The expected data is:

const uint8 rpp_uio_16_eeprom[RPP_UIO16_EEPROM_LENGTH] = {
    0x52, 0x2D, 0x50, 0x69, 0x01, 0x00, 0x02, 0x00, 0x6D, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0xC0, 0xE9, 0x73, 0x39,
    0x59, 0x5C, 0x8B, 0xAF, 0x62, 0x4F, 0x19, 0x32, 0xFE, 0x3F, 0x2D, 0xD5,
...

The data read from the EEPROM was:

0000  52 2d 50 69 01 00 02 00 6d 00 00 00 01 00 00 00
0010  31 00 00 00 c0 e9 73 39 59 5c 8b af 62 4f 19 32
0020  fe 3f 2d d5 ...

The data matches. I am reading 4 blocks of 32 bytes each for a total of 256 bytes. 

Took a while to debug. I hooked a logic analyzer up to the EEPROM and found it wasn't accessing the I2C interface. Rookie mistake. I copied the reading code but forgot to include the initialization code in main (goes before the program loop):

    // enable I2C interrupts
    I2C_EEPROM_EnableInt();  
    //Start I2C
    I2C_EEPROM_Start(); 

After adding the initialization code, the read worked. The read code looks like:

void readEEPROM(uint8 * eepromBuffer)
{
    uint8 SLAVE_ADDR = 0x50;
    uint8 cMessage[2];
    uint16 cLength = 256;
    
    cMessage[0] = 0;
    cMessage[1] = 0;
    
    //write a dummy byte to initialize the address word counter of 
    //eeprom to start address for read back operation. First location 
    //of cMessage array has word address.
    
    I2C_EEPROM_MasterWriteBuf(SLAVE_ADDR, cMessage, 2, I2C_EEPROM_MODE_COMPLETE_XFER);
    
    //wait until Transfer is complete
    while((I2C_EEPROM_MasterStatus() & I2C_EEPROM_MSTAT_WR_CMPLT )==0);
    
    //Delay for setting address in EEPROM
    CyDelayUs(1);
    
    //Read the 16 bytes from slave, staring from word address specified by iMessage
    //SLAVE_ADDR is the slave address in this API
    //cRx_Buffer is the pointer to array where data has to be stored after reading from EEPROM.
    //cLength-1 is the number of bytes which have to be read from EEPROM
    //I2C_MODE_COMPLETE_XFER, is to read data completly before sending stop command.
    
    I2C_EEPROM_MasterReadBuf(SLAVE_ADDR, eepromBuffer, cLength-1, I2C_EEPROM_MODE_COMPLETE_XFER );
            
    //wait until Transfer is complete
    while((I2C_EEPROM_MasterStatus() & I2C_EEPROM_MSTAT_RD_CMPLT )==0); 
}

The read function reads 256 bytes from the EEPROM into an array. The pointer  into the array was provided by the calling function in main( ). After reading the array is dumped to the USB and gets displayed in the PuTTY screen.

    uint8 eepromBuffer[256];
...
                        readEEPROM(eepromBuffer);
                        dumpEEPROM(eepromBuffer);

I added a plain text field to the right of the read. That lets me see the data as readable characters. Here's the output:

Read from the EEPROM
0000  52 2d 50 69 01 00 02 00 6d 00 00 00 01 00 00 00  R-Pi....m.......
0010  31 00 00 00 c0 e9 73 39 59 5c 8b af 62 4f 19 32  1.....s9Y\..bO.2
0020  fe 3f 2d d5 05 00 01 00 0f 0a 6c 61 6e 64 2d 62  .?-.......land-b
0030  6f 61 72 64 73 2e 63 6f 6d 52 50 50 2d 55 49 4f  oards.comRPP-UIO
0040  2d 31 36 f2 9f 02 00 01 00 20 00 00 00 00 00 00  -16.............
0050  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0060  00 00 00 00 00 00 00 00 00 00 00 ed 6e 00 00 00  ............n...
0070  00 00 00 ed 6e ff ff ff ff ff ff ff ff ff ff ff  ....n...........
0080  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
0090  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00a0  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00b0  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00c0  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00d0  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00e0  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
00f0  ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff f9  ................

You can see our company name, land-boards.com and the board ID, RPP-UIO-16.

 Next, time to check the write code.  

Discussions