This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I am Using Peripheral Example Code "i2c_eeprom".But I Am Unable to Read The Data From EEPROM.
My EEPROM Part number is 24C04.
I am Attaching the Code Below, Please Check it Once.
i2c_ex2_eeprom.c
Prem,
We are working on getting this assigned to the correct subject matter expert. Please give us another day to respond.
Best,
Matthew
Prem,
It is not clear from your message what kind of failure you are seeing. Is EEPROM NACKing?
i2c_ex2_eeprom example is outdated. I recommend you to consider below EEPROM I2C examples:
If polling method is preferred, use i2c_ex4_eeprom_polling example
If interrupt method is preferred, use i2c_ex6_eeprom_interrupt example.
Regards,
Manoj
Hi Sir,
First of All Thank You.
As You Said That " i2c_ex4_eeprom_polling example", I am Working on That.
But I Have One Doubt regarding to the above example, How can I send One Byte address.
I am using 24C04 EEPROM and Below is The Write Address Format.
Please Check it Once and Give me Suggestions.
Thank You.
#include "driverlib.h" #include "device.h" #include "i2cLib_FIFO_polling.h" // // Globals // struct I2CHandle EEPROM; struct I2CHandle *currentMsgPtr; // Used in interrupt uint16_t passCount = 0; uint16_t failCount = 0; uint16_t AvailableI2C_slaves[1]; uint16_t TX_MsgBuffer[MAX_BUFFER_SIZE]; uint16_t RX_MsgBuffer[MAX_BUFFER_SIZE]; uint32_t ControlAddr; uint16_t status; //void fail(void); //void pass(void); void I2C_GPIO_init(void); void I2Cinit(void); void verifyEEPROMRead(void); // // Main // void main(void) { // // Initialize device clock and peripherals // Device_init(); // // Disable pin locks and enable internal pullups. // Device_initGPIO(); // // Initialize I2C pins // I2C_GPIO_init(); // // Initialize PIE and clear PIE registers. Disable CPU interrupts. // Interrupt_initModule(); // // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // Interrupt_initVectorTable(); I2Cinit(); //I2Cs connected to I2CA will be found in AvailableI2C_slaves buffer //after you run I2CBusScan function. uint16_t *pAvailableI2C_slaves = AvailableI2C_slaves; status = I2CBusScan(I2CA_BASE, pAvailableI2C_slaves); uint16_t i; for(i=0;i<MAX_BUFFER_SIZE;i++) { TX_MsgBuffer[i] = 0; RX_MsgBuffer[i] = 0; } EEPROM.SlaveAddr = 0x50; EEPROM.base = I2CA_BASE; EEPROM.pControlAddr = &ControlAddr; EEPROM.NumOfAddrBytes = 1; EEPROM.pTX_MsgBuffer = TX_MsgBuffer; EEPROM.pRX_MsgBuffer = RX_MsgBuffer; EEPROM.NumOfAttempts = 5; EEPROM.Delay_us = 10; EEPROM.WriteCycleTime_in_us = 6000; //10ms for EEPROM this code was tested //Example 1: EEPROM Byte Write //Write 11 to EEPROM address 0x0 ControlAddr = 0; EEPROM.NumOfDataBytes = 1; TX_MsgBuffer[0] = 11; // TX_MsgBuffer[1] = 11; status = I2C_MasterTransmitter(&EEPROM); //Wait for EEPROM write cycle time //This delay is not mandatory. User can run their application code instead. //It is however important to wait for EEPROM write cycle time before you initiate //another read / write transaction DEVICE_DELAY_US(EEPROM.WriteCycleTime_in_us); //Example 2: EEPROM Byte Read //Make sure 11 is written to EEPROM address 0x0 ControlAddr = 0; EEPROM.pControlAddr = &ControlAddr; EEPROM.NumOfDataBytes = 1; status = I2C_MasterReceiver(&EEPROM); while(I2C_getStatus(EEPROM.base) & I2C_STS_BUS_BUSY); verifyEEPROMRead(); // //Example 3: EEPROM word (16-bit) write // //EEPROM address 0x1 = 22 & 0x2 = 33 // ControlAddr = 1; //EEPROM address to write // EEPROM.NumOfDataBytes = 2; // TX_MsgBuffer[0] = 0x11; // TX_MsgBuffer[1] = 0x22; // EEPROM.pTX_MsgBuffer = TX_MsgBuffer; // status = I2C_MasterTransmitter(&EEPROM); // // //Wait for EEPROM write cycle time // //This delay is not mandatory. User can run their application code instead. // //It is however important to wait for EEPROM write cycle time before you initiate // //another read / write transaction // DEVICE_DELAY_US(EEPROM.WriteCycleTime_in_us); // // //Example 4: EEPROM word (16-bit) read // //Make sure EEPROM address 1 has 0x11 and 2 has 0x22 // ControlAddr = 1; // EEPROM.pControlAddr = &ControlAddr; // EEPROM.pRX_MsgBuffer = RX_MsgBuffer; // EEPROM.NumOfDataBytes = 2; // // status = I2C_MasterReceiver(&EEPROM); // // verifyEEPROMRead(); // // //Example 5: EEPROM Page write // //Program address = data pattern from address 64 // // for(i=0;i<MAX_BUFFER_SIZE;i++) // { // TX_MsgBuffer[i] = i+64; // } // // ControlAddr = 4; //EEPROM address to write // EEPROM.NumOfDataBytes = MAX_BUFFER_SIZE; // EEPROM.pTX_MsgBuffer = TX_MsgBuffer; // status = I2C_MasterTransmitter(&EEPROM); // // //Wait for EEPROM write cycle time // //This delay is not mandatory. User can run their application code instead. // //It is however important to wait for EEPROM write cycle time before you initiate // //another read / write transaction // DEVICE_DELAY_US(EEPROM.WriteCycleTime_in_us); // // //Example 6: EEPROM word Paged read // ControlAddr = 4; // EEPROM.pControlAddr = &ControlAddr; // EEPROM.pRX_MsgBuffer = RX_MsgBuffer; // EEPROM.NumOfDataBytes = MAX_BUFFER_SIZE; // // status = I2C_MasterReceiver(&EEPROM); // // verifyEEPROMRead(); // if(status) { fail(); } else { pass(); } } // // pass - Function to be called if data written matches data read // void pass(void) { asm(" ESTOP0"); for(;;); } // // fail - Function to be called if data written does NOT match data read // void fail(void) { asm(" ESTOP0"); for(;;); } void verifyEEPROMRead(void) { uint16_t i; while(I2C_getStatus(EEPROM.base) & I2C_STS_BUS_BUSY); for(i=0;i<=EEPROM.NumOfDataBytes;i++) { if(RX_MsgBuffer[i] != TX_MsgBuffer[i]) { //Transmitted data doesn't match received data //Fail condition. PC shouldn't reach here ESTOP0; // fail(); } } } void I2C_GPIO_init(void) { // I2CA pins (SDAA / SCLA) GPIO_setDirectionMode(DEVICE_GPIO_PIN_SDAA, GPIO_DIR_MODE_IN); GPIO_setPadConfig(DEVICE_GPIO_PIN_SDAA, GPIO_PIN_TYPE_PULLUP); GPIO_setQualificationMode(DEVICE_GPIO_PIN_SDAA, GPIO_QUAL_ASYNC); GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCLA, GPIO_DIR_MODE_IN); GPIO_setPadConfig(DEVICE_GPIO_PIN_SCLA, GPIO_PIN_TYPE_PULLUP); GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCLA, GPIO_QUAL_ASYNC); GPIO_setPinConfig(DEVICE_GPIO_CFG_SDAA); GPIO_setPinConfig(DEVICE_GPIO_CFG_SCLA); } void I2Cinit(void) { //myI2CA initialization I2C_disableModule(I2CA_BASE); I2C_initMaster(I2CA_BASE, DEVICE_SYSCLK_FREQ, 400000, I2C_DUTYCYCLE_50); I2C_setConfig(I2CA_BASE, I2C_MASTER_SEND_MODE); I2C_setSlaveAddress(I2CA_BASE, 0x50); I2C_setOwnSlaveAddress(I2CA_BASE, 96); //I2CA address I2C_disableLoopback(I2CA_BASE); I2C_setBitCount(I2CA_BASE, I2C_BITCOUNT_8); I2C_setDataCount(I2CA_BASE, 2); I2C_setAddressMode(I2CA_BASE, I2C_ADDR_MODE_7BITS); I2C_enableFIFO(I2CA_BASE); I2C_clearInterruptStatus(I2CA_BASE, I2C_INT_ARB_LOST | I2C_INT_NO_ACK); I2C_setFIFOInterruptLevel(I2CA_BASE, I2C_FIFO_TXEMPTY, I2C_FIFO_RX12); I2C_enableInterrupt(I2CA_BASE, I2C_INT_ADDR_SLAVE | I2C_INT_ARB_LOST | I2C_INT_NO_ACK | I2C_INT_STOP_CONDITION); I2C_setEmulationMode(I2CA_BASE, I2C_EMULATION_FREE_RUN); I2C_enableModule(I2CA_BASE); } // // End of File //
You need to use Example 1: EEPROM Byte Write. It generates START condition + TX target address + TX data
Hi Sir,
Thank You For Your Reply.
1.EEPROM Byte Write Okay Sir I Understood, But Byte Read: I am Not Getting Read Operation.
2.I Think in Read operation: it reads device address + RX data. Am I Correct?
Could You Please Support Me To Solve read Operation with EEPROM.
First, please confirm whether EEPROM Byte Write worked in your setup.
Here is how EEPROM Read byte command works:
EEPROM Byte Read:
START + TX Slave Address + TX EEPROM Address to read (MSB) + TX EEPROM Address to read (LSB) + Repeat START + RX Read byte as shown below
Did you check I2C bus on logic analyzer?
Regards,
Manoj
Good to know EEPROM write operation are working. Hope you will be able to get EEPROM read operation working as well
Regard