I am working on a Tiva Launchpad and interfacing to a TI ADS1100. I am trying to read/write to the configuration register in this code snipet. I can communicate with the devices, however it only works when I step through in the debugger. stepping through gets me the good data back and I can successfully write the config register on the ADC as well. But if I just let it run, I get garbage back. Any ideas??
// Setup System Clock for 120MHz
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
// Configure UART0 for the debug console.
ConfigureUART();
// Configure UART5 for communication with the display server.
ConfigureUART5();
// Initialize I2C0, I2C1, I2C2, and I2C3.
InitI2C0(g_ui32SysClock);
InitI2C1(g_ui32SysClock);
InitI2C2(g_ui32SysClock);
InitI2C3(g_ui32SysClock);
uint8_t D1, D2, D3 = 0x11;
while (1) {
I2CMasterSlaveAddrSet (I2C0_BASE, 0x48, true); //set slave address to 0x10 and read
I2CMasterControl (I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); //Read the 1st Byte
while (I2CMasterBusy(I2C0_BASE)); //Wait till end of transaction
D1 = (uint8_t)(I2CMasterDataGet (I2C0_BASE)); //Read from FIFO
I2CMasterControl (I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT); //Read the 1st Byte
while (I2CMasterBusy(I2C0_BASE)); //Wait till end of transaction
D2 = (uint8_t)(I2CMasterDataGet (I2C0_BASE)); //Read from FIFO
I2CMasterControl (I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); //Read the 2nd Byte
while (I2CMasterBusy(I2C0_BASE)); //Wait till end of transaction
D3 = (uint8_t)(I2CMasterDataGet (I2C0_BASE)); //Read from FIFO
printf("ADS1100 Addr: 0x%02x 0x%02x 0x%02x 0x%02x\n\n", 0x48, D1, D2, D3);
SysCtlDelay(120000000);
void InitI2C0(uint32_t argClock)
{
//enable I2C module 0
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//reset module
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
//enable GPIO peripheral that contains I2C 0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
// Configure the pin muxing for I2C0 functions on port B2 and B3.
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
// Select the I2C function for these pins.
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
// Enable and initialize the I2C0 master module. Use the system clock for
// the I2C0 module. The last parameter sets the I2C data transfer rate.
// If false the data rate is set to 100kbps and if true the data rate will
// be set to 400kbps.
//
// Stop the Clock, Reset and Enable I2C Module
// in Master Function
//
SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//
// Wait for the Peripheral to be ready for programming
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0));
//
// Initialize and Configure the Master Module
//
I2CMasterInitExpClk(I2C0_BASE, argClock, true);
I2CMasterGlitchFilterConfigSet(I2C0_BASE, I2C_MASTER_GLITCH_FILTER_8);
//clear I2C FIFOs
HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000;
}
}