Part Number: TM4C123GH6PM
Hello,
I need to read PD2 and PD3 as analog inputs. So I have done:
uint32_t fifo_left[4];
uint32_t fifo_right[4];
void init_adc() {
// enable adc0
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
// PD2, PD3
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
// configure two sequences
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 1);
// sequence 1 step configuration
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH4);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH4);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH4);
ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_CH4 | ADC_CTL_IE | ADC_CTL_END);
// sequence 2 step configuration
ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH5);
ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH5);
ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH5);
ADCSequenceStepConfigure(ADC0_BASE, 2, 3, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);
// enable sequences
ADCSequenceEnable(ADC0_BASE, 1);
ADCSequenceEnable(ADC0_BASE, 2);
// clear interrupt
ADCIntClear(ADC0_BASE, 1);
ADCIntClear(ADC0_BASE, 2);
}
and in the while loop:
// trigger adc, wait for result, clear int, and get data to fifo
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false)) { }
ADCIntClear(ADC0_BASE, 1);
ADCSequenceDataGet(ADC0_BASE, 1, fifo_right);
ADCProcessorTrigger(ADC0_BASE, 2);
while(!ADCIntStatus(ADC0_BASE, 2, false)) { }
ADCIntClear(ADC0_BASE, 2);
ADCSequenceDataGet(ADC0_BASE, 2, fifo_left);
and it works. I am using two sequences (1 and 2) on ADC0, and sampling CH4 and CH5.
Here are my questions: Could I configure the steps of the sequence all at once? Like, read ch4 into fifo, and then end generating intterrupt?
And the second question: in the while loop, i trigger sequence 1, and then wait and then read. then for the sequence 2. could i trigger both sequences at the same time, or is there a better way of doing it?
With best regards,
Can