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/TM4C1294NCPDT: TM4C1294XL

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: TMP006

Tool/software: Code Composer Studio

I AM USING TM4C12GH6 SENSOR HUB BOOSTER PACK

#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include "Board.h"
#include <ti/sysbios/knl/Clock.h>

Void clk0Fxn(UArg arg0);
Void clk1Fxn(UArg arg0);
Clock_Struct clk0Struct, clk1Struct;
Clock_Handle clk2Handle;

Void clk0Fxn(UArg arg0)
{
    uint16_t temperature;
    uint8_t txBuffer[6];
    uint8_t rxBuffer[6];
    I2C_Handle i2c;
    I2C_Params i2cParams;
    I2C_Transaction i2cTransaction;

    // Create I2C interface for sensor usage
    //
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_400kHz; // It can be I2C_400kHz orI2C_100kHz

    // Let's open the I2C interface
    //
    i2c = I2C_open(Board_I2C_TMP, &i2cParams); // Board_I2C_TMP is actually I2C7
    if (i2c == NULL) {
        // error initializing IIC
        //
        System_abort("Error Initializing I2C\n");
    }

    System_printf("I2C Initialized!\n");

    // Point to the T ambient register and read its 2 bytes (actually 14 bits)
    // register number is 0x01.
    //
    txBuffer[0] = 0x01; // Ambient temperature register
    i2cTransaction.slaveAddress = Board_TMP006_ADDR; // For SENSHUB it is 0x41
    i2cTransaction.writeBuf = txBuffer; // transmit buffer
    i2cTransaction.writeCount = 1; // only one byte will be sent
    i2cTransaction.readBuf = rxBuffer; // receive buffer
    i2cTransaction.readCount = 2; // we are expecting 2 bytes

    // carry out the I2C transfer. The received 16 bits is in big endian format since IIC
    // protocol sends the most significant byte first (i.e. rxBuffer[0]) and then
    // least significant byte (i.e. rxBuffer[1]).
    //
    // Remember that temperature register is 14 bits and we need to shift right 2 bits
    // to get a number. We need to divide it by 32 to get the temperature value.
    //
    if (I2C_transfer(i2c, &i2cTransaction)) {

        // 14 bit to 16 bit conversion since least 2 bits are 0s
        //
        temperature = (rxBuffer[0] << 6) | (rxBuffer[1] >> 2);

        // This time we are going to check whether the number is negative or not.
        // If it is negative, we will sign extend to 16 bits.
        //
        if (rxBuffer[0] & 0x80) {
            temperature |= 0xF000;
        }

        // We need to divide by 32 to get the actual temperature value.
        // Check with the TMP006 datasheet
        //
        temperature /= 32;
        System_printf("Sample %d (C)\n", temperature);
    }
    else {

        // no response from TMP006. Is it there?
        //
        System_printf("I2C Bus fault\n");
    }

    // flush everything to the console
    //
    System_flush();

    // close the interface
    //
    I2C_close(i2c);
}




Void clk1Fxn(UArg arg0)
{
    UInt32 time;

    time = Clock_getTicks();
    System_printf("System time in clk1Fxn = %lu\n", (ULong)time);
    System_printf("Calling BIOS_exit() from clk1Fxn\n");
    BIOS_exit(0);
}
/*
 * ======== main ========
 */
int main(void)
{
    Clock_Params clkParams;
    // Call board init functions
    Board_initGeneral();
    Board_initGPIO();
    Board_initI2C();

    // Construct tmp006 Task thread
    Clock_Params_init(&clkParams);
    clkParams.period = 1;
    clkParams.startFlag = TRUE;

    /* Construct a periodic Clock Instance with period = 5 system time units */
    Clock_construct(&clk0Struct, (Clock_FuncPtr)clk0Fxn,
                    1, &clkParams);

    clkParams.period = 0;
    clkParams.startFlag = FALSE;

    /*
     * Construct a one-shot Clock Instance with timeout = 11
     * system time units
     */
    Clock_construct(&clk1Struct, (Clock_FuncPtr)clk1Fxn,
                    10, &clkParams);

    clk2Handle = Clock_handle(&clk1Struct);

    Clock_start(clk2Handle);

    GPIO_write(Board_LED0, Board_LED_ON);

    // Let TI-RTOS scheduler work
    //
    BIOS_start();

    return (0);
}

HERE İS MY CODE AND ACTUALLY I M TRYING TO DO MEASURING TEMP EVERY 1 SEC AND WRITE IT CONSLE BUT ALWAYS GETTIN BUS FAULTY BUT DEFINES FOR I2C IS WORKING ACTUALLY AN OTHER CODE (WHICH IS SAME AS THE DEFINES UP) SO I TOUGHT MAYBE ITS ABOUT CLOCK SYSTEM AND I DONT KNOW SOMETHINK ABOUT IT

  • Hello Batuhan,

    Can you provide more details here about the failure?

    What specific fault is occurring?

    Can you post the Debug Log for the fault occurring?

    Also can you attach the .cfg file?

    You mentioned the I2C is working for another code, can you explain the differences between this code and that other working code?

    By the way, I edited your original post to use our Code Syntax Highlighter which you can do in the future when posting code by clicking the </> button in the toolbar for post creation.

  • 1-I add uart phonema  so fınal satatus like that.

    2-

    Can you provide more details here about the failure?

    What specific fault is occurring?

    as ı understand my code ıs always goıng ınsıde of else(blue area) mean that my ı couldnt go inside of   if (I2C_transfer(i2c, &i2cTransaction))

    so the reason of that mıght because of 

    txBuffer[0] = 0x01; // Ambient temperature register
    i2cTransaction.slaveAddress = Board_TMP006_ADDR; // For SENSHUB it is 0x41
    i2cTransaction.writeBuf = txBuffer; // transmit buffer
    i2cTransaction.writeCount = 1; // only one byte will be sent
    i2cTransaction.readBuf = rxBuffer; // receive buffer
    i2cTransaction.readCount = 2; those 

    but when ı ınsert the same code wıth out usıng tıme module ınsıde of a task ı can get temperature sample from that task  

    3*You mentioned the I2C is working for another code, can you explain the differences between this code and that other working code?

    so actualyy there ıs no dıffrence between  codes one of them ıs ınsıde of task and when ı call task. it execute properly (it works )

    my code just  executing inside of timer module

    Clock_Params_init(&clkParams);
    clkParams.period = 1;
    clkParams.startFlag = TRUE;

    /* Construct a periodic Clock Instance with period = 5 system time units */
    Clock_construct(&clk0Struct, (Clock_FuncPtr)clk0Fxn,
    1, &clkParams);

    and ı m callıng that module every 1 sec but ı trapped inside bus fault

     

    BY THE WAY THANKS FOR HELP SORRY FOR BAD ENGLİSH :)

  • Hi Batuhan,

    The I2C_transfer is running in the context of a Swi (since it is a Clock function). Since the I2C_transfer is a blocking call (can call Semaphore_pend), non-deterministic things can happen when called from a Swi (or Hwi). That's why it is working in a task.   

    Todd