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.

CC2538 issue with i2c peripheral

Other Parts Discussed in Thread: CC2538

Hi everyone,

I'm currently trying to integrate a peripheral with the CC2538 SoC using the i2c interface and ran into some difficulties to make it work properly.

Basically, one of the first problem seen is that the I2CM_DR register cannot be set. Also, I've found no documentation about the I2C Loopback Configuration which could be useful for test and debugging in order to test if the configuration was done properly.

I'm using the driverlib available through the Foundation Firmware V1.0.1.0 and the platform used is the SmartRF06 EB. Sadly, there are no examples available using the I2C interface. :(

To help a bit, here's the code used for the initialization:

   // Ensure the peripheral is enabled
   SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_I2C);
   
   // Reset the peripheral to ensure clean state
   SysCtrlPeripheralReset(SYS_CTRL_PERIPH_I2C);
   
   // Config I/O pin A.6 to be I2C SCL
   GPIOPinTypeI2C(GPIO_A_BASE, IOC_PIN_6);
   IOCPinConfigPeriphOutput(GPIO_A_BASE, IOC_PIN_6, IOC_MUX_OUT_SEL_I2C_CMSSCL);
   IOCPinConfigPeriphInput(GPIO_A_BASE, IOC_PIN_6, IOC_I2CMSSCL);
   
   // Config I/O pin A.7 to be I2C SDA
   GPIOPinTypeI2C(GPIO_A_BASE, IOC_PIN_7);
   IOCPinConfigPeriphOutput(GPIO_A_BASE, IOC_PIN_7, IOC_MUX_OUT_SEL_I2C_CMSSDA);
   IOCPinConfigPeriphInput(GPIO_A_BASE, IOC_PIN_7, IOC_I2CMSSDA);
   
   // Init the i2c master clock in normal speed (SysClock = 32 MHz)
   I2CMasterInitExpClk(SysCtrlClockGet(), FALSE);   //I2CM_TPR = 0xF, MFE = 1

Afterwards, as a test to communicate with the device (external EEPROM), one operation tested was to send a word to it. The following code was used.

   // Set slave address and RW reset to 0
   I2CMasterSlaveAddrSet(slaveAddress, FALSE);  // I2CM_SA set properly
   
   // Verify that peripheral is ready
   while(I2CMasterBusBusy()) // OK!
   {
   }
    
   // Put the first byte to send. MSB first
   I2CMasterDataPut((uint8)(data >> 8u)); // data = 0x091B -> I2CM_DR = 0!!
   
   // Send the MSB to slave in burst mode since another byte comes after
   I2CMasterControl(I2C_MASTER_CMD_BURST_SEND_START); // Don't send STOP until whole word sent, I2CM_CTRL = 0x3
   
   // Wait until transfer is completed
   while(I2CMasterBusy()) // I2CM_STAT = 0x4E -> Error!
   {
   }

Debugging was stopped after this point due to error. Otherwise, the next action was to send the LSB.

Another test was to try and read a byte from the EEPROM. Performing a read operation successfully populated the register I2CM_DR with the expected value 0xFF. Although there was an ADRACK error. But that could be an error on my side.

In conclusion,

1. Is there something missing with the configuration of the CC2538?

2. Is it normal that I2CM_DR cannot be set?

Thank you very much!

Sim


   

  • Hi,

    if you set the system clock and the IO clock in a previous function call, i don't see any flaw in your code.

    When you said that the I2CM_DR = 0, do you mean that you tried to read out the register after having called I2CMasterDataPut()? 

    In that case, most probably what happened is that the data already being pushed out by the I2C controller, the FIFO was already emptied.

    Also, I am not sure when tried to read the EEPROM you successfully read out any byte of it, because of the ADRACK error reported.

    May I ask if you can probe the SCL and SDA lines when you launch your small application?>\

    Thanks,

    TheDarkSide

  • Hi TheDarkSide,


    Thanks! Yes exactly, the FIFO was already emptied because the data was pushed to the controller.

    After verification by probing the lines, the expected byte was successfully sent.

    The reason why the value 0xFF was read in the I2CM_DR register was because the slave would not respond and would leave the SDA line up. Hence, generating a byte value of 0xFF.

    The problem came from some bad configuration from the slave part. My bad.

    Everything is working as expected. :)

    The good point is that everybody can now see an example on how to use the CC2538 i2c peripheral. Hope it could help someone!


    Thanks TI,

    Sim