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/CC1310: problem with I2C SCL start on high.

Part Number: CC1310

Tool/software: Code Composer Studio

Hello,

i have problem with my i2c SCL that start on high logic i can see it on oscilloscope.

I2C_transfer(); return always FALSE some times i get TRUE and i have true parameters back. 

im always open and close I2C, 

//////////////////////////////////////////////////////////////////////////

it's my init to I2C:

I2C_Params i2cParams;

I2C_init();
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2cParams.transferMode = I2C_MODE_BLOCKING;
i2cHandle = I2C_open(CC1310_LAUNCHXL_I2C0, &i2cParams);

if (i2cHandle == NULL)
{

while(1);
}

return TRUE;

/* open i2c always open.*/

///////////////////////////////////////////////////////////////////////////

it how it run :

bool PeripheralsShtw2MeasureAndReadTemperatureAndHumidity(float* tempAndHmdt)
{
/*tempAndHmdt[0] is the temperature value and tempAndHmdt[1] is the humidity value */
uint8_t numOfRetries = 0;
bool transactionStatus;

/*uint32_t startTime = Clock_getTicks();
TimersSystemCheckTimeout (startTime, 0x493e0);*/


if (i2cHandle == NULL)
{
//PIN_setOutputValue(handleLedPins, CC1310_LAUNCHXL_PIN_GLED, led_ON);
PeripheralsControlVoltage(etPeripheralsVoltageEnable);
PeripheralsI2cBusInit();

}

do
{
transactionStatus = I2C_transfer(i2cHandle, &i2cShtwStruct);

if (transactionStatus)
{
/* Extract temperature value and CRC check */
if (PeripheralsCalcCrc8(shtwRxBuffer,SHTW_TMP_DATA_BYTES_SIZE) == shtwRxBuffer[2]) /* Check if the CRC value given by SHTW2 is equal to the CRC calculated based on received data*/
{
tempAndHmdt[0] = PeripheralsShtw2CalcTemperature(shtwRxBuffer);
}
else
{
transactionStatus = FALSE;
testResult = 0;

}

if (PeripheralsCalcCrc8((shtwRxBuffer + 3),SHTW_HMDT_DATA_BYTES_SIZE) == shtwRxBuffer[5])
{
tempAndHmdt[1] = PeripheralsShtw2CalcHumidty((shtwRxBuffer + 3));
}
else
{
transactionStatus = FALSE;
testResult = 0;
}
}

if(transactionStatus == FALSE)
{
numOfRetries++;
usleep(SHTW2_MEASURMENT_US_DURATION);
}
}
while( (numOfRetries < NUM_OF_I2C_RETRIES) && (transactionStatus == FALSE) );

if(transactionStatus == FALSE)
{

PIN_setOutputValue(handleLedPins, CC1310_LAUNCHXL_PIN_RLED, led_ON);
PIN_setOutputValue(handleLedPins, CC1310_LAUNCHXL_PIN_GLED, led_OFF);
while(1);
}
/*TimersSystemCheckTimeout (startTime, 0x493e0);*/

if (i2cHandle != NULL)
{
I2C_close(i2cHandle);
PeripheralsControlVoltage(etPeripheralsVoltageDisable);
i2cHandle = NULL;

}

return transactionStatus;
}

//////////////////////////////////////////////////////////////////////////////////////////////

maybe someone has an idea or there is a possibility to control the clock .

thanku for replay..

  • Could you clarify the issue a bit?
    "i have problem with my i2c SCL that start on high logic i can see it on oscilloscope.": Why is this a problem? As far as I can see from the plots the SCL line should start high.

    What does i2cShtwStruct contain? This struct should contain the slave address etc, see this example: dev.ti.com/.../README.html
  • thanku for replay,

    i have same parameters as on SDK example, but I2C_transfer(); return FALSE.
    sometimes return TRUE i saw on oscilloscope that clock מםא synchronize with data.
    why it is can happen?

    thanku
  • - You write that you use the same parameters as in the example. Does that mean you use the same sensor as in the example since the address would be different otherwise?
    - Could you show plots of the bus when you get TRUE and when you get FALSE as response?
  • my sensor shtw2, i have same parameters except address  slave.

    ok, i have something interesting here , when i'm not init UART all work when i do init to UART I2C_transfer(); false.

    why is it?

     

  • Ok, so it does work if you don't use the UART. Do you have a DIO conflict?

    Could you provide me with a minimal project that can recreate the issue on a launchpad?
  • there is no conflict with DIO.

    sure, how i can sand you?
  • You can send me a fried request on the forum and send it as attachment there.
  • /*
     * Copyright (c) 2015-2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== empty.c ========
     */
    
    /* For usleep() */
    #include <unistd.h>
    #include <stdint.h>
    #include <stddef.h>
    #include <stdbool.h>
    #include <string.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    #include <ti/devices/cc13x0/driverlib/aon_batmon.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/drivers/Power.h>
    // #include <ti/devices/cc13x0/driverlib/sys_ctrl.h>
    #include <ti/drivers/I2C.h>
    // #include <ti/drivers/SDSPI.h>
    // #include <ti/drivers/SPI.h>
    #include <ti/drivers/UART.h>
    #include "circ_buff.h"
    // #include <ti/drivers/Watchdog.h>
    
    /* Board Header file */
    #include "Board.h"
    
    /* SHTW2 device address  */
    
    typedef enum
    {
        etPeripheralsVoltageDisable = 0x00,
        etPeripheralsVoltageEnable
    }PeriphralsVoltageStatus;
    
    #define MAX_COUNTER_VAL          0xFFFFFFFF
    #define SHTW_ADDRESS               0x70
    
    #define PERIPHERALS_STARTUP_DURATION  400
    
    /* SHTW2 command values*/
    /* Enable clock stretching and read temperature first  */
    #define SHTW_CLK_STRCHEN_TMPFST_MSB     0x7C
    #define SHTW_CLK_STRCHEN_TMPFST_LSB     0xA2
    
    /* SHTW2 Tx */
    #define SHTW_COMMAND_BYTES_SIZE     2     /* Size of command used to send to SHTW2 sensor in bytes units*/
    
    /* SHTW2 Rx */
    #define SHTW_HMDT_DATA_BYTES_SIZE   2
    #define SHTW_TMP_DATA_BYTES_SIZE    2
    #define SHTW_CRC_BYTES_SIZE         2
    #define NUM_OF_I2C_RETRIES          3
    #define SHTW2_MEASURMENT_US_DURATION              15000
    #define I2C_CONTROL                 1
    #define UART_WITH_CALLBACK          1
    #define SHTW2_EXISTS                1
    
    /*  EEPROM   */
    /*Page size is 64 byte- meaning when executing page write bits A15 to A6 of the address are constant for the whole write process. Notice - Roll up is possible */
    #define EEPROM_DEVICE_ADDRESS                                 0x50
    #define EEPROM_MAX_ADDRESS_MSB                                0x3F
    #define EEPROM_MAX_ADDRESS_LSB                                0xFF
    
    #define EEPROM_ADDRESS_BYTES_SIZE                             2
    #define EEPROM_PAGE_BYTES_SIZE                                64
    #define EEPROM_DATA_BYTES_SIZE_WRITE_BYTE_COMMAND             1
    #define EEPROM_DATA_BYTES_SIZE_RANDOM_READ_BYTE_COMMAND       1
    #define EEPROM_DATA_RECORDS_SECTION_ADDRESS                   640
    #define EEPROM_INTERNAL_WRITE_TIME                            35000
    #define SIZE_OF_EEPROM_TEST                                   EEPROM_PAGE_BYTES_SIZE
    #define NUM_OF_EEPROM_RETRIES                                 3
    
    
    uint8_t testResult= 0;
    I2C_Handle  i2cHandle;
    I2C_Transaction i2cShtwStruct;
    PIN_Handle handleLedPins;
    PIN_State LedPinState;
    uint8_t shtwTxBuffer[SHTW_COMMAND_BYTES_SIZE] = {SHTW_CLK_STRCHEN_TMPFST_MSB , SHTW_CLK_STRCHEN_TMPFST_LSB};
    uint8_t shtwRxBuffer[SHTW_TMP_DATA_BYTES_SIZE + SHTW_HMDT_DATA_BYTES_SIZE + SHTW_CRC_BYTES_SIZE];
    
    bool PeripheralsShtw2MeasureAndReadTemperatureAndHumidity(float* tempAndHmdt);
    static float PeripheralsShtw2CalcTemperature (uint8_t *data );
    static float PeripheralsShtw2CalcHumidty (uint8_t *data );
    void PeripheralsShtw2MeasureAndReadTemperatureAndHumidityInit(void);
    static uint8_t PeripheralsCalcCrc8(const uint8_t *data, uint8_t dataSize);
    void PeripheralsControlVoltage (PeriphralsVoltageStatus periphralsVoltageStatus);
    bool TimersSystemCheckTimeout (uint32_t startTick, uint32_t timeOut);
    static bool PeripheralsI2cBusInit (void);
    static bool PeripheralsPinsOpen(void);
    void PeripheralsInit(void);
    bool PeripheralsUartInit (void);
    void PeripheralsEepromWriteInit (void);
    void PeripheralsEepromSequentialReadInit (void);
    static void PeripheralsUartReadCallback(UART_Handle handle, void *rxBuf, size_t size);
    void PeripheralsShutDownI2C();
    void PeripheralsOpenI2C();
    
    PIN_Handle peripheralsVoltageControlHandle;
    PIN_State  peripheralsVoltageControlState;
    
    UART_Handle uart;
    uint8_t uartRxInterruptBuf[64];
    /*     EEPROM       */
    I2C_Transaction i2cEepromWriteStruct;
    I2C_Transaction i2cEepromSequentialReadStruct;
    uint8_t EepromWriteTxBuffer[EEPROM_ADDRESS_BYTES_SIZE + EEPROM_PAGE_BYTES_SIZE];  /* need to change location into eepromwrite function*/
    uint8_t EepromSequentialReadTxBuffer[EEPROM_ADDRESS_BYTES_SIZE];
    tCircularBuffer* CcBleRxCircBuff;
    
    volatile uint32_t lastByteRxFromBleUartTick;
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        
        Board_initGeneral();
         PeripheralsInit();
        float tempAndHumidity[2];
    
     
    while(1)
    {
            
            PeripheralsShtw2MeasureAndReadTemperatureAndHumidity(tempAndHumidity);
    }
    
    
        return 0;
    
    }
    
    void PeripheralsShtw2MeasureAndReadTemperatureAndHumidityInit(void)
    {
        i2cShtwStruct.slaveAddress = SHTW_ADDRESS;
        i2cShtwStruct.writeBuf     = shtwTxBuffer;
        i2cShtwStruct.writeCount   = SHTW_COMMAND_BYTES_SIZE;
        i2cShtwStruct.readBuf      = shtwRxBuffer;
        i2cShtwStruct.readCount    = SHTW_TMP_DATA_BYTES_SIZE + SHTW_HMDT_DATA_BYTES_SIZE + SHTW_CRC_BYTES_SIZE;
    }
    
    static float PeripheralsShtw2CalcTemperature (uint8_t *data )
    {
                float decimalData;
    
                decimalData = ((data[0] & 0xFF) << 8) | (data[1] & 0xFF);    //Binary to decimal transformation
    
                return ( -45 + 175*decimalData/65536 ) ;                     //Extraction by a given formula, see data sheet
    }
    
    static float PeripheralsShtw2CalcHumidty (uint8_t *data )
    {
                float decimalData;
    
                decimalData = ((data[0] & 0xFF) << 8) | (data[1] & 0xFF);    //Binary to decimal transformation
    
                return ( 100*decimalData/65536 ) ;                           //Extraction by a given formula, see data sheet
    }
    
    bool PeripheralsShtw2MeasureAndReadTemperatureAndHumidity(float* tempAndHmdt)
    {
        //tempAndHmdt[0] is the temperature value and tempAndHmdt[1] is the humidity value
        uint8_t numOfRetries = 0;
        bool transactionStatus;
    
        /*uint32_t startTime = Clock_getTicks();
        TimersSystemCheckTimeout (startTime, 0x493e0);*/
    
    
    #if I2C_CONTROL
        PeripheralsOpenI2C();
    #endif
        do
        {
            transactionStatus = I2C_transfer(i2cHandle, &i2cShtwStruct);
    
            if (transactionStatus)
            {
                      //Extract temperature value and CRC check
                if (PeripheralsCalcCrc8(shtwRxBuffer,SHTW_TMP_DATA_BYTES_SIZE) == shtwRxBuffer[2])   //Check if the CRC value given by SHTW2 is equal to the CRC calculated based on received data
                {
                    tempAndHmdt[0] = PeripheralsShtw2CalcTemperature(shtwRxBuffer);
                }
                else
                {
                    transactionStatus = FALSE;
                    testResult = 0;
    
                }
    
                if (PeripheralsCalcCrc8((shtwRxBuffer + 3),SHTW_HMDT_DATA_BYTES_SIZE) == shtwRxBuffer[5])
                {
                    tempAndHmdt[1] = PeripheralsShtw2CalcHumidty((shtwRxBuffer + 3));
                }
                else
                {
                    transactionStatus = FALSE;
                    testResult = 0;
                }
            }
    
            if(transactionStatus == FALSE)
            {
                numOfRetries++;
                usleep(SHTW2_MEASURMENT_US_DURATION);
            }
        }
        while( (numOfRetries < NUM_OF_I2C_RETRIES) && (transactionStatus == FALSE) );
    
    #if I2C_CONTROL
        PeripheralsShutDownI2C();
    #endif
    
    
        if(transactionStatus == FALSE)
        {
    
            //PIN_setOutputValue(handleLedPins, CC1310_LAUNCHXL_PIN_RLED, led_ON);
            //PIN_setOutputValue(handleLedPins, CC1310_LAUNCHXL_PIN_GLED, led_OFF);
            while(1);
        }
        //TimersSystemCheckTimeout (startTime, 0x493e0);
    
    
    
        return transactionStatus;
    }
    
    static uint8_t PeripheralsCalcCrc8(const uint8_t *data, uint8_t dataSize)
    {
    
      uint8_t polynomial = 0x31;                  //X^(8) + X^(5) + X^(4) + 1
      uint8_t bit;                                //Bit counter for the byte internal loop
      uint8_t crc = 0xFF;                         //Initialization
      uint8_t byteCtr;                           // Data byte counter
    
      for (byteCtr = 0; byteCtr < dataSize; byteCtr++)
      {
        crc ^= data[byteCtr];
        for ( bit = 8; bit > 0; --bit)
        {
          if (crc & 0x80)
          {                       //if the first bit is a '1'
            crc = (crc << 1) ^ polynomial;
          }
          else crc = (crc << 1);
        }
      }
      return crc;
    
    }
    
    static bool PeripheralsI2cBusInit (void)
    {
    
            I2C_Params      i2cParams;
    
            I2C_init();
            I2C_Params_init(&i2cParams);
            i2cParams.bitRate = I2C_400kHz;
            i2cParams.transferMode = I2C_MODE_BLOCKING;
            i2cHandle = I2C_open(CC1310_LAUNCHXL_I2C0, &i2cParams);
    
            if (i2cHandle == NULL)
            {
    
                while(1);
            }
    
            return TRUE;
    
    }
    
    void PeripheralsControlVoltage (PeriphralsVoltageStatus periphralsVoltageStatus)
    {
        //TODO: use this function to turn on and off the EEPROM and SHTW2 sensor and test it
        PIN_setOutputValue(peripheralsVoltageControlHandle, TAG3_PERIPHERAL_VOLTAGE_CONTROL, periphralsVoltageStatus);
        if(periphralsVoltageStatus == etPeripheralsVoltageEnable)
        {
            usleep(PERIPHERALS_STARTUP_DURATION);
        }
    }
    
    bool TimersSystemCheckTimeout (uint32_t startTick, uint32_t timeOut)
    {
    
        uint32_t endTick = Clock_getTicks();
        uint32_t diffTick;
    
         //check for counter overflow
    
        if(endTick >= startTick)
        {
    
            diffTick = endTick - startTick ;
        }
    
        else
        {
    
            diffTick = MAX_COUNTER_VAL - (startTick - endTick);    //32 bit counter register with count up mode
        }
    
        if( diffTick >  timeOut ){           //each tick is 10 us
            return TRUE;
    
        }
    
        return FALSE;
    
    }
    
    static bool PeripheralsPinsOpen()
    {
       
    
        PIN_Config peripheralsVoltageControlTable[] =
        {
         TAG3_PERIPHERAL_VOLTAGE_CONTROL     | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW  | PIN_PUSHPULL | PIN_DRVSTR_MAX,
         PIN_TERMINATE
        };
    
    
    
        peripheralsVoltageControlHandle =  PIN_open(&peripheralsVoltageControlState, peripheralsVoltageControlTable);
        if (peripheralsVoltageControlHandle == NULL)
        {
            return FALSE;
        }
    
    
    
        return TRUE;
    }
    
    void PeripheralsInit(void)
    {
    
    
    #if SHTW2_EXISTS
        PeripheralsShtw2MeasureAndReadTemperatureAndHumidityInit();
    #endif
    
        PeripheralsEepromSequentialReadInit();
        PeripheralsEepromWriteInit();
    
        bool resultPinsOpen;
        bool resultUartInit;
        bool resultI2cBusInit;
    
        resultPinsOpen = PeripheralsPinsOpen();
        resultUartInit =  PeripheralsUartInit();
        resultI2cBusInit = PeripheralsI2cBusInit();
    
    
        if ( !resultPinsOpen )
        {
            while(1);
        }
    
    
         if ( !resultUartInit )
         {
             while(1);
         }
    
    
    
    #if I2C_CONTROL
         if ( !resultI2cBusInit )
         {
             while(1);
         }
         else
         {
             PeripheralsShutDownI2C();
         }
    #else
         if ( !resultI2cBusInit )
         {
              while(1);
         }
    #endif
    
    
    
    
    
    
    
    
    
    #if STS31_EXISTS
        PeripheralsSts31MeasureAndReadTemperatureInit();
    #endif
    
    
    #if BLUENRG_EXISTS
        PeripheralsResetBle();
    #endif
    }
    
    
    bool PeripheralsUartInit (void)
    {
    
      UART_Params uartParams;
      UART_init();
      UART_Params_init(&uartParams);
    
    #if UART_WITH_CALLBACK
      uartParams.baudRate      = 9600;
      uartParams.writeDataMode = UART_DATA_BINARY;
      uartParams.readMode      = UART_MODE_CALLBACK;
      uartParams.readDataMode  = UART_DATA_BINARY;
      uartParams.readCallback  = (UART_Callback)PeripheralsUartReadCallback;
    
      uart = UART_open(CC1310_LAUNCHXL_UART0, &uartParams);
      if (uart == NULL)
      {
            return FALSE;
      }
      UART_read(uart, uartRxInterruptBuf, 1); /*required*/
    #else
      uartParams.readTimeout = UART_TIMEOUT;
      uartParams.writeDataMode = UART_DATA_BINARY;
      uartParams.readDataMode = UART_DATA_BINARY;
      uartParams.readReturnMode = UART_RETURN_FULL;
      uartParams.readMode = UART_MODE_BLOCKING;
      uartParams.writeMode = UART_MODE_BLOCKING;
      uartParams.readEcho = UART_ECHO_OFF;
      uartParams.baudRate = 9600;
      uartParams.readCallback =  NULL;
      uartParams.writeTimeout = UART_TIMEOUT*100;
    
      uart = UART_open(TAG3_UART, &uartParams);
      if (uart == NULL)
      {
            return FALSE;
      }
    #endif
    
      return TRUE;
    }
    
    void PeripheralsEepromWriteInit (void)
    {
        i2cEepromWriteStruct.slaveAddress = EEPROM_DEVICE_ADDRESS;
        i2cEepromWriteStruct.readCount    = 0;
        i2cEepromWriteStruct.writeBuf     = EepromWriteTxBuffer;
    }
    
    
    void PeripheralsEepromSequentialReadInit (void)
    {
        i2cEepromSequentialReadStruct.slaveAddress = EEPROM_DEVICE_ADDRESS;
        i2cEepromSequentialReadStruct.writeBuf     = EepromSequentialReadTxBuffer;
        i2cEepromSequentialReadStruct.writeCount   = EEPROM_ADDRESS_BYTES_SIZE;
    }
    
    static void PeripheralsUartReadCallback(UART_Handle handle, void *rxBuf, size_t size)
    {
        // Make sure we received bytes
        if (size >= 1)
        {
            // Copy bytes from RX buffer to Circular buffer
           FillBuffer(CcBleRxCircBuff, rxBuf, size);
    
           lastByteRxFromBleUartTick = Clock_getTicks();
    
    
        }
        // Start another read, with size the same as it was during first call to  UART_read()
        UART_read(uart, rxBuf, 1);
    }
    
    void PeripheralsShutDownI2C()
    {
        if (i2cHandle != NULL)
        {
            I2C_close(i2cHandle);
            PeripheralsControlVoltage(etPeripheralsVoltageDisable);
            i2cHandle = NULL;
            //Semaphore_post(i2cSemHandle);
        }
    }
    
    void PeripheralsOpenI2C()
    {
        //
    
        if (i2cHandle == NULL)
        {
            //Semaphore_pend(i2cSemHandle, BIOS_WAIT_FOREVER );
            PeripheralsControlVoltage(etPeripheralsVoltageEnable);
            PeripheralsI2cBusInit();
        }
    }
    
    
    

  • looks like i found some ticket on this one e2e.ti.com/.../703559