Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: LM75A
Tool/software: Code Composer Studio
I can observe i2c clock signal on oscillascope it works fine. It means that i send data master to slave.
I use lm75a as a slave device which is temperature sensor. I have issue about reading data from slave. I read value but it does not change. It means it is not temperature or what value am i reading?
My code is shown below:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "inc/tm4c129xnczad.h"
#define SLAVE_ADDRESS 0x00
void delay (void)
{
volatile uint32_t ui32Loop;
for(ui32Loop = 0; ui32Loop < 200; ui32Loop++);
}
volatile uint32_t result[7];
uint32_t g_ui32SysClock;
uint32_t TempValueC;
int main(void)
{
printf("\n hello0\n");
// g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320), 40000000);
//
// Enable the GPIO port that is used for the on-board LED.
//
SYSCTL_RCGCGPIO_R = SYSCTL_RCGCGPIO_R3 | SYSCTL_RCGCGPIO_R9 | SYSCTL_RCGCGPIO_R1;
//
// Do a dummy read to insert a few cycles after enabling the peripheral.
//
printf("\n hello1 \n");
// result = SYSCTL_RCGCGPIO_R;
//
// Enable the GPIO pin for the LED (PD3). Set the direction as output, and
// enable the GPIO pin for digital function.
//
// GPIO_PORTD_AHB_DIR_R = 0x8;
//GPIO_PORTD_AHB_DEN_R = 0x8;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
SYSCTL_RCGCI2C_R = (1 << 7) | (1 << 6); // Mode Clock Gating Control for I2C modules 4 and 6
GPIOPinConfigure(GPIO_PK6_I2C4SCL);
GPIOPinConfigure(GPIO_PK7_I2C4SDA);
//GPIOPinConfigure(GPIO_PA6_I2C6SCL);
// GPIOPinConfigure(GPIO_PA7_I2C6SDA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C4);
printf("\n hello2 \n");
GPIOPinTypeI2C(GPIO_PORTK_BASE, (1 << 7));
printf("\n helloa \n");// Configures SDA
GPIOPinTypeI2CSCL(GPIO_PORTK_BASE, (1 << 6));
printf("\n hellob \n");// Configures SCL
//GPIOPinTypeI2C(GPIO_PORTA_BASE, (1 << 7));
printf("\n helloc \n");// Configures SDA
//GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, (1 << 6)); // Configures SCL
printf("\n hello4 \n");
I2CMasterInitExpClk(I2C4_BASE, g_ui32SysClock, false);
printf("\n hello5 \n");
I2CSlaveEnable(I2C4_BASE);
I2CSlaveInit(I2C4_BASE, SLAVE_ADDRESS);
I2CMasterSlaveAddrSet(I2C4_BASE, SLAVE_ADDRESS, false);
printf("\n hello6 \n");
//
// Loop forever.
//
while(1)
{
printf("\n 1\n");
I2CMasterDataPut(I2C4_BASE, SLAVE_ADDRESS);
printf("\n 2\n");
I2CMasterControl(I2C4_BASE, I2C_MASTER_CMD_SINGLE_SEND);
printf("\n 3\n");
//
// Wait until the slave has received and acknowledged the data.
//
//while(!(I2CSlaveStatus(I2C4_BASE) & I2C_SLAVE_ACT_RREQ));
//
// Read the data from the slave.
printf("\n 4\n");
result[7] = I2CSlaveDataGet(I2C4_BASE);
//result = I2CSlaveDataGet(I2C4_BASE);
printf("\n 5\n");
printf("\n%d\n",result);
TempValueC = (147.5 - ((75.0 * 3.3 * result[0])) / 4096.0);
printf("%d",TempValueC);
while(I2CMasterBusy(I2C4_BASE));
//
// Delay for a bit.
//
delay ();
// Delay for a bit.
//
delay ();
}
}