I am developing with the TM4C129ENCPDT and using I2C0 to interface with a bq27421. I have it set up to run at 100kHz off of the system clock. When I try to transmit 3 bytes (0x00, 0x01 and 0x00), on my scope I get the address (0x55) with the write bit, which is ACK'd by the slave, and sometimes a 0x00 and other times a 0x01 followed by what appears to be a clock stretch and another ACK by the slave and then a STOP. I never have seen 3 data bytes on the scope and the first data byte is usually not correct.
I have the following code for initialization.
I2C0_Init(void { SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); //Enable I2C0 peripheral. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Enable GPIO port B so we can use PortB[3:2] for I2C0. GPIOPinConfigure(GPIO_PB2_I2C0SCL); //Configure the pin muxing for I2C0 functions on port B2 and B3. GPIOPinConfigure(GPIO_PB3_I2C0SDA); GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); //Configure B2 for SCL. GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); //Configure B3 for SDA. I2CMasterInitExpClk(I2C0_BASE, halSys_getClock(), false); }
And to transmit, the following code.
void I2C0_Write(void { I2CMasterSlaveAddrSet(I2C0_BASE, 0x55, I2C_WRITE); I2CMasterDataPut(I2C0_BASE, 0x00); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START); while (I2CMasterBusy(I2C0_BASE) == true); I2CMasterDataPut(I2C0_BASE, 0x01); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT); while (I2CMasterBusy(I2C0_BASE) == true); I2CMasterDataPut(I2C0_BASE, 0x00); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while (I2CMasterBusy(I2C0_BASE) == true); }
The scope shot below has SDA on the top and SCL on the bottom. As you can see, the address is transmitted correctly, but the first data byte that is transmitted is 0x01 (it should be 0x00). The second byte transmitted is 0x00, but it should be 0x01.
Thanks,
Jim