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.

CC2543: I2c communication problem with LIS2DE12TR

Part Number: CC2543

I am interfacing CC2543 with LIS2DE12TR using I2C according to example code.

But unable to read particular register using register address. because I don't understand how to send the register address and what is the Status of  I2CSTAT  after sending the register address.

I have also read the User's Guide 20.1.4.2 Master Mode for The knowing about Status of I2CSTAT Register..

So Please Help me if any one know about it.....

Thanks 

CC2543 working as a master

#pragma vector = I2C_VECTOR
__interrupt void I2C_ISR(void)
{

// Clear I2C CPU interrupt flag.
I2CIF = 0;


// If a Start or Restart condition has been transmitted ...
if (I2CSTAT == 0x08 || I2CSTAT == 0x10)
{
// Send Slave address and R/W access.
I2CDATA = (SLAVE_ADDRESS << 1) | READ_FROM_SLAVE;

// End Start condition.
I2CCFG &= ~I2CCFG_STA;
}

// If a Data byte has been received and acknowledge has been returned...
else if (I2CSTAT == 0x50)
{
// Read Data byte.
buffer[bufferIndex++] = I2CDATA;
}

// If finished receiving...
if (bufferIndex >= BUFFER_SIZE )
{
// Generate Stop condition.
I2CCFG |= I2CCFG_STO;



// Disable interrupt from I2C by setting [IEN2.I2CIE = 0].
IEN2 &= ~IEN2_I2CIE;

}

  • This is Example Code...............

    #include <hal_types.h>
    // Include Name definitions of individual bits and bit-fields in the CC254x device registers.
    #include <ioCC254x_bitdef.h>
    // Include device specific file
    #if (chip==2541)
    #include "ioCC2541.h"   
    #elif (chip==2543)
    #include "ioCC2543.h"
    #elif (chip==2545)
    #include "ioCC2545.h"
    #else
    #error "Chip not supported!"
    #endif
    
    
    /***********************************************************************************
    * CONSTANTS
    */
    
    // Define size of buffer and number of bytes to send
    #define BUFFER_SIZE 0xFF
    #define SLAVE_ADDRESS 0x53    // 7-bit addressing
    
    #define READ_FROM_SLAVE 0x01
    #define WRITE_TO_SLAVE 0x00
    
    
    /***********************************************************************************
    * LOCAL VARIABLES
    */
    
    // Masters's transmit buffer.
    static uint8 buffer[BUFFER_SIZE];
    static uint16 bufferIndex = 0;
    
    
    /***********************************************************************************
    * LOCAL FUNCTIONS
    */
    
    /***********************************************************************************
    * @fn          I2C_ISR
    *
    * @brief       Function which sends the next I2C data byte.
    *
    * @param       none
    *
    * @return      0
    */
    #pragma vector = I2C_VECTOR
    __interrupt void I2C_ISR(void)
    { 
    #if(chip==2541)
        // Clear I2C CPU interrupt flag.
        P2IF = 0;
    #else
        // Clear I2C CPU interrupt flag.
        I2CIF = 0;
    #endif
      
        // If a Start or Restart condition has been transmitted ...
        if (I2CSTAT == 0x08 || I2CSTAT == 0x10)
        {
            // Send Slave address and R/W access.
            I2CDATA = (SLAVE_ADDRESS << 1) | READ_FROM_SLAVE;
        
            // End Start condition.
            I2CCFG &= ~I2CCFG_STA;
        }
    
        // If a Data byte has been received and acknowledge has been returned...
        else if (I2CSTAT == 0x50)
        {
            // Read Data byte.
            buffer[bufferIndex++] = I2CDATA;
        }
      
        // If finished receiving...
        if (bufferIndex >= BUFFER_SIZE )
        {
            // Generate Stop condition.
            I2CCFG |= I2CCFG_STO;
    
    #if(chip==2541)
            // Disable interrupt from I2C by setting [IEN2.I2CIE = 0].
            IEN2 &= ~IEN2_P2IE;
    #elif(chip==2543 || chip==2545)
            // Disable interrupt from I2C by setting [IEN2.I2CIE = 0].
            IEN2 &= ~IEN2_I2CIE;
    #endif
        
            // Set SRF05EB LED1.
            P1_0 = 1;  
        }
    
        // I2CCFG.SI flag must be cleared by software at the end of the ISR.
        I2CCFG &= ~I2CCFG_SI;
    }
    
    
    /***********************************************************************************
    * @fn          main
    *
    * @brief       Send data to a single slave using I2C in Master mode
    *
    * @param       void
    *
    * @return      0
    */
    int main(void)
    {
        /****************************************************************************
        * Clock setup
        * See basic software example "clk_xosc_cc254x"
        */
      
        // Set system clock source to HS XOSC, with no pre-scaling.
        CLKCONCMD = (CLKCONCMD & ~(CLKCON_OSC | CLKCON_CLKSPD)) | CLKCON_CLKSPD_32M;
        // Wait until clock source has changed.
        while (CLKCONSTA & CLKCON_OSC);
      
        // Note the 32 kHz RCOSC starts calibrating, if not disabled.
    
    #if (chip==2543)
        /***************************************************************************
        * Setup I/O ports
        *
        * Port and pins used by I2C, at the alternative 1 location:
        * I2C SCL:   P0_6    (Debug Connector P18_5)
        * I2C SDA:   P0_7    (Debug Connector P18_3)
        */
    
        // Configure I2C for location Alternative 1.
        PERCFG &= ~PERCFG_I2CCFG;
      
        // Give priority to I2C over Timer 1 for port 0 pins.
        PPRI &= ~PPRI_PRI1P0;
    
        // Set P0_6 and P0_7 as peripheral I/O.
        P0SEL |= BIT7 | BIT6;
    
    #elif(chip==2545)
        /***************************************************************************
        * Setup I/O ports
        *
        * Port and pins used by I2C, at the alternative 2 location:
        * I2C SCL:   P2_5    (Debug Connector P18_5)
        * I2C SDA:   P2_6    (Debug Connector P18_3)
        */
    
        // Configure I2C for location Alternative 2.
        PERCFG |= PERCFG_I2CCFG;
       
        // Give priority to I2C over USART0, then Timer3.
        PPRI = (PPRI & ~PPRI_PRI1P1) | PPRI_PRI1P1_I2C;
    
        // Set P2_5 and P2_6 as peripheral I/O.
        P2SEL |= BIT6 | BIT5;
      
    #elif(chip==2541)
        /***************************************************************************
        * Setup I/O ports
        *
        * CC2541 has dedicated I2C ports
        * I2C SCL:   Pin 2   (Debug Connector P18_5)
        * I2C SDA:   Pin 3   (Debug Connector P18_3)
        */
    
        // Enable I2C on CC2541.
        I2CWC &= ~0x80;
    #endif
    
        // Configure P1_0 as GPIO output for LED1.
        P1SEL &= BIT0;      // GPIO.
        P1DIR |= BIT0;      // Output.
        P1_0 = 0;           // LED1 off.
    
    
      /***************************************************************************
      * Setup interrupt
      */
    
    #if(chip==2541)
        // Clear I2C (P2) CPU interrupt flag.
        P2IF = 0;
    
        // Enable interrupt from I2C by setting [IEN2.P2IE = 1].
        IEN2 |= IEN2_P2IE;
    #elif(chip==2543 || chip==2545)
        // Clear I2C CPU interrupt flag.
        I2CIF = 0;
    
        // Enable interrupt from I2C by setting [IEN2.I2CIE = 1].
        IEN2 |= IEN2_I2CIE;
    #endif
    
        // Enable global interrupts.
        EA = 1;
    
    
        /***************************************************************************
        * Configure I2C
        */
    
        // Enable the I2C module with 33 kHz clock rate.
        // Enable Assert Acknowledge (AA bit).
        // The STArt bit signals a master.
        I2CCFG = (I2CCFG & ~I2CCFG_CR) | I2CCFG_CR_DIV_960 | I2CCFG_ENS1 | I2CCFG_AA | I2CCFG_STA;
    
    
        /* Main Loop, the transfers are interrupt handled. */
        while(1);
    
    }

  • Hi dharmendra,

    You will need to further familiarize yourself with the LIS2DE12TR and use a logic analyzer/oscilloscope to make sure that the I2C interface follows the timing diagrams and format defined inside the datasheet.  The same datasheet should also contain the correct SLAVE_ADDRESS value and further information about the responses given from the LIS2DE12TR based on commands given.  Please make sure that the correct external pull-up resistors are also used, and that the I2CCFG.SI flag is cleared by software at the end of the ISR.

    Regards,
    Ryan

  • Thanks Ryan

    Can you suggest me any example of I2C of CC2543.
    where CC2543 communicates with any I2C sensor and reads the register of the sensor, with or without Using Library.

  • Past the CC2543 examples already noted, you can refer to BLE examples using CC254X devices which share the same I2C peripheral and functional operation.  Thus the I2C resources can directly be copied and applied, furthermore I suspect you could find more examples through an online search.

    https://e2e.ti.com/f/1/t/172539 
    https://e2e.ti.com/f/1/t/376688 

    Regards,
    Ryan

  • Thanks Ryan for helping me and quick reply....