工具/软件:
我尝试按单个序列接收五个值、即 ADC 通道 CH0 至 CH3 和温度传感器。
我已经使用以下代码对其进行了配置、并可以使用接收数据:
ADCSequenceDataGet (ADC0_BASE、0、GS_pui32ADCBuffer);但是、当我向 AIN3 (ADC CH3) 施加 1V 电压时、温度传感器值也会略有变化 (ADCSequenceDataGet 函数写入的值增加约 100)。您是否知道温度传感器值可能会发生变化?在其他函数中启用计时器中断。
//
// Enable the peripherals used by this application.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//
// Enable the GPIO pin for ADC0 Channel 0-4 (PE3 PE2 PE1 PE0) which configures it for
// analog functionality.
//
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_HALF, 1);
//
// Wait for the clock configuration to set.
//
SysCtlDelay(10);
//
// Disable the ADC0 sequence 0 interrupt on the processor (NVIC).
//
IntDisable(INT_ADC0SS0);
//
// Disable interrupts for ADC0 sample sequence 0 to configure it.
//
ADCIntDisable(ADC0_BASE, 0);
//
// Disable ADC0 sample sequence 0. With the sequence disabled, it is now
// safe to load the new configuration parameters.
//
ADCSequenceDisable(ADC0_BASE, 0);
//
// Enable sample sequence 0 with a processor signal trigger. Sequence 0
// will do a single sample when the processor sends a signal to start the
// conversion.
//
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
ADCReferenceSet(ADC0_BASE,ADC_REF_EXT_3V);
//アナログ入力0-4Ch,温度センサの値を取得する設定
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3);
ADCSequenceStepConfigure(ADC0_BASE, 0, 4,
ADC_CTL_TS | ADC_CTL_END | ADC_CTL_IE);
//
// Since sample sequence 0 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 0);
//
// Clear the interrupt status
ADCIntClear(ADC0_BASE, 0);
//
// Enables the DMA channel for the ADC0 sample sequence 0.
//
//ADCSequenceDMAEnable(ADC0_BASE, 0);
//
// Enable the ADC 0 sample sequence 0 interrupt.
//
ADCIntEnable(ADC0_BASE, 0);
//
// Enable the interrupt for ADC0 sequence 0 on the processor (NVIC).
//
IntEnable(INT_ADC0SS0);
//
// Enable the ADC trigger output for Timer A.
//
TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
//
// Enable processor interrupts.
//
IntMasterEnable();