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.

TMS320F2833 I2C receive data from sensor

Hello all,

I am trying to read data from a temperature sensor (14bit) with I2C module working a master. When I run the code I can see the clock working only for few cycles and then stays low and the SDA stays high. I have set it to run in Repeat mode, so I set only a START at the beginning. Do you have any idea what is wrong ?

PS: since the sensor is 14bit and the I2C module can transfer maximum 8bit each time , how is possible to overcome this ? Any idea ?


Thanks.

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
#include "DSP2833x_Examples.h"

// Note: I2C Macros used in this example can be found in the
// DSP2833x_I2C_defines.h file

// Prototype statements for functions found within this file.
void   I2CA_Init(void);
Uint16 I2CA_ReadData(void);


#define I2C_SLAVE_ADDR        0x27
#define I2C_NUMBYTES          4
int Data;

void main(void)
{

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();
// Setup only the GP I/O only for I2C functionality
   InitI2CGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();

// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//   EALLOW;    // This is needed to write to EALLOW protected registers
//   PieVectTable.I2CINT1A = &i2c_int1a_isr;
//   EDIS;   // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   I2CA_Init();

// Step 5. User specific code


// Enable interrupts required for this example

// Enable I2C interrupt 1 in the PIE: Group 8 interrupt 1
//   PieCtrlRegs.PIEIER8.bit.INTx1 = 1;

// Enable CPU INT8 which is connected to PIE group 8
 // IER |= M_INT8;
 //  EINT;

   // Application loop
   for(;;)
   {
          Data= I2caRegs.I2CDRR;

    // end of for(;;)
   }
}   // end of main




void I2CA_Init(void)
{
    // Initialize I2C

    I2caRegs.I2CSAR = 0x27;        // Slave address


    #if (CPU_FRQ_150MHZ)             // Default - For 150MHz SYSCLKOUT
        I2caRegs.I2CPSC.all = 14;   // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz)
    #endif
    #if (CPU_FRQ_100MHZ)             // For 100 MHz SYSCLKOUT
        I2caRegs.I2CPSC.all = 9;        // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz)
    #endif

    // Configure I2C mode register

    I2caRegs.I2CMDR.all = 0;        // Reset the I2C module
    I2caRegs.I2CSTR.all = 0;     // Reset all status bits
    I2caRegs.I2CIER.all = 0;        // Disable all interrupts.

    EALLOW;
               SysCtrlRegs.PCLKCR0.bit.I2CAENCLK  = 1; // Enable I2C module system clock
    EDIS;

    I2caRegs.I2CMDR.bit.FDF  = 0;    // Free data format is disabled
    I2caRegs.I2CMDR.bit.STB  = 1;    // The I2C module is in start mode (only when I2C module is Master)

    I2caRegs.I2CMDR.bit.BC   = 0;    // 8 bits per data byte
    I2caRegs.I2CMDR.bit.RM  =  1;    // Set in repeat mode
    I2caRegs.I2CMDR.bit.MST  = 1;    // Set I2C module as Master
    I2caRegs.I2CMDR.bit.TRX  = 0;    // The I2C module is a receiver and receives data on the SDA pin
    I2caRegs.I2CMDR.bit.FREE = 1;    // Let the I2C run when the DSP is halted with the debugger

    I2caRegs.I2CCLKL = 50;            // NOTE: must be non zero
    I2caRegs.I2CCLKH = 50;            // NOTE: must be non zero


    I2caRegs.I2CMDR.bit.IRS  = 1;   // Take I2C out of reset

    DELAY_US(50);

    I2caRegs.I2CMDR.bit.STP  = 0;    // Generate a stop condition, when the internal data counter counts down to zero
    I2caRegs.I2CMDR.bit.STT  = 1;    // Generate a start condition on the I2C bus

    I2caRegs.I2CFFRX.all = 0;       // Reset/Disable the TXFIFO.
   //I2caRegs.I2CFFTX.all = 0x6000;    // Enable FIFO mode and TXFIFO
   //I2caRegs.I2CFFRX.all = 0x2040;    // Enable RXFIFO, clear RXFFINT,

   return;
}



//===========================================================================
// No more.
//===========================================================================