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/CC2640: MCP7940N RTC on I2C with CC2640

Part Number: CC2640
Other Parts Discussed in Thread: CC2650STK

Tool/software: Code Composer Studio

Hi,

I am trying to interface MCP7940N RTC chip with CC2640 via I2C.

I am using Latest BLE stack and CCS v7.

I have modified the I2C example in BLE stack for sensortag and changed the I2C pins in CC2650STK.h .

I can get a true response from I2C_open(Board_I2C, &i2cParams);

But I2C_transfer(i2c, &i2cTransaction) always fails.

Am I missing something?

I have pasted the code below.

/***************************************************************/
  /* Create I2C for usage */
  I2C_Params_init(&i2cParams);
  i2cParams.bitRate = I2C_400kHz;
  i2c = I2C_open(Board_I2C, &i2cParams);
  if (i2c == NULL) {
      UART_write(uart, "\n\rError Initializing I2C", sizeof("\n\rError Initializing I2C"));
  }
  else {
      UART_write(uart, "\n\rInitialized I2C Successfully", sizeof("\n\rInitialized I2C Successfully"));
  }

   uint8_t         txBuffer[1];
   uint8_t         rxBuffer[2];

   txBuffer[0]=0x80;
   i2cTransaction.slaveAddress = 0x6f;
   i2cTransaction.writeBuf = txBuffer;
   i2cTransaction.writeCount = 1;
   i2cTransaction.readBuf = rxBuffer;
   i2cTransaction.readCount = 1;

   if (I2C_transfer(i2c, &i2cTransaction)) {
       UART_write(uart,"Received data is", sizeof("Received data is"));
       UART_write(uart,rxBuffer, sizeof(rxBuffer));
      }
      else {
          UART_write(uart, "\n\rI2C Read Failed", sizeof("\n\rI2C Read Failed"));
      }
   /***************************************************************/

Can any one guide me?

  • Hello Jan,

    As you may have seen from searching other related posts in the forum, the best way to troubleshoot these issues is with the debugger and an I2C bus analyzer or logic analyzer. Stepping through the I2C_transfer function will probably give you more insight.

    Best wishes
  • Hi Jan,

    Are you properly addressing the MCP7940N chip properly?

    It looks like you'll have to follow this section taken from that devices datasheet on page 10:

    Also details for our I2C driver can be found in the SDK at the following: http://dev.ti.com/tirex/content/simplelink_cc2640r2_sdk_1_40_00_45/docs/tidrivers/doxygen/html/_i2_c_c_c26_x_x_8h.html

    There you can see some example use-cases. Taken from the documentation, a basic receive of 10 bytes over I2C is provided below:

    // Locals
    I2C_Handle handle;
    I2C_Params params;
    I2C_Transaction i2cTrans;
    uint8_t rxBuf[32];      // Receive buffer
    uint8_t txBuf[32];      // Transmit buffer
    
    // Configure I2C parameters.
    I2C_Params_init(&params);
    
    // Initialize master I2C transaction structure
    i2cTrans.writeCount   = 0;
    i2cTrans.writeBuf     = txBuf;
    i2cTrans.readCount    = 10;
    i2cTrans.readBuf      = rxBuf;
    i2cTrans.slaveAddress = 0x3C;
    
    // Open I2C
    handle = I2C_open(Board_I2C, &params);
    
    // Do I2C transfer receive
    I2C_transfer(handle, &i2cTrans);

    -Sy Su

  • Hi Sy Su,

    I will go through the below link and update the results.

    Thanks

  • Hi JXS,

    I don't have I2C Bus analyzer, I will try as Sy Su told below.
    If you have any alternative solutions, please let me know.

    Thanks