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.

RTOS/TM4C123GH6ZRB: I2C acces to external EEPROM before BIOS call

Part Number: TM4C123GH6ZRB

Tool/software: TI-RTOS

Hi,

I need to read and write to external EEPROM through I2C0 master before BIOS_start(). Below is my code snippet for read and write operation. External EEPROM has the value 0x03 in location 0x0000 . But the read value is always zero. 

How to do EEPROM read and write before BIOS_start() ?

#define EPPROM_DEVICE_ADDRESS 0xAE
#define EEPROM_ADDRESS (EPPROM_DEVICE_ADDRESS >> 1)

void EepromRead(uint16_t address_u16, uint8_t *rxdata, uint8_t rxdataLen)
{
uint8_t ret = 0;
uint8_t address_u8;

I2CMasterSlaveAddrSet(I2C0_BASE, EPPROM_DEVICE_ADDRESS, false);
while(I2CMasterBusy(I2C0_BASE)) {}

SysCtlDelay(1000);

I2CMasterDataPut(I2C0_BASE, 0x00); //READ
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE)) {}

SysCtlDelay(1000);

address_u8 = (uint8_t) (address_u16 >> 8);
I2CMasterDataPut(I2C0_BASE, address_u8); //First Word Address
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C0_BASE)) {}

SysCtlDelay(1000);


address_u8 = (uint8_t) (address_u16);
I2CMasterDataPut(I2C0_BASE, address_u8); //Second Word Address
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_BASE)) {}

SysCtlDelay(1000);

I2CMasterSlaveAddrSet(I2C0_BASE, EPPROM_DEVICE_ADDRESS, true);
while(I2CMasterBusy(I2C0_BASE)) {}

SysCtlDelay(1000);

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE );
while(I2CMasterBusy(I2C0_BASE)) {}

SysCtlDelay(1000);

ret = I2CMasterDataGet(I2C0_BASE) & 0xFF;
rxdata[0] = ret;
}

Void main()

{

  uint8_t rxBuff[1];

  EepromRead(0x0000, rxBuff, 1);

  System_printf("Data Read %x\n", rxBuff[0]);

}

  • Hi,

    I don't know which EEprom device you are interfacing with. Looking at your code, I see that you have three I2CMasterDataPut in the function. I can understand the last two I2CMasterDataPut to put out the Eeprom word addresses. But I'm not sure why you need the I2CMasterDataPut(I2C0_BASE, 0x00). Is this required by your EEprom device? Another thing to check is if you have proper pullup resistors on the SDA and SCL buses. I will suggest you use either the logic analyzer or the scope to capture the bus activities. It will be easier to debug your problem. One more thing is that if you could first do a non-TI-RTOS based I2C project to interface with your device. I don't see in your code how you initialized the I2C and pinmuxing and etc. Refer to the TivaWare I2C examples and see if you can first interface to your EEprom device without the RTOS.
  • Hi,

    Thanks for the reply.

    I am using AT24C64D external EEPROM.

    As you said, first I2CMasterDataPut "I2CMasterDataPut(I2C0_BASE, 0x00)" is not needed.

    Below is my I2C0 master initializatin code.

    // The I2C0 peripheral must be enabled before use.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    // Configure the pin muxing for I2C0 functions on port B2 and B3.
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA_SC, GPIO_DIR_MODE_HW | GPIO_PIN_TYPE_OD);

    // Enable the I2C0 Master module
    I2CMasterEnable(I2C0_BASE);

    Correct me if i am wrong
  • Hi,

     You did not enable GPIOB. You need  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB) too. You don't need to call the GPIOPadConfigSet(....).  The GPIOPinTypeI2C will take care of the pad configuration. Please look at the GPIOPintypeI2C function below.

    void
    GPIOPinTypeI2C(uint32_t ui32Port, uint8_t ui8Pins)
    {
        //
        // Check the arguments.
        //
        ASSERT(_GPIOBaseValid(ui32Port));
    
        //
        // Make the pin(s) be peripheral controlled.
        //
        GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW);
    
        //
        // Set the pad(s) for open-drain operation with a weak pull-up.
        //
        GPIOPadConfigSet(ui32Port, ui8Pins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
    }

  • Well done - once more - Charles!

    While never admitted (here) - you've employed the substantial power of the well known, "KISS" - which most always provides the fastest, easiest - drive to success.

    Removing the RTOS from the equation vastly simplifies - it is my belief that (some) consideration should be granted to, "Confirming that ALL functions succeed in their "API only" (bare metal) form - prior to entering the, "RTOS Jungle."

    As evidenced here - even a most basic "I2C transaction to a small, external EEProm" - requires, "Great attention to Detail." Adding the (many) complications - introduced by the premature introduction of the RTOS - seems "LESS than optimal."