I'm having problem with I2C being stuck at the Master Busy loop. What's even weirder is that when I step through the code in the debugger, everything works perfectly. Note that this only works if I step through the function without stepping inside the function where it's executing the I2C commands. If I try to step into the function, it will get stuck at the Master Busy loop.
Here is my initialization code:
//
// Enable the peripherals to be used.
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//
// Waits for peripherals to be ready.
//
while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0) &&
!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB) &&
!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOK));
//
// Select I2C function for PB2 and PB3
//
MAP_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
MAP_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
//
// Configure PB2 and PB3 for I2C
//
MAP_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
MAP_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
//
// Configure and enable master.
//
MAP_I2CMasterInitExpClk(I2C0_BASE, g_ui32SysClock, false);
//
// Configure pin PK0 as output.
//
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0);
Here's the function that it's getting stuck in:
// // Set slave address. // MAP_I2CMasterSlaveAddrSet(I2C0_BASE, 0x30, false); // // Place data to be send into FIFO. // MAP_I2CMasterDataPut(I2C0_BASE, command); // // Set burst length. // MAP_I2CMasterBurstLengthSet(I2C0_BASE, 2); // // Initiate master burst send. // MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START); // // Wait for master to finish transaction. // while (!MAP_I2CMasterBusy(I2C0_BASE)); while (MAP_I2CMasterBusy(I2C0_BASE)); // // Place data to be send into FIFO. // MAP_I2CMasterDataPut(I2C0_BASE, value); // // End master burst send. // MAP_I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); // // Wait for master to finish transaction. // while (!MAP_I2CMasterBusy(I2C0_BASE)); // This one here while (MAP_I2CMasterBusy(I2C0_BASE));
The program get stuck specifically at the second "while (!MAP_I2CMasterBusy(I2C0_BASE));", which means it was able to get past the first one.
I do have two 4.7k pull-up resistors for the SCL and SDA line.
Again, it only get stuck when I run the program, or when I try to step through the line "while (!MAP_I2CMasterBusy(I2C0_BASE));". If I step through the entire function completely without going inside, then it works as intended.