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.

CCS/TMS320F28377S: Problem with I2C

Part Number: TMS320F28377S

Tool/software: Code Composer Studio

Hi,

I am trying to interface it with VCNL4010(IR Sensor) over I2C and I have a problem. I have found a example code in device support and with reference to it, I have modified the code. But it's not working. On the osciloscope I have all the time high condition and I don't see any communication. 

#include "F28x_Project.h"

void i2c_a_init (void);
void i2c_a_write_data(Uint16,Uint16);
Uint16 i2c_a_read_data (Uint16 register_address);

int main(void){

    InitSysCtrl();
    InitGpio();

    i2c_a_init();

    while(1){

        i2c_a_write_data(0x81,0x07);
        i2c_a_read_data (0x80);
    }
}

void i2c_a_init (void)
{
    I2caRegs.I2CSAR.all = 0x0026;     // 7-bit Slave address - DS1672

    EALLOW;
    GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0;
    GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0;

    // Set qualification for the selected I2C pins

    GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3;
    GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3;

    // Configure which of the possible GPIO pins will be I2C_A pins
    // using GPIO regs
    //
    GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1;
    GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1;
    EDIS;

    // Initialize I2C in master transmitter mode
    I2caRegs.I2CPSC.all = 19;    // I2C clock should be between 7Mhz-12Mhz
    I2caRegs.I2CCLKL = 45;      // Prescalers set for 100kHz bit rate
    I2caRegs.I2CCLKH = 45;      // At a 10Mhz I2C clock
    I2caRegs.I2CFFTX.all = 0x6000;    // Enable FIFO mode and TXFIFO
    I2caRegs.I2CFFRX.all = 0x2040;    // Enable RXFIFO, clear RXFFINT
    return;
}
void i2c_a_write_data (Uint16 register_address, Uint16 register_value)
{
   //START condition, STOP condition, Master, Transmitter, I2C enabled
    I2caRegs.I2CMDR.all = 0x2E20;
    I2caRegs.I2CCNT = 0x02;                 // bytes to send - 2 here
    I2caRegs.I2CDXR.all = register_address; // register location
    I2caRegs.I2CDXR.all = register_value;   // register location
}


Uint16 i2c_a_read_data (Uint16 register_address)
{
    //START condition, STOP condition, Master, Transmitter, I2C enabled
    I2caRegs.I2CMDR.all = 0x2E20;
    I2caRegs.I2CCNT = 0x01;                 // bytes to send - always 1
    I2caRegs.I2CDXR.all = register_address; // register location

    // Start condition, Stop condition, Master, I2C enabled
    I2caRegs.I2CMDR.all = 0x2C20;
    I2caRegs.I2CCNT = 0x01;         // bytes to receive - always 1
    return I2caRegs.I2CDRR.all;     // read and return data
}

Thank you for help
Best regards 

Szymon

  • Hello,

    The only issue I'm seeing with your code is that your write/read functions don't check the FIFO status at any point. For example, when you write to DXR you should make sure there's room in the TXFIFO for the number of bytes you're going to write. When you write to DRR, you should make sure there is an item in the RXFIFO available to read.

    That issue doesn't really explain why you aren't seeing any activity on the line at all though. Can you open up the Registers view in CCS and check the status of the I2CSTR register? What does it look like at the beginning of i2c_a_write_data()? What does it look like at the end of i2c_a_write_data()?

    Thanks,
    Whitney
  • Hello

    Thank you for your reply.

    Yes I can read value of I2CSTR.

    At the beginning i2c_a_write_data() value of I2CSTR is 0x0410.

     At the end i2c_a_write_data() value of I2CSTR is 0x1400

    Best regards

    Szymon

  • Hello,

    Thanks for the additional information. The fact that BB went high should mean that the start condition was sent, so I'm surprised you weren't seeing any activity on the signals.

    Can you try adding a couple lines of code to the end of code to the end of i2c_a_write_data() as an experiment? You can use the following two lines to determine that the bytes were sent and that the stop condition was sent.

    while(I2caRegs.I2CFFTX.bit.TXFFST != 0U);
    while(I2caRegs.I2CMDR.bit.STP != 0U);

    You could put a breakpoint on the call to i2c_a_read_data() and see if it gets stuck on one of those loops or if it makes it to the breakpoint.

    Whitney
  • Hello,
    Thank you for your reply.

    I added two lines that you built and when I perform program step by step, the program hangs on the line: while(I2caRegs.I2CFFTX.bit.TXFFST != 0U);

    I have no idea what could be wrong. I see a high state all the time on SDA line.

    Best regards
    Szymon
  • If you don't run it step by step--as in you hit Resume, let it run for a little bit, and then halt it--does it still get stuck in that same place with no activity on SDA?

    I don't see anything wrong with your GPIO configuration, but can you double check the values of the GPIO configuration registers in the CCS Registers view? Would you also be able to try switching to a different GPIO for SDA just to make sure there isn't anything wrong with that one you're using?

    Thanks,

    Whitney

  • Did you find a solution to your problem?

    Whitney
  • Hi,

    All the time I have the same problem

    Best regards

    Szymon

  • Did you try my suggestion in my previous post?

    Whitney Dewey said:

    I don't see anything wrong with your GPIO configuration, but can you double check the values of the GPIO configuration registers in the CCS Registers view? Would you also be able to try switching to a different GPIO for SDA just to make sure there isn't anything wrong with that one you're using?


    Whitney
  • Do you still have this problem? Have you tried the suggestion above?

    Edit: Since I haven't heard back from you, I'm going to assume you fixed the issue and close the thread. Please feel free to comment (or start a new post if this one locks) if this is not the case and you require further help.

    Whitney