#include "msp.h"
#include <stdint.h>
#define CALADC_15V_30C *((unsigned int *)0x1A1A) // Temperature Sensor Calibration-30 C
// See device datasheet for TLV table memory mapping
#define CALADC_15V_85C *((unsigned int *)0x1A1C) // Temperature Sensor Calibration-85 C
volatile long temp;
volatile long IntDegF;
volatile long IntDegC;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Initialize the shared reference module
// By default, REFMSTR=1 => REFCTL is used to configure the internal reference
//while(REFCTL0 & REFGENBUSY); // If ref generator busy, WAIT
//REFCTL0 |= REFVSEL_0 + REFON; // Enable internal 1.2V reference
// Configure ADC - Pulse sample mode; ADC14_CTL0_SC trigger
ADC14->CTL0 |= ADC14_CTL0_SHT0_5 | ADC14_CTL0_ON | ADC14_CTL0_SHP; // ADC ON,temperature sample period>30us
ADC14->CTL1 |= ADC14_CTL1_TCMAP; // Enable internal temperature sensor
ADC14->MCTL[0] = ADC14_MCTLN_VRSEL_1 + ADC14_MCTLN_INCH_22; // ADC input ch A22 => temp sense
ADC14->IER0 = 0x0001; // ADC_IFG upon conv result-ADCMEM0
while(!(REFCTL0 & REFGENRDY)); // Wait for reference generator
// to settle
ADC14->CTL0 |= ADC14_CTL0_ENC;
NVIC->ISER[0] = 1 << ((ADC14_IRQn) & 31);// Enable ADC interrupt in NVIC module
__enable_interrupt();
//SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; // Wake up on exit from ISR
while(1)
{
ADC14->CTL0 |= ADC14_CTL0_SC; // Sampling and conversion start
//__sleep();
//__no_operation(); // Only for debugger
// Temperature in Celsius
// The temperature (Temp, C)=
IntDegC = (temp-CALADC_15V_30C)*(85-30)/(CALADC_15V_85C-CALADC_15V_30C)+30;
// Temperature in Fahrenheit
// Tf = (9/5)*Tc | 32
IntDegF = 9*IntDegC/5+32;
__no_operation(); // Only for debugger
}
}
// ADC14 interrupt service routine
void ADC14_IRQHandler(void)
{
if (ADC14->IFGR0 & ADC14_IFGR0_IFG0)
{
temp = ADC14->MEM[0];
}
}