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);
InitConsole();
//
// Display the setup on the console.
//
UARTprintf("ADC ->\n");
UARTprintf(" Type: Internal Temperature Sensor\n");
UARTprintf(" Samples: One\n");
UARTprintf(" Update Rate: 250ms\n");
UARTprintf(" Input Pin: Internal temperature sensor\n\n");
//5??,??PLL,????16M,system????? main osc?????40MHZ
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//??ADC0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_5);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
//We want to use ADC0, sample sequencer 1,
//we want the processor to trigger the sequence and we want to use the highest priority
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH2);
//Configure steps 0 - 2 on sequencer 1 to sample the temperature sensor (ADC_CTL_TS).
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH8|ADC_CTL_IE|ADC_CTL_END);
//Sample the temperature sensor (ADC_CTL_TS) and configure the interrupt flag (ADC_CTL_IE)
//Tell the ADC logic that this is the last conversion on sequencer1 (ADC_CTL_END).
ADCSequenceEnable(ADC0_BASE, 1);
//enable ADC sequencer 1
while(1)
{
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
//trigger the ADC conversion with software
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
//wait for the conversion to complete
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
//ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
//Since 2/4 = 1/2 = 0.5, 1.5 will be rounded to 2.0 with
//the addition of 0.5. In the case of 1.0, when 0.5 is added to yield 1.5, this will be rounded
//back down to 1.0 due to the rules of integer math.?????
//ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
//TEMP = 147.5 – ((75 * (VREFP – VREFN) * ADCVALUE) / 4096)
//VREFP – VREFN=3.3V
// ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
UARTprintf("Temperature = %d %d %d %d\r\n", ui32ADC0Value[0],
ui32ADC0Value[1],ui32ADC0Value[2],ui32ADC0Value[3]);
//F = ( C * 9)/5 +32
}
}
我自己尝试了一下,收到的数据会出现0或4095这两个数,还有就是结算公式是不是和内部温度传感器的结算方法相同,谢谢指点