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.

TM4C123GH6PM: No output when using I2C sensorlib drivers

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: INA226

Hello There,

I hope someone can bring a bit of help here.

After successfully writing to and reading from I2C devices using driverlib commands, I decided to try the sensor lib drivers (they look nicer) and copy the example in the SPMU371D, pages 79 and 80. Additionally I've added the interrupt handler in "startup_css.c", and initialize the I2C port 1.

The thing is that the I2C signals have no activity at all when running this code. When debugging the code the micro stays in line "while(!g_bI2CMSimpleDone)". In the example below please do not care about the slave address, at least I'd like to see some activity in the I2C port! What's needed here?

Any help is appreicated,
Justo

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "driverlib/uart.h"
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_i2c.h"
#include "utils/uartstdio.h"
#include "sensorlib/i2cm_drv.h"


#define I2C_SLAVE 0x77

//
// The I2C master driver instance data.
tI2CMInstance g_sI2CMSimpleInst;


// A boolean that is set when an I2C transaction is completed.
volatile bool g_bI2CMSimpleDone = true;


//
// The interrupt handler for the I2C module.
//
void I2CMSimpleIntHandler(void)
{
    I2CMIntHandler(&g_sI2CMSimpleInst);
}

//
// Callback when I2C transactions have completed.
//
void I2CMSimpleCallback(void *pvData, uint_fast8_t ui8Status)
{
    // See if an error occurred.
    if(ui8Status != I2CM_STATUS_SUCCESS)
    {
        // An error occurred, so handle it here if required.
        UARTprintf("Error\n");
    }

        // Indicate that the I2C transaction has completed.
        g_bI2CMSimpleDone = true;
        UARTprintf("No Error\n");
}


// I2C master driver example.
void
I2CMSimpleExample(void)
{
    uint8_t pui8Data[4];
    //
    // Initialize the I2C master driver. It is assumed that the I2C module has
    // already been enabled and the I2C pins have been configured.
    //
    I2CMInit(&g_sI2CMSimpleInst, I2C1_BASE, INT_I2C1, 0xff, 0xff, 80000000);

    //
    // Write two bytes of data to the I2C device at address 0x22.
    //
    g_bI2CMSimpleDone = false;
    I2CMWrite(&g_sI2CMSimpleInst, 0x22, pui8Data, 2, I2CMSimpleCallback, 0);
    while(!g_bI2CMSimpleDone)
    {
    }

    //
    // Read four bytes of data from the I2C device at address 0x31.
    //
    g_bI2CMSimpleDone = false;
    I2CMRead(&g_sI2CMSimpleInst, 0x31, pui8Data, 1, pui8Data, 4,
    I2CMSimpleCallback, 0);
    while(!g_bI2CMSimpleDone)
    {
    }

}


//
// Serial Port configuration
//
void ConfigureUART(void)
{
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);
}


//
// MAIN
//
int main(void)
{

ConfigureUART(); // Initialize serial port

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);

// Configure I2C
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6); // I2CSCL
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinConfigure(GPIO_PA7_I2C1SDA);

// Enable and initialize the I2C1 master module. false: 100kbps; true: 400kbps.
I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);

// Send something!
I2CMSimpleExample();

while(1)
        {
            SysCtlDelay(20000000);
        }

}

  • Hello Justolap,

    I am not sure if sensorlib is actually a better base for you to work from. It would really depend on your application. Sensorlib is great if you are using any of the sensors that are either directly supported or using a very similar version to one that is supported which would require minimal changes, as then a lot of the handling for the sensor itself is done for you.

    If you are working with some other I2C device and need to build your code from the ground up, you'd be better off continuing from your success with driverlib and building from there further. Of course if you want to use sensorlib as a background for how to architect your application, it could be a good reference, but I am not so sure about porting a sensorlib project and then trying to modify it for your means.

    So with all that said, what device are you trying to interface to the TM4C?
  • Hello Ralph,

    Thanks for your prompt reply.

    I see your point. In this case the I2C is used for some components like current sensors (INA226), DACs from ADI, Temperature sensors (from TI too) a display... I think that's all. I'll stay with my working code then!

    In the other hand, the reason why I discovered the driverlib libs was when I was trying to use it for the new sensor boost board called BOOSTXL-SENSORS. The driverlib examples in "TivaWare_C_Series-2.1.4.178" are for the older board .... not for the one I have ...

    Thanks again for your answer, it helps me in organizing all the options.

    Regards,
    Justo