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); } }