Hello,
I am trying to communicate with a very easy light sensor via i2c. the light sensor is ts34725. To do this I use a microcontroller which is new for me: tm4c1294xl
So I am trying to get the id of the module to be sure evrything starts well. But already get a NAK there
Can somebody telle me what I am doing wrong in my short piece of software? As you see The 0x44 (which I need) gets transmitted. But My mc sends a nak for some reason. Also when I try to print the data I receive it prints wrong data (mostly 0).
Does anybody know why?
void setupI2c()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7);
GPIOPinConfigure(0x00001002);
GPIOPinConfigure(0x00001402);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_5);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_4);
}
void getModel() {
int i=0; int k; int data[1]={0};
int g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320), 40000000);
I2CMasterInitExpClk( I2C7Master_Base, g_ui32SysClock, false); I2CMasterSlaveAddrSet(I2C7Master_Base, 0x29, false); //true = read I2CMasterControl(I2C7Master_Base, I2C_MASTER_CMD_SINGLE_SEND); I2CMasterDataPut(I2C7Master_Base, 0x80|0x12); // result register while(I2CMasterBusy(I2C7Master_Base)); /******************************/ /*for(i=0;i<10000;i++) {k++;}
/*****************************/
I2CMasterSlaveAddrSet(I2C7Master_Base, 0x29, true); //true = read
for(i=0;i<10000;i++)
{k--;}
I2CMasterControl(I2C7Master_Base, I2C_MASTER_CMD_SINGLE_RECEIVE);
data[0]=I2CMasterDataGet(I2C7Master_Base);
while(I2CMasterBusy(I2C7Master_Base));
UARTprintf(" model: %x\n", data[0]);
}