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.

TMS320F28379D: i2c Problem

Part Number: TMS320F28379D

I want the following Steps to read the data:

But I am sending address twice which I dont want:

Here is my scope image:

Code Snippet is follows:

I2caRegs.I2CMDR.bit.IRS = 1;                // reset I2C

            // Make sure I2C is not busy and has stopped
            while (I2caRegs.I2CSTR.bit.BB == 1);        // busy loop
            I2caRegs.I2CSTR.bit.SCD = 1;                // Clear the SCD bit (stop condition bit)
            while(I2caRegs.I2CMDR.bit.STP == 1);        // stop bit loop

            I2caRegs.I2CSAR.all = 0x00;             // I2C slave address
            I2caRegs.I2CCNT = 1;                    // assume register address is one byte
            while (I2caRegs.I2CSTR.bit.BB == 1);        // still busy?

            //I2caRegs.I2CMDR.all = 0x2620;             // start, no stop bit, master, tx, reset I2C 00100110
            I2caRegs.I2CMDR.bit.NACKMOD = 0;            // NACK mode bit
            I2caRegs.I2CMDR.bit.FREE = 0;               // Stop I2C when suspended
            I2caRegs.I2CMDR.bit.STT = 1;                // START condition bit
            I2caRegs.I2CMDR.bit.STP = 0;                // STOP condition bit
            I2caRegs.I2CMDR.bit.MST = 1;                // Master mode
            I2caRegs.I2CMDR.bit.TRX = 1;                // Transmitter mode
            I2caRegs.I2CMDR.bit.XA = 0;                 // 7-bit addressing mode
            I2caRegs.I2CMDR.bit.RM = 0;                 // Nonrepeat mode
            I2caRegs.I2CMDR.bit.DLB = 0;                // Digital loopback mode is disabled
            I2caRegs.I2CMDR.bit.IRS = 1;                // The I2C module is enabled
            I2caRegs.I2CMDR.bit.STB = 0;                // The I2C module is not in the START byte mode
            I2caRegs.I2CMDR.bit.FDF = 0;                // Free data format mode is disabled
            I2caRegs.I2CMDR.bit.BC = 0;                 // 8 bits per data byte



            while(I2caRegs.I2CSTR.bit.XRDY == 0);       // Do nothing till bus is free
            I2caRegs.I2CDXR.all     = 0x01;                  // register address of the sensor (1 byte)

            while(!I2caRegs.I2CSTR.bit.ARDY);           // all ready?
            //I2caRegs.I2CMDR.all = 0x2C20;             // start, stop bit when CNT =0, master, rx, reset I2C 00101100
            I2caRegs.I2CMDR.bit.NACKMOD = 0;            // NACK mode bit
            I2caRegs.I2CMDR.bit.FREE = 0;               // Stop I2C when suspended
            I2caRegs.I2CMDR.bit.STT = 1;                // START condition bit
            I2caRegs.I2CMDR.bit.STP = 1;                // STOP condition bit
            I2caRegs.I2CMDR.bit.MST = 1;                // Master mode
            I2caRegs.I2CMDR.bit.TRX = 0;                // Receiver mode
            I2caRegs.I2CMDR.bit.XA = 0;                 // 7-bit addressing mode
            I2caRegs.I2CMDR.bit.RM = 0;                 // Nonrepeat mode
            I2caRegs.I2CMDR.bit.DLB = 0;                // Digital loopback mode is disabled
            I2caRegs.I2CMDR.bit.IRS = 1;                // The I2C module is enabled
            I2caRegs.I2CMDR.bit.STB = 0;                // The I2C module is not in the START byte mode
            I2caRegs.I2CMDR.bit.FDF = 0;                // Free data format mode is disabled
            I2caRegs.I2CMDR.bit.BC = 0;                 // 8 bits per data byte
            I2caRegs.I2CCNT     = 1;                    // only read one byte data

            if(I2caRegs.I2CSTR.bit.NACK == 1)
            {
                 I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT;    // 0x0002
            }
            I2caRegs.I2CMDR.bit.STP = 1;                    // stop bit when CNT=0

            while(!I2caRegs.I2CSTR.bit.SCD);                // stop bit detected?

            data[0]    = I2caRegs.I2CDRR.all;                  // read one byte data

So if possible is there a way where I can just write 8 bits and then just become master receiver without sending address?

Thanks

Sagar

  • Sagar,

    You don't need to start with master-transmitter and then move onto master receiver. You can directly start as master-receiver.

    Regards,
    Manoj
  • Here the slave address is 0x00 and control register is 0x3D. So i have to be master transmitter first and then master receiver. but when becoming master reciever I dont want to send message. I simply want to read!

    So is there a way to do that?

    Thanks for the help
  • Sagar,

    Slave address 0x00 is reserved for "General Call". So, consider using non-zero slave address.

    If you have to send a command, you have to use both master transmitter and then configure to master receiver. When you re-configure to master-receiver, it will re-send the address + Read bit on the bus. There is no way around it.

    Regards,
    Manoj