TI中文支持网
TI专业的中文技术问题搜集分享网站

请看一下,这段能不能接到外接的一路数据

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

//
// 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: AIN0/PE3\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);
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_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
//Configure steps 0 – 2 on sequencer 1 to sample the temperature sensor (ADC_CTL_TS).
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|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*C or %d*F or %d \r\n", ui32TempValueC,
ui32TempValueF,ui32TempAvg);
//F = ( C * 9)/5 +32
}
}

里面的黄色部分,是不是就是指的是TM4C123GXL上面的标有PE3的这个引脚

xyz549040622:

PE3是adc的一个输入引脚,但是你使能了PE3作为AD引脚,但是连接的还是ADC_CTL_TS,这是温度传感器的。

chang liu11:

回复 xyz549040622:

n那该改成什么呀,我已经搞了一个多月了

xyz549040622:

回复 chang liu11:

比如你用的是ADC0的通道0/1/2/3,对应的序列通道1.那么例程可以这么写

    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0);ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1);ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH2);

ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH3 | ADC_CTL_IE |ADC_CTL_END);

上面的代码没经过验证,只是根据经验来配置的。

赞(0)
未经允许不得转载:TI中文支持网 » 请看一下,这段能不能接到外接的一路数据
分享到: 更多 (0)