Error while reading EEPROM content via I2C in the S32K148EVB using the sample project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error while reading EEPROM content via I2C in the S32K148EVB using the sample project

1,378 Views
satish_k_singh
Contributor III

Hello ,

Currently  I am interfacing the Microchip 128bit EEPROM 24A00 , and after writing the content in to the EEPROM, the 

reading of the same differs from what is written, when they are done one after the other as can be seen in the below buffer content

LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
Transfer Buffer
buffer[0] uint8_t 0 '\0'
buffer[1] uint8_t 1 '\001'
buffer[2] uint8_t 2 '\002'
buffer[3] uint8_t 3 '\003'
buffer[4] uint8_t 4 '\004'
buffer[5] uint8_t 5 '\005'

Clear Buffer
buffer[0] uint8_t 0 '\0'
buffer[1] uint8_t 0 '\0'
buffer[2] uint8_t 0 '\0'
buffer[3] uint8_t 0 '\0'
buffer[4] uint8_t 0 '\0'
buffer[5] uint8_t 0 '\0'

LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buffer, (TRANSFER_SIZE - 1), true, OSIF_WAIT_FOREVER);
Receive Buffer
buffer[0] uint8_t 5 '\005'
buffer[1] uint8_t 3 '\003'
buffer[2] uint8_t 0 '\0'
buffer[3] uint8_t 0 '\0'
buffer[4] uint8_t 78 'N'
buffer[5] uint8_t 0 '\0'

We make use of the below version and i have attached the code too.

S32 Design Studio for ARM

Version: 2.0
Build id: 170810

So could you please let know how to resolve the same.

Labels (2)
0 Kudos
3 Replies

1,171 Views
AlinaB
NXP Employee
NXP Employee

Hello,

I took a look upon your code:

/* Initialize the data buffer */
for (i = 0u; i <= TRANSFER_SIZE; i++)
{
buffer[i] = i;// Address 0 , Data 1, 2 , 3, 4, 5 , 6
}

It looks like you want to sent the address from the tx buffer, but it doesn't work like this.

The address that will be sent is the one from the configuration structure (found in Generated Code/lpi2c1.c). Everything from the tx buffer will be interpreted as data.

const lpi2c_master_user_config_t lpi2c1_MasterConfig0 = {
    .slaveAddress = 80U,      //this address will be sent, configure here the right address of the slave
    .is10bitAddr = false,
    .operatingMode = LPI2C_FAST_MODE,
    .baudRate = 50000U,
    .transferType = LPI2C_USING_INTERRUPTS,
    .dmaChannel = 0U,
    .masterCallback = NULL,
    .callbackParam = NULL,
};

Also the call to LPI2C_DRV_MasterReceiveDataBlocking() should be done like this:
LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER); //reads all the data that have been written previously

Best regards,
Alina

0 Kudos

1,171 Views
satish_k_singh
Contributor III

Hello ,

thanks for the reply , the comment in the initialize buffer is not right , the slave address I need to set is 0X50 (80U in decimal) and I have done the same in the attached code , but i Still have issue with reading the content. I have attached the code and snapshot of the buffer.

I write 0, 1, 2, 3, 4, 5 into the EEPROM , but when i Read I get the value 5, 3, 0, 0, 78, 78 in the buffer.

Transfer_Buffer_Success.jpg

Buffer_Clear.pngReceive_Buffer.jpg


/* Initialize LPI2C Master configuration
* - Slave address 0x50
* - Standard operating mode, 5000 Hz frequency
* - See LPI2C components for configuration details
*/
LPI2C_DRV_MasterInit(INST_LPI2C1, &lpi2c1_MasterConfig0, &lpi2c1MasterState);

/* Initialize the data buffer */
for (i = 0u; i < TRANSFER_SIZE; i++)
{
buffer[i] = i;
}

/* Send a packet of data to the bus slave */
LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);

/* Clear the buffer to prepare it for the next operation */
for (i = 0u; i < TRANSFER_SIZE; i++)
{
buffer[i] = 0u;
}

/* Request data from the bus slave */
LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);

/* End of the driver example */

/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/

0 Kudos

1,171 Views
AlinaB
NXP Employee
NXP Employee

Hello, 

The code seems to be alright then. 

What pins are you using for master lpi2c? Could you provide a capture with the SCL and SDA signals when data is send/received?

0 Kudos