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.

TM4C123GH6PM: Unable to track the origin of automatically generated sensor readings !

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: LM35,

hello.

I am trying to interface LM35 temperature sensor with Launchpad.

I have been following the Tiva Launchpad workshop documentation availeble on the internet.

As I could only get the code for the internal temperature sensor, I modified it as suggested by Ralph Jacobi. This is my code:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
int main(void)
{
uint32_t ui32ADC0Value[4];
volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
while(1)
{
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
}
}

Also, I connected the output pin of the sensor to PE_3 pin.

But on observing the breakpoint, I get the readings even if this pin (PE_3) is disconnected!

I am unable to figure out the origin of this miscellaneous reading. (shown in the below screenshot)

Thank you in advance!

  • I don't see anywhere in your code where you configured PE3 to be an analog input pin. You should have these statements:

      SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);   //Enables the clock to PORT E
      GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);

    Without these statements you are converting the voltage on an internal floating node.

  • Hello Mr. Bob,
    Thank you for the swift reply.
    Do you refer to PE_3 ?
    I added the lines of code you suggested. But, still getting the same readings.
    How should I differentiate whether the readings are from the internal temperature sensor or the external one ?
    (Also, I seem to have jumped right into getting things done by getting the code from workshop examples,etc... How should I begin programming the tm4c123gh6pm the right way? )
  • Yes, sorry. I meant PE3. I have corrected my earlier post. Did you use GPIO_PIN_3?