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.

I2C slave on cc2541

Other Parts Discussed in Thread: CC2541, CC2533

Hello all,

I am working on cc2541 device and need to implement i2c slave. I downloaded hal_i2c files from one of the threads.

I want to initialize i2c as slave. The slave initialization function has two arguments, one is address but the other is related to i2ccallback. I didn't understand how this is working.

If someone has already implemented i2c slave, please let me know how this is supposed to be used. And I would greatly appreciate if someone can explain me how i need to declare variable to pass onto the function and how callback is happening.

Regards,

maharjanbk

  • Hi,

    I believe the i2ccallback function might be called when new data is available for you to read out (typically called from the ISR), but that depends on which driver you are using and how it's built. It's easier if you share it with us :)

    If you want to design an i2c slave driver, you'll find Chapter 20 in the CC2540/41 Users Guide very useful.

    Best Regards

  • Hello Nick,

    Thank you for your response to my post. I am not trying to do anything complicated as designing i2c slave driver or so. All I want to do is communicate cc2541 as i2c slave (receive mode ) to other microcontroller (master) where other microcontroller sends some 10 - 15 bytes of data. 

    I haven't understood how i2c slave works but after reading the code (which i have provided below - one i downloaded from some thread and is meant for cc2533 device) i guess, when cc2541 detects its own address will store the transmitted data in some buffer and is read afterwards using HalI2Cread command. But to initiate I2C in slave mode, we have to initialize I2C first. And I didn't understand i2ccallback parameter which needs to be passed. And that i2ccallback parameter is used in function HAL_ASSERT(). Please explain if you have knowledge about this function.

    I hope I have made my problem clear and appreciate ur help on this matter. I have pasted initialization code in BOLD fonts.

    /**************************************************************************************************
    Filename: hal_i2c.c
    Revised: $Date: 2012-03-09 10:36:22 -0800 (Fri, 09 Mar 2012) $
    Revision: $Revision: 29694 $

    Description: This module defines the HAL I2C API for the CC2533.


    Copyright 2011-2012 Texas Instruments Incorporated. All rights reserved.

    IMPORTANT: Your use of this Software is limited to those specific rights
    granted under the terms of a software license agreement between the user
    who downloaded the software, his/her employer (which must be your employer)
    and Texas Instruments Incorporated (the "License"). You may not use this
    Software unless you agree to abide by the terms of the License. The License
    limits your use, and you acknowledge, that the Software may not be modified,
    copied or distributed unless embedded on a Texas Instruments microcontroller
    or used solely and exclusively in conjunction with a Texas Instruments radio
    frequency transceiver, which is integrated into your product. Other than for
    the foregoing purpose, you may not use, reproduce, copy, prepare derivative
    works of, modify, distribute, perform, display or sell this Software and/or
    its documentation for any purpose.

    YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
    PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
    INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
    NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
    TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
    NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
    LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
    INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
    OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
    OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
    (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

    Should you have any questions regarding your right to use this Software,
    contact Texas Instruments Incorporated at www.TI.com.
    **************************************************************************************************/

    /* ------------------------------------------------------------------------------------------------
    * Includes
    * ------------------------------------------------------------------------------------------------
    */

    #include "comdef.h"
    #if (defined HAL_I2C) && (HAL_I2C == TRUE)
    #include "hal_assert.h"
    #include "hal_board_cfg.h"
    #include "hal_i2c.h"
    #include "osal.h"

    /* ------------------------------------------------------------------------------------------------
    * Constants
    * ------------------------------------------------------------------------------------------------
    */

    #define I2C_ENS1 BV(6)
    #define I2C_STA BV(5)
    #define I2C_STO BV(4)
    #define I2C_SI BV(3)
    #define I2C_AA BV(2)
    #define I2C_MST_RD_BIT BV(0) // Master RD/WRn bit to be OR'ed with Slave address.

    #define I2C_CLOCK_MASK 0x83

    #define I2C_PXIFG P2IFG
    #define I2C_IF P2IF
    #define I2C_IE BV(1)

    /* ------------------------------------------------------------------------------------------------
    * Typedefs
    * ------------------------------------------------------------------------------------------------
    */

    typedef enum {
    // HAL_I2C_MASTER mode statuses.
    mstStarted = 0x08,
    mstRepStart = 0x10,
    mstAddrAckW = 0x18,
    mstAddrNackW = 0x20,
    mstDataAckW = 0x28,
    mstDataNackW = 0x30,
    mstLostArb = 0x38,
    mstAddrAckR = 0x40,
    mstAddrNackR = 0x48,
    mstDataAckR = 0x50,
    mstDataNackR = 0x58,

    // HAL_I2C_SLAVE mode statuses.
    slvAddrAckR = 0x60,
    mstLostArbR = 0x68,
    slvAddrAckG = 0x70,
    mstLostArbG = 0x78,
    slvDataAckR = 0x80,
    slvDataNackR = 0x88,
    genDataAckR = 0x90,
    genDataNackR = 0x98,
    slvStopped = 0xA0,
    slvAddrAckW = 0xA8,
    mstLostArbW = 0xB0,
    slvDataAckW = 0xB8,
    slvDataNackW = 0xC0,
    slvLastAckW = 0xC8,

    // HAL_I2C_MASTER/SLAVE mode statuses.
    i2cIdle = 0xF8
    } i2cStatus_t;

    /* ------------------------------------------------------------------------------------------------
    * Macros
    * ------------------------------------------------------------------------------------------------
    */

    #define I2C_WRAPPER_DISABLE() st( I2CWC = 0x0C; )
    #define I2C_CLOCK_RATE(x) st( I2CCFG &= ~I2C_CLOCK_MASK; \
    I2CCFG |= x; )

    #define I2C_CLR_NACK() st( I2CCFG |= I2C_AA; I2CCFG &= ~I2C_SI; )
    #define I2C_SET_NACK() st( I2CCFG &= ~I2C_AA; )

    // Master to Ack to every byte read from the Slave; Slave to Ack Address & Data from the Master.
    #define I2C_ENABLE() st( I2CCFG |= (I2C_ENS1 | I2C_AA); )

    // Must clear SI before setting STA and then STA must be manually cleared.
    #define I2C_STRT() st ( \
    I2CCFG &= ~I2C_SI; \
    I2CCFG |= I2C_STA; \
    while ((I2CCFG & I2C_SI) == 0); \
    I2CCFG &= ~I2C_STA; \
    )

    // Must set STO before clearing SI.
    #define I2C_STOP() st ( \
    I2CCFG |= I2C_STO; \
    I2CCFG &= ~I2C_SI; \
    while ((I2CCFG & I2C_STO) != 0); \
    )

    // Stop clock-stretching and then read when it arrives.
    #define I2C_READ(_X_) st ( \
    I2CCFG &= ~I2C_SI; \
    while ((I2CCFG & I2C_SI) == 0); \
    (_X_) = I2CDATA; \
    )

    // First write new data and then stop clock-stretching.
    #define I2C_WRITE(_X_) st ( \
    I2CDATA = (_X_); \
    I2CCFG &= ~I2C_SI; \
    while ((I2CCFG & I2C_SI) == 0); \
    )

    // Stop clock-stretching and then read when it arrives.
    #define SLV_READ(_X_) st ( \
    I2CCFG &= ~I2C_SI; \
    while (((I2CCFG & I2C_SI) == 0) \
    && (I2CSTAT != slvStopped)); \
    (_X_) = I2CDATA; \
    )

    // First write new data and then stop clock-stretching.
    #define SLV_WRITE(_X_) st ( \
    I2CDATA = (_X_); \
    I2CCFG &= ~I2C_SI; \
    while (((I2CCFG & I2C_SI) == 0) \
    && (I2CSTAT != slvStopped)); \
    )

    #if HAL_I2C_POLLED
    #define I2C_INT_ENABLE()
    #else
    #define I2C_INT_ENABLE() st( IEN2 |= I2C_IE; )
    #endif
    #define I2C_INT_DISABLE() st( IEN2 &= ~I2C_IE; )

    /* ------------------------------------------------------------------------------------------------
    * Local Variables
    * ------------------------------------------------------------------------------------------------
    */

    static uint8 i2cAddrSave, i2cCfgSave; // Save & restore variables for PM.

    #if HAL_I2C_MASTER
    static uint8 i2cAddr; // Target Slave address pre-shifted up by one leaving RD/WRn LSB as zero.

    #else // if HAL_I2C_SLAVE

    static i2cCallback_t i2cCB;
    static volatile i2cLen_t i2cRxIdx, i2cTxIdx;
    static uint8 i2cRxBuf[HAL_I2C_BUF_MAX+1], i2cTxBuf[HAL_I2C_BUF_MAX+1];
    #endif

    static volatile i2cLen_t i2cRxLen, i2cTxLen;

    #if HAL_I2C_MASTER
    /**************************************************************************************************
    * @fn i2cMstStrt
    *
    * @brief Attempt to send an I2C bus START and Slave Address as an I2C bus Master.
    *
    * input parameters
    *
    * @param RD_WRn - The LSB of the Slave Address as Read/~Write.
    *
    * output parameters
    *
    * None.
    *
    * @return The I2C status of the START request or of the Slave Address Ack.
    */
    static uint8 i2cMstStrt(uint8 RD_WRn)
    {
    I2C_STRT();

    if (I2CSTAT == mstStarted)
    {
    I2C_WRITE(i2cAddr | RD_WRn);
    }

    return I2CSTAT;
    }

    /**************************************************************************************************
    * @fn HalI2CInit
    *
    * @brief Initialize the I2C bus as a Master.
    *
    * input parameters
    *
    * @param address - I2C slave address.
    * @param clockRate - I2C clock rate.
    *
    * output parameters
    *
    * None.
    *
    * @return None.
    */
    void HalI2CInit(uint8 address, i2cClock_t clockRate)
    {
    i2cAddr = address << 1;

    I2C_WRAPPER_DISABLE();
    I2C_CLOCK_RATE(clockRate);
    I2C_ENABLE();
    }

    /**************************************************************************************************
    * @fn HalI2CRead
    *
    * @brief Read from the I2C bus as a Master.
    *
    * input parameters
    *
    * @param len - Number of bytes to read.
    * @param pBuf - Pointer to the data buffer to put read bytes.
    *
    * output parameters
    *
    * None.
    *
    * @return The number of bytes successfully read.
    */
    i2cLen_t HalI2CRead(i2cLen_t len, uint8 *pBuf)
    {
    // mycode-------------- write first register address to read
    i2cMstStrt(0);
    I2C_WRITE(*pBuf++);
    //------------------------------------------------------
    if (i2cMstStrt(I2C_MST_RD_BIT) != mstAddrAckR)
    {
    len = 0;
    }

    for (i2cLen_t cnt = 0; cnt < len; cnt++)
    {
    I2C_READ(*pBuf++);

    if (I2CSTAT != mstDataAckR)
    {
    if (I2CSTAT == mstDataNackR)
    {
    len = cnt + 1;
    }
    else
    {
    len = cnt;
    }
    break;
    }
    }

    I2C_STOP();
    return len;
    }

    /**************************************************************************************************
    * @fn HalI2CWrite
    *
    * @brief Write to the I2C bus as a Master.
    *
    * input parameters
    *
    * @param len - Number of bytes to write.
    * @param pBuf - Pointer to the data buffer to write.
    *
    * output parameters
    *
    * None.
    *
    * @return The number of bytes successfully written.
    */
    i2cLen_t HalI2CWrite(i2cLen_t len, uint8 *pBuf)
    {
    if (i2cMstStrt(0) != mstAddrAckW)
    {
    len = 0;
    }

    for (i2cLen_t cnt = 0; cnt < len; cnt++)
    {
    I2C_WRITE(*pBuf++);

    if (I2CSTAT != mstDataAckW)
    {
    if (I2CSTAT == mstDataNackW)
    {
    len = cnt + 1;
    }
    else
    {
    len = cnt;
    }
    break;
    }
    }

    I2C_STOP();
    return len;
    }

    #else // if HAL_I2C_SLAVE

    /**************************************************************************************************
    * @fn i2cSlvRx
    *
    * @brief Block, reading from the I2C bus as a Slave.
    *
    * input parameters
    *
    * None.
    *
    * output parameters
    *
    * None.
    *
    * @return None.
    */
    static i2cLen_t i2cSlvRx(void)
    {
    uint8 ch, idx = 0;

    do {
    SLV_READ(ch);

    if ((I2CSTAT == slvDataAckR) || (I2CSTAT == slvDataNackR))
    {
    i2cRxBuf[idx++] = ch;
    }

    if (idx == HAL_I2C_BUF_MAX)
    {
    I2C_SET_NACK();
    }
    } while (I2CSTAT == slvDataAckR);

    i2cRxLen = idx;
    i2cRxIdx = 0;
    I2C_CLR_NACK();

    return idx;
    }

    /**************************************************************************************************
    * @fn i2cSlvTx
    *
    * @brief Block, writing to the I2C bus as a Slave.
    *
    * input parameters
    *
    * None.
    *
    * output parameters
    *
    * None.
    *
    * @return None.
    */
    static i2cLen_t i2cSlvTx(void)
    {
    uint8 idx = i2cTxIdx, len = i2cTxLen;

    while (1)
    {
    if (len == 1)
    {
    I2C_SET_NACK(); // Setup to write last byte.
    }
    SLV_WRITE(i2cTxBuf[idx]);

    if ((I2CSTAT == slvDataAckW) || (I2CSTAT == slvLastAckW) || (I2CSTAT == slvDataNackW))
    {
    idx++;

    if ((--len == 0) || (I2CSTAT == slvDataNackW))
    {
    break;
    }
    }
    else
    {
    break;
    }
    }

    i2cTxIdx = idx;
    i2cTxLen = len;
    I2C_CLR_NACK();

    return len;
    }

    /**************************************************************************************************
    * @fn HalI2CInit
    *
    * @brief Initialize the I2C bus as a Slave.
    *
    * input parameters
    *
    * @param address - I2C slave address.
    * @param i2cCallback - I2C callback.
    *
    * output parameters
    *
    * None.
    *
    * @return None.
    */
    void HalI2CInit(uint8 address, i2cCallback_t i2cCallback)
    {
    i2cCB = i2cCallback;
    HAL_ASSERT(i2cCB);

    I2C_WRAPPER_DISABLE();
    I2CADDR = address << 1;
    I2C_ENABLE();
    // Clear the CPU interrupt flag for Port_2 PxIFG has to be cleared before PxIF.
    I2C_PXIFG = 0;
    I2C_IF = 0;
    I2C_INT_ENABLE();
    }

    /**************************************************************************************************
    * @fn HalI2CRead
    *
    * @brief Read the data read from the I2C bus as a Slave.
    *
    * input parameters
    *
    * @param len - Number of bytes to read.
    * @param pBuf - Pointer to the data buffer to put read bytes.
    *
    * output parameters
    *
    * None.
    *
    * @return The number of bytes successfully read.
    */
    i2cLen_t HalI2CRead(i2cLen_t len, uint8 *pBuf)
    {
    uint8 rxLen = i2cRxLen;

    if (len >= rxLen)
    {
    len = rxLen;
    rxLen = 0;
    }
    else
    {
    rxLen -= len;
    }

    (void)osal_memcpy(pBuf, i2cRxBuf+i2cRxIdx, len);
    i2cRxIdx += len;
    i2cRxLen = rxLen;

    return len;
    }

    /**************************************************************************************************
    * @fn HalI2CWrite
    *
    * @brief Write the data to write to the I2C bus as a Slave.
    *
    * input parameters
    *
    * @param len - Length of the data buffer to write.
    * @param pBuf - Pointer to the data buffer to write.
    *
    * output parameters
    *
    * None.
    *
    * @return The number of bytes setup to write.
    */
    i2cLen_t HalI2CWrite(i2cLen_t len, uint8 *pBuf)
    {
    #if ((HAL_I2C_BUF_MAX != 255) && (HAL_I2C_BUF_MAX != 65535))
    if (len > HAL_I2C_BUF_MAX)
    {
    len = HAL_I2C_BUF_MAX;
    }
    #endif

    if (i2cTxLen != 0) // Refuse to overwrite old msg with new data so no race with ISR.
    {
    return 0;
    }

    (void)osal_memcpy(i2cTxBuf, pBuf, len);
    i2cTxIdx = 0;
    i2cTxLen = len;

    if (I2CSTAT == slvAddrAckW)
    {
    i2cSlvTx();
    I2C_INT_ENABLE();
    }

    return len;
    }

    /**************************************************************************************************
    * @fn HalI2CPoll
    *
    * @brief Poll the I2C module as a Slave when not running by ISR.
    *
    * input parameters
    *
    * None.
    *
    * output parameters
    *
    * None.
    *
    * @return None.
    */
    #if HAL_I2C_POLLED
    void HalI2CPoll(void)
    #else
    HAL_ISR_FUNCTION(halI2CIsr, I2C_VECTOR)
    #endif
    {
    HAL_ENTER_ISR();

    switch (I2CSTAT)
    {
    case slvAddrAckR:
    if (i2cRxLen == 0)
    {
    i2cSlvRx(); // Block, receiving bytes from the Master.
    }
    else // Rx overrun.
    {
    volatile uint8 ch;
    // Throw away these new bytes & leave old msg so no race with background HalI2CRead().
    I2C_SET_NACK();
    SLV_READ(ch);
    I2C_CLR_NACK();
    }

    (void)i2cCB(i2cRxLen); // Alert Application that a Master Tx is ready to read.
    break;

    case slvAddrAckW:
    if (i2cTxLen != 0)
    {
    i2cSlvTx(); // Block, transmitting bytes to the Master.
    }
    else if (i2cCB(0) == FALSE)
    {
    I2C_SET_NACK();
    SLV_WRITE(0);
    I2C_CLR_NACK();
    }
    else
    {
    /* Slave will be clock-stretching, blocking master, until Application makes a HalI2CWrite().
    * While addressed as a slave, the I2C ISR keeps firing even though the I2CSTAT is not
    * changing and the flags are cleared below. So this special ISR disable here to be
    * re-enabled within the slave HalI2CWrite() function.
    */
    I2C_INT_DISABLE();
    }
    break;

    case i2cIdle: // Not expected, but not really an error, so no need to execute a STOP.
    break;

    default:
    I2C_STOP();
    I2C_CLR_NACK(); // Setup to Ack the next time addressed.
    break;
    }

    // Clear the CPU interrupt flag for Port_2 PxIFG has to be cleared before PxIF.
    I2C_PXIFG = 0;
    I2C_IF = 0;

    HAL_EXIT_ISR();
    }
    #endif

    /**************************************************************************************************
    * @fn HalI2CReady2Sleep
    *
    * @brief Determine whether the I2C is ready to sleep.
    *
    * input parameters
    *
    * None.
    *
    * output parameters
    *
    * None.
    *
    * @return 1 if the I2C is ready to sleep; 0 otherwise.
    */
    uint8 HalI2CReady2Sleep(void)
    {
    return ((i2cRxLen == 0) && (i2cTxLen == 0) && (I2CSTAT == i2cIdle));
    }

    /**************************************************************************************************
    * @fn HalI2CEnterSleep
    *
    * @brief Save I2C state before entering a Power Mode.
    *
    * input parameters
    *
    * None.
    *
    * output parameters
    *
    * None.
    *
    * @return None.
    */
    void HalI2CEnterSleep(void)
    {
    i2cCfgSave = I2CCFG;
    i2cAddrSave = I2CADDR;
    }

    /**************************************************************************************************
    * @fn HalI2CExitSleep
    *
    * @brief Restore I2C state after exiting a Power Mode.
    *
    * input parameters
    *
    * None.
    *
    * output parameters
    *
    * None.
    *
    * @return None.
    */
    void HalI2CExitSleep(void)
    {
    I2CCFG = i2cCfgSave;
    I2CADDR = i2cAddrSave;
    }

    #endif
    /**************************************************************************************************
    */

  • Hi Joakim,

    I am also working on getting the CC2541 to work as an I2C Slave and I have an external MCU that is configured as an I2C Master. I know that the I2C master works well because I have connected it to another I2C slave and managed to get the information reliably.

    The problem I am having is the ISR routine never gets called on the CC2541 device. The I2C master also complains that the slave has not acknowledged the address. So the communication is failing at a very early stage.

    Following is the ISR I have for the slave and I put a breakpoint on the line indicated below. However, the program counter never reaches there. This tells me that the I2C interrupt never fires.

    HAL_ISR_FUNCTION( halI2CIsr, I2C_VECTOR )
    {/* I2C interrupt handler routine */
      HAL_ENTER_ISR();

      P2IFG = 0; // THIS IS WHERE I PLACED A BREAKPOINT IN DEBUG MODE. PROGRAM COUNTER NEVER REACHES HERE!
      P2IF    = 0;

      HAL_EXIT_ISR();

    }

    Any feedback or suggestions will be greatly appreciated.

    Regards...

  • Why is it that I find the answer shortly after posting the question? This is the second time it has happened today!! Well, at least I cannot complain that using the forum is not helping, right? :)

    I added the following to the I2C initialisation routine and the interrupts started firing!.

      I2CCFG |= I2C_AA;

    The above change allows the slave to send an ACK when it recognises its own address, which is what my I2C master is expecting.

    Could the documentation on the I2C be improved somehow? It is not as clear as some of the other MCU vendors' documentation I have used before. TI's documentation is generally very good but I found the I2C part to be a bit difficult to follow. For example, the above setting was only mentioned in a table which can eaasily be missed.

    Regards...

  • Hi,

    Cryptoman said:
    Could the documentation on the I2C be improved somehow?

    Yes, the I2C driver is not officially part of the SDK and is therefore not fully documented in the software development guide. The only example of it that I know is the Sensor Tag project. There's a lot of details in the SoC users guide though, which I assume you found. But you have a good point.

    Best Regards

    Joakim

  • Joakim Lindh said:
    The only example of it that I know is the Sensor Tag project.

    That's good to know. I was not aware of that. Thanks. I can review the implementation there to improve what I have written so far.

    Joakim Lindh said:
    There's a lot of details in the SoC users guide though, which I assume you found.

    You are right. That reference was the main one I used to come as far as I have. It took some time to make sense of some of the statements and to locate the information that was needed.

    It was not the end of the world but when you know it could be easier, you tend to complain. As stated in "The Matrix": "Ignorance is bliss" (sometimes, of course :) )

    Regards...

  • Hi,

    i am trying to connect Gyroscope (L3GD20) with CC2541 through I2C communication. Im using TI Keyfob Sample program for the same but unfortunately i am not able to establish communication with the device.

     we tried to capture SCL and SDA from the ports on CC2541with out any slave connected(attaching the same for your reference). But with the slave connected, we are not able to recieve any acknowledgement from the slave after start condition.


    please refer to the I2C code that we have implemented for our slave Gyro and let me know if any corrections to be done for establishing basic I2C communication link.

    im also attaching the code for your reference

    #include<ioCC2541.h>

    #define BV(n) (1 << (n))

    typedef unsigned char u8_t;
    typedef unsigned short int u16_t;
    typedef short int i16_t;
    typedef signed char i8_t;

    #define I2C_ENS1 BV(6)
    #define I2C_STA BV(5)
    #define I2C_STO BV(4)
    #define I2C_SI BV(3)
    #define I2C_AA BV(2)

    #define RESET P0_6
    #define led1 P1_0
    #define led2 P1_1

    #define I2C_SR 0xE0 
    #define I2C_SP 0xD0 
    #define I2C_DO 0xC0

    #define CLKCON_OSC32K 0x80 // 32 kHz clock source select/status
    #define CLKCON_OSC 0x40 // system clock source select/status
    #define CLKCON_TICKSPD (0x07 << 3) // bit mask, global timer tick speed divider
    #define CLKCON_TICKSPD_32M (0x00 << 3)
    #define CLKCON_TICKSPD_16M (0x01 << 3)
    #define CLKCON_TICKSPD_8M (0x02 << 3)
    #define CLKCON_TICKSPD_4M (0x03 << 3)
    #define CLKCON_TICKSPD_2M (0x04 << 3)
    #define CLKCON_TICKSPD_1M (0x05 << 3)
    #define CLKCON_TICKSPD_500K (0x06 << 3)
    #define CLKCON_TICKSPD_250K (0x07 << 3)
    #define CLKCON_CLKSPD (0x07) // bit mask for the clock speed division
    #define CLKCON_CLKSPD_32M (0x00)
    #define CLKCON_CLKSPD_16M (0x01)
    #define CLKCON_CLKSPD_8M (0x02)
    #define CLKCON_CLKSPD_4M (0x03)
    #define CLKCON_CLKSPD_2M (0x04)
    #define CLKCON_CLKSPD_1M (0x05)
    #define CLKCON_CLKSPD_500K (0x06)
    #define CLKCON_CLKSPD_250K (0x07)

    #define L3G4200D_OUT_X_L 0x28
    #define L3G4200D_OUT_X_H 0x29
    #define L3G4200D_OUT_Y_L 0x2A
    #define L3G4200D_OUT_Y_H 0x2B
    #define L3G4200D_OUT_Z_L 0x2C
    #define L3G4200D_OUT_Z_H 0x2D

    typedef enum {
    X_AXIS =0x01,
    Y_AXIS =0x02,
    Z_AXIS=0x03
    } axis;

    void i2c_init();
    void gyro_start();
    void gyro_stop();
    void gyro_send(unsigned char x);
    void gyro_write(unsigned char reg,unsigned char dat);
    unsigned char gyro_receive(unsigned char reg);
    void gyro_init();
    void delay(unsigned char n);
    void timer_delay(unsigned char m);

    ******************************************************************************************

    #include<ioCC2541.h>
    #include<gyro.h>
    void gyro_start()
    {
    I2CCFG &=~I2C_SI;
    I2CCFG |=I2C_STA;
    while((I2CCFG&I2C_SI)==0);
    I2CCFG &=~I2C_STA;
    }
    void gyro_stop()
    {
    I2CCFG &=I2C_STO;
    I2CCFG |=~I2C_SI;
    while((I2CCFG&I2C_STO)!=0);
    }
    void gyro_send(unsigned char x)
    {
    I2CDATA = x; 
    I2CCFG &= ~I2C_SI; 
    while ((I2CCFG & I2C_SI) == 0);
    }

    unsigned char gyro_read()
    {
    I2CCFG &= ~I2C_SI; 
    while ((I2CCFG & I2C_SI) == 0); 
    return I2CDATA; 
    }

    void gyro_write(unsigned char reg,unsigned char dat)
    {
    I2CCFG=I2C_SR;

    I2CDATA=0xD4;
    I2CCFG=I2C_DO;

    I2CDATA=reg;
    I2CCFG=I2C_DO;

    I2CDATA=dat;
    I2CCFG=I2C_DO;

    I2CCFG=I2C_SP;

    }
    unsigned char gyro_receive(unsigned char reg)
    {
    I2CCFG=I2C_SR;

    I2CDATA=0xD4;
    I2CCFG=I2C_DO;

    I2CDATA=reg;
    I2CCFG=I2C_DO;

    I2CCFG=I2C_SR;

    I2CDATA=0xD5;
    I2CCFG=I2C_DO;

    I2CCFG=I2C_DO;

    I2CCFG=I2C_SP;

    return I2CDATA;
    }
    void i2c_init()


    //I2CCFG=0x45;
    I2CWC = 0x00;
    }
    void gyro_init()
    {
    gyro_write(0x20,0x0F);
    gyro_write(0x21,0x29);
    gyro_write(0x22,0x80);
    gyro_write(0x23,0x20);
    gyro_write(0x32,0x2C);
    gyro_write(0x33,0xA4);
    gyro_write(0x34,0x2C);
    gyro_write(0x35,0xA4);
    gyro_write(0x36,0x2C);
    gyro_write(0x37,0xA4);
    gyro_write(0x38,0x00);
    gyro_write(0x30,0x2A);
    }

    i16_t L3G4200D_GetAngRateRaw(axis a) 
    {
    u8_t valueL;
    u8_t valueH;
    u16_t value;
    switch (a)
    {
    case X_AXIS:
    valueL=gyro_receive(L3G4200D_OUT_X_L);


    valueH=gyro_receive(L3G4200D_OUT_X_H);


    value = (i16_t)( (valueH << 8) | valueL );
    break;
    case Y_AXIS:
    valueL=gyro_receive(L3G4200D_OUT_Y_L);

    valueH=gyro_receive(L3G4200D_OUT_Y_H);


    value = (i16_t)( (valueH << 8) | valueL );
    break;
    case Z_AXIS:
    valueL=gyro_receive(L3G4200D_OUT_Z_L);


    valueH=gyro_receive(L3G4200D_OUT_Z_H);


    value = (i16_t)( (valueH << 8) | valueL );
    break;
    }
    return value; 
    }

    i am also attaching the schematic for your reference

    4530.CC2541 Keyfob with GYRO.pdf

    A quick reply for this problem will be really helpful for us as we are running out of time

    Thanks in advance

    Regards,

    Krishna

  • Hi Krishna,

    My project with CC2541 involves using it as a slave rather than a master, which is the opposite of what you are working on. In your case the CC2541 is the master and the gyroscope is the slave.

    I checked your schematic and the connections seem to look OK. The buss pull-up resistors are the same as what I have here. The supply power is 2.1V in your case whereas I stick to the good old 3.3V.

    I did not get a chance to study the code you have provided but had a quick look through. One thing I spotted is how you are waiting for the SI interrupt flag to be asserted. You are basically using a while loop that will block everything else until your SI flag is asserted. Rather than doing this, I recommend that you use an interrupt service routine (ISR). As mentioned in an earlier post, please have a look at the Sensor Tag sample project that makes use of the I2C communication. I am sure you will find some good features to directly copy and paste into your existing project.

    Also, I want to share another information that I discovered while working on another I2C project of mine. You might want to have a look at the datasheet of your gyroscope to see if it needs a repeated start condition to be able to provide internal data. Usually each I2C slave device datasheet includes a section where the details of the I2C communication is explained. Some slave devices behave differently and that can cause read issues. For example, in my project the real time clock and the accelerometer share the same I2C bus. However, the accelerometer requires a repeated start to be read whereas the RTC works without a repeated start. It took me a while to discover this and until then my accelerometer was not working at all.

    I also suggest that you introduce two functions called "i2c_write" and "i2c_read" which will tidy up your code in general. Your top level functions can call these two low level functions as and when needed, which I am sure will make testing much easier for you.

    I will keep you posted if I spot other issues in your code.

    In the meantime, good luck with your work!

    Regards...

  • Hi Cryptoman,

    I got the device working Perfect through I2C communication link

    Thanks for your valuable advice and help in time.

    Regards,

    Krishna

  • Hi Krishna,

    I am glad to hear that you managed to sort out your problem. Was the problem related to the ppints I mentioned in my post or there was some other issue?

    Regards...

  • Hi Cryptoman,

    we made a couple of corrections to the code which enabled I2C communication link, they are

    1) we enabled SDA and SCL pullup enable  in I2CWC Register

    2) we have added the following line of code -I2CCFG |= (I2C_ENS1 | I2C_AA)

    your points were really helpful in sorting out this issue..

    Thanks again

    Regards,

    Krishna

  • Hi Cryptoman,

    I got one more problem with another slave(OLED) which was also connected to the master(CC2541) through I2C . In this case Master(CC2541) is communicating with the slave(OLED SSD1306) and i am able to get acknowledgement for commands from the slave for Start, Slave Address and Data Receive but not able to get acknowledgement for the data from slave and not able to display any data on the slave(OLED).

    I tried with both 32MHz and  8MHz system clock, but the result was same

    I am also attaching the updated code for your reference, kindly please check the code and suggest me suitable corrections to sort out this issue.

    #include<ioCC2541.h>
    #include<oled.h>

    unsigned char logo1[4][132] =
    {
    {0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0x0C,0x06,0x03,0x01,0x03,0x06,0xCC,0xE0,0xF0,0xF8,0xFC,0x06,0x03,0x01,0x03,0x06,0x0C,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
    {0x00,0x00,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0x00,0x00,0xE0,0xF8,0x38,0x1C,0x1C,0x1C,0x3C,0x78,0xF0,0xC0,0x00,0x00,0x7C,0xFC,0xC0,0x00,0x00,0x00,0x00,0x00,0xF1,0xFF,0x1F,0x7C,0xE0,0x00,0x00,0x00,0x30,0x38,0x1C,0x8C,0xCC,0xF8,0xF0,0x00,0x00,0x78,0xFC,0x0C,0x0C,0x00,0x78,0xFC,0xCC,0x8C,0x98,0xFC,0xFC,0x00,0x00,0x3C,0xFC,0xC0,0x00,0x7C,0xFC,0xC0,0x00,0x00,0xF0,0xF8,0x1C,0x0C,0x0C,0x1C,0x38,0xF0,0xC0,0x00,0x7C,0xFC,0xC0,0x00,0x00,0x00,0x3C,0xFC,0xC0,0x00,0x78,0xFC,0x0C,0x0C,0x00,0x1C,0x3C,0x7C,0xCC,0x8C,0x0C,0x0C,0x00,0x00,0x00},
    {0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x1F,0x7F,0xF0,0xC0,0x80,0x80,0x80,0x80,0xC0,0xF0,0x30,0x00,0x00,0x3F,0x3F,0x0C,0x18,0x38,0x20,0x00,0x3F,0x3F,0x00,0x00,0x03,0x1F,0x3C,0x20,0x00,0x0F,0x1F,0x33,0x31,0x31,0x38,0x18,0x00,0x30,0x3F,0xFC,0xB0,0x30,0x00,0x0C,0x1C,0x31,0x31,0x31,0x3F,0x1F,0x00,0x00,0x7F,0xFF,0x80,0x30,0x7F,0xFF,0xB0,0x30,0x07,0x0F,0x1C,0x38,0x30,0x30,0x38,0x1F,0x07,0x00,0x00,0x3F,0x3F,0x0C,0x10,0x30,0x30,0x3F,0x1F,0x00,0x30,0x3F,0xFC,0xB0,0x30,0x00,0x30,0x30,0x31,0x33,0x3E,0x3C,0x38,0x00,0x00},
    {0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x30,0x60,0xC0,0x80,0xC0,0x60,0x33,0x07,0x0F,0x1F,0x3F,0x60,0xC0,0x80,0xC0,0x60,0x30,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x01,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
    };

    unsigned char logo2[4][132] =
    {
    {0x00,0xF8,0x00,0x00,0x00,0xF8,0x00,0x00,0xF8,0x08,0xF8,0x08,0xFF,0x10,0x08,0x18,0xF0,0x00,0x00,0x08,0x00,0x38,0xC0,0x00,0x38,0xC0,0x00,0xE0,0x18,0xE0,0x00,0xE0,0x18,0xE0,0x00,0xE0,0x18,0xE0,0x00,0xE0,0x18,0xE0,0x00,0xE0,0x18,0xE0,0x00,0xE0,0x18,0xE0,0x00,0x00,0x08,0x00,0xF0,0x08,0x08,0x30,0x00,0xF8,0x00,0x00,0x00,0x01,0xE1,0x1E,0xE0,0x00,0x00,0x30,0x88,0x88,0x70,0x00,0xF8,0x08,0x30,0x48,0x48,0x90,0xF8,0x00,0xF8,0x00,0xF8,0x00,0xF0,0x18,0x08,0x18,0xF0,0x00,0xF8,0x00,0x00,0x00,0xF8,0x00,0xF8,0x08,0x18,0x68,0x88,0x08,0x00,0x00,0x08,0x00,0xF0,0x08,0x08,0x30,0x00,0xF0,0x18,0x08,0x18,0xF0,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00,0xF8,0x00},
    {0x00,0x3F,0x02,0x04,0x04,0x03,0x00,0x04,0x3F,0x04,0x3F,0x04,0x07,0x02,0x04,0x06,0x03,0x00,0x00,0x04,0x00,0x00,0x03,0x3C,0x00,0x03,0x3C,0x07,0x00,0x01,0x06,0x01,0x00,0x07,0x00,0x07,0x00,0x01,0x06,0x01,0x00,0x07,0x00,0x07,0x00,0x01,0x06,0x01,0x00,0x07,0x00,0x00,0x00,0x00,0x03,0x04,0x04,0x03,0x00,0x07,0x02,0x04,0x00,0x06,0x01,0x00,0x01,0x06,0x00,0x03,0x04,0x04,0x02,0x04,0x3F,0x04,0x03,0x04,0x04,0x04,0x03,0x00,0x3F,0x04,0x3F,0x24,0x03,0x06,0x04,0x06,0x03,0x00,0x07,0x02,0x04,0x04,0x03,0x04,0x3F,0x04,0x04,0x04,0x05,0x06,0x00,0x00,0x00,0x00,0x03,0x04,0x04,0x03,0x00,0x03,0x06,0x04,0x06,0x03,0x00,0x00,0x07,0x04,0x04,0x07,0x04,0x04,0x03,0x00},
    {0x00,0xF0,0x0C,0x02,0x02,0x02,0x0C,0x30,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0xF0,0x40,0x40,0x40,0xF0,0x0E,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x06,0x1A,0x22,0xC2,0x82,0x02,0x00,0x00,0xF8,0x86,0x02,0x02,0x86,0xF8,0x00,0x00,0x18,0x04,0x02,0x02,0x84,0xF8,0x00,0x00,0x06,0x1A,0x22,0xC2,0x82,0x02,0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x02,0x0C,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x06,0x02,0x82,0x46,0x3C,0x00,0x00,0x00,0xF8,0x46,0x42,0x46,0xCC,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0xF8,0x46,0x42,0x46,0xCC,0x00,0x00,0x8C,0x42,0x42,0x22,0x3C,0x00},
    {0x00,0x0F,0x30,0x40,0x40,0x40,0x20,0x18,0x00,0x00,0x00,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,0x00,0x01,0x3F,0x40,0x3E,0x01,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x30,0xFF,0x00,0x00,0x00,0x00,0x30,0xC0,0x80,0x80,0xC3,0x3E,0x00,0x00,0x3E,0xC3,0x81,0x81,0x43,0x3E,0x00,0x00,0x60,0x80,0x81,0x81,0xC3,0x3C,0x00,0x00,0x30,0xC0,0x80,0x80,0xC3,0x3E,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x61,0x41,0x40,0x60,0x18,0x00,0x00,0x00,0x01,0x06,0x04,0x06,0x01,0x00,0x00,0x00,0x07,0x03,0x06,0x00,0x00,0x47,0x00,0x00,0x00,0x01,0x06,0x04,0x06,0x01,0x00,0x00,0x03,0x04,0x04,0x04,0x03,0x00},
    };

    void oled_start()
    {
    I2CCFG &=~I2C_SI;
    I2CCFG |=I2C_STA;
    while((I2CCFG&I2C_SI)==0);
    I2CCFG &=~I2C_STA;
    }
    void oled_stop()
    {
    I2CCFG &=I2C_STO;
    I2CCFG |=~I2C_SI;
    while((I2CCFG&I2C_STO)!=0);
    }
    void oled_send(unsigned char x)
    {
    I2CDATA = x;
    I2CCFG &= ~I2C_SI;
    while ((I2CCFG & I2C_SI) == 0);
    }

    unsigned char oled_read()
    {
    I2CCFG &= ~I2C_SI;
    while ((I2CCFG & I2C_SI) == 0);
    return I2CDATA;
    }

    void oled_command(unsigned char cmd)
    {
    I2CCFG=I2C_SR;
    wait_ack(SR_SENT); //start_ack


    I2CDATA=0x78;
    I2CCFG=I2C_DO;
    wait_ack(SLAW_ACK_SENT); //slave address+W ack


    I2CDATA=0x00;
    I2CCFG=I2C_DO;
    wait_ack(DATA_ACK_SENT); //data sent ack


    I2CDATA=cmd;
    I2CCFG=I2C_DO;
    wait_ack(DATA_ACK_SENT); //data sent ack
    led1=1;
    led2=0;


    I2CCFG=I2C_SP;

    }
    void oled_data(unsigned char dat)
    {
    I2CCFG=I2C_SR;
    wait_ack(SR_SENT); //start_ack


    I2CDATA=0x78;
    I2CCFG=I2C_DO;
    wait_ack(SLAW_ACK_SENT); //slave address+W ack


    I2CDATA=0x40;
    I2CCFG=I2C_DO;
    wait_ack(DATA_ACK_SENT); //data sent ack

    I2CDATA=dat;
    I2CCFG=I2C_DO;
    wait_ack(DATA_ACK_SENT); //data sent ack


    I2CCFG=I2C_SP;

    }
    void i2c_init()
    {

    I2CCFG=I2C_DO;
    I2CWC |= ~0x80;
    }
    void oled_init()
    {
    RESET=0;
    delay(128);
    RESET=1;
    delay(128);
    /**oled_command(0xAE);
    oled_command(0xD5);
    oled_command(0x80);
    oled_command(0xA8);
    oled_command(0x1F);
    oled_command(0xD3);
    oled_command(0x00);
    oled_command(0x40);
    oled_command(0x8D);
    oled_command(0x14);
    oled_command(0xA1);
    oled_command(0xC8);
    oled_command(0xDA);
    oled_command(0x02);
    oled_command(0x81);
    oled_command(0xCF);
    oled_command(0xD9);
    oled_command(0xF1);
    oled_command(0xDB);
    oled_command(0x40);
    oled_command(0xA4);
    oled_command(0xA6);
    oled_command(0xAF);***/
    oled_command(0xAE);//--Set Display off

    led1=0;
    led2=1;

    oled_command(0x00);//--set low column address

    oled_command(0x10);//--set high column address

    oled_command(0x81);//--set contrast control register
    oled_command(0x7f);

    oled_command(0xa1);//--set segment re-map 95 to 0

    oled_command(0xA6);//--set normal display

    oled_command(0xa8);//--set multiplex ratio(1 to 16)
    oled_command(0x1f);//--duty 1/32

    oled_command(0xd3);//--set display offset
    oled_command(0x00);//--not offset

    oled_command(0xd5);//--set display clock divide ratio/oscillator frequency
    oled_command(0xf0);//--set divide ratio

    oled_command(0xd9);//--set pre-charge period
    oled_command(0x22);

    oled_command(0xda);//--set com pins hardware configuration
    oled_command(0x02);//disable left/right remap and set for sequential

    oled_command(0xdb);//--set vcomh
    oled_command(0x49);//--0.83*vref

    oled_command(0x8d);//--set DC-DC enable
    oled_command(0x14);//

    oled_command(0xAF);//--turn on oled panel

    oled_command(0xA4);//--Entire Display ON

    //timer_delay(100);
    }

    void delay(unsigned char n)
    {
    while(n--)
    asm("nop");
    }
    void timer_delay(unsigned char m)
    {
    unsigned char i;
    T3CTL|=0x10;
    for(i=0;i<m;i++)
    {
    while((TIMIF&0x01)==0);
    T3OVFIF=0;
    }
    }

    void show_bitmap(unsigned char bitmap)
    {
    unsigned char j=0;
    unsigned char i=0;

    for(i=0;i<8;i++)
    {
    oled_command(0x00); //lower column address
    oled_command(0x10); //upper column address
    oled_command(0xB0+i); //set page address
    for(j=0;j<128;j++)
    {
    if(bitmap==0)
    {
    led1=0;
    led2=1;
    oled_data(logo1[i][j]);
    }
    else
    {

    oled_data(logo2[i][j]);
    }
    }
    }
    }

    void wait_ack(unsigned char ack)
    {
    while(I2CSTAT!=ack);
    }

    ***************************************************************************************************

    #include<ioCC2541.h>
    #include<oled.h>
    int main(void)
    {
    CLKCONCMD = (CLKCONCMD & ~(CLKCON_OSC | CLKCON_CLKSPD)) | CLKCON_CLKSPD_8M ;
    while (CLKCONSTA & CLKCON_OSC); // Wait until clock source has changed
    P0SEL|=0x00;
    P0DIR|=0x40;
    P1SEL|=0x00;
    P1DIR|=0x03;
    T3IE=1;
    T3CC0=250;
    T3CTL|=0xFF;
    P2IEN=0x20;
    IEN2 |=0x02;
    P2IFG = 0;
    P2IF=0;
    EA=1;
    led1=0;
    led2=0;
    i2c_init();
    oled_init();
    while(1)
    {

    show_bitmap(0);
    }
    }

    #pragma vector =P2INT_VECTOR
    __interrupt void P2INT_ISR(void)
    {
    P2IFG=0x00;
    P2IF=0;
    if(I2CSTAT==0x28)
    {
    //led1=1;
    //led2=0;
    }

    }



    Thanks & Regards,
    Krishna

  • Hi Cryptoman,

    An important addition to the above query, as we are getting stuck at no offset command which is 0x00, whether it might be causing problem in communicating with the device.

    If in that case any solution regarding that command that helps in getting communication work will be very helpful for us. 

    Thanks& Regards,

    Krishna.