I'm using the TM4C launchpad and interfacing it with the sht21 temperature and relative humidity sensor using the I2C module. I struggle with trying to understand why this code returns true for the first while loop which checks if the master is busy. Also, if it does run, the only "data" it displays is 255. I am unable to understand what the goof up in my code is.
#include "inc/tm4c123gh6pm.h"
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "utils/uartstdio.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "i2cheader.h"
#include "uart.h"
void InitI2C0(void);
void BlinkLed(void);
int main(void)
{
uint8_t data1, data2 = 0;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|
SYSCTL_OSC_MAIN);
InitConsole();
DisplaySetup();
InitI2C0();
I2CMasterSlaveAddrSet(I2C0_BASE, 0X40, false);
I2CMasterDataPut(I2C0_BASE, 0XE3);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE));//ALWAYS RETURNS TRUE
SysCtlDelay(1000);
I2CMasterSlaveAddrSet(I2C0_BASE, 0x40, true);
//READ FIRST BYTE
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C0_BASE));
data1= I2CMasterDataGet(I2C0_BASE);
//READ SECOND BYTE
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while (I2CMasterBusy(I2C0_BASE));
data2 = I2CMasterDataGet(I2C0_BASE);
//display data onto the console
}
I'm quite the novice at microcontroller coding, so any help would be appreciated. Thank you!