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.

CCS/TM4C1294NCPDT: I2C can't read true temperature value

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   ();
    }
}



  • I think you want to first read the LM75A datasheet to know how to read/write to the LM75A registers. When you look at the scope do you have the correct Address byte and is it correctly acknowledged by the slave? When you say you are not reading the temperature, what does it show on the scope? Capture the scope and show what it is.

    I see you calling I2CMasterDataPut(I2C4_BASE, SLAVE_ADDRESS). What is this for? If you are reading the temperature then there is no need to generate the pointer byte as the pointer byte is 0 by default after power up which points to the temperature register. You shouldn't need the I2CMasterDataPut() as far as I know. In any case check the LM75A datasheet and verify your scope capture against the datasheet.