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.
Hello folks,
I'm attempting to write a library to get basic i2c functionality working on the TM4C1294NCPDT, and am at the moment testing send functions. Hardware wise, I've set up the tiva to talk to a logic analyzer so that I could see the transmissions for debugging purposes.
I am running into a strange issue where for some reason, in my send function, it will only send the first part of the burst. After that, it hangs up in the 'while(!I2CMasterBusy(I2C0_BASE))' call in the for loop. I don't have much more information to elaborate on than that, I can't figure out why it's happening. The only thing I can think of is that maybe the logic analyser isn't talking back and it's freezing due to detecting an error.
Does everything look alright below, to start?
uint8_t data[4] = {10, 20, 30, 40};
static long F_CPU = 120000000;
void send(uint8_t SlaveAddr, uint8_t msg[], uint32_t msgSize);
void init();
int main()
{
SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL|SYSCTL_CFG_VCO_480), 120000000);
//i2cComm.init(PB_2, PB_3);
//i2cComm.send(10, data, 4 );
init();
send(10, data, 4 );
while(1);
}
void send(uint8_t SlaveAddr, uint8_t msg[], uint32_t msgSize)
{
//slave address is bits 6:0 of byte
SlaveAddr = SlaveAddr & 0b01111111;
// Tell the master module what address it will place on the bus when
// communicating with the slave.
I2CMasterSlaveAddrSet(I2C0_BASE, SlaveAddr, false);
//put first byte of data to be sent into FIFO
I2CMasterDataPut(I2C0_BASE, msg[0]);
//Initiate burst message send from the MCU
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
//wait for MCU to start transaction
while(!I2CMasterBusy(I2C0_BASE));
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));
//send more of the data, up till the last byte, using the
//BURST_SEND_CONT command of the I2C module
for(uint32_t i = 1; i < (msgSize) - 1; i++)
{
//put next piece of data into I2C FIFO
I2CMasterDataPut(I2C0_BASE, msg[i]);
//send next data that was just placed into FIFO
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
//wait for MCU to start transaction
while(!I2CMasterBusy(I2C0_BASE));
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));
}
//put last piece of data into I2C FIFO
I2CMasterDataPut(I2C0_BASE, msg[msgSize-1]);
//send next data that was just placed into FIFO
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
//wait for MCU to start transaction
while(!I2CMasterBusy(I2C0_BASE));
// Wait until MCU is done transferring.
while(I2CMasterBusy(I2C0_BASE));
}
void init()
{
//enable the i2c module
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//reset the i2c module
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
//enable gpio module
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //simulates enabling both SDA and SCL pins when passing pins into init func
//configure the gpio pins for using the i2c module as a source
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
//configure the gpio pins for i2c operation
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.
// F_CPU is the constant used by energia to represent the global clock rate
I2CMasterInitExpClk(I2C0_BASE, F_CPU, false);
//clear I2C FIFOs
HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000;
}
Hardware setup:
Indeed it is correctly installed; it sends off the first transmission just fine, I discovered by viewing the analysed data, and doesn't seem to have an issue when transmitting just single bytes.