Hi all,
I'm trying to read analog values in multiple pins with tm4c129, but I'm getting always zero.
Can I get some help, please?
My code is attached.
/* * adc.c * * Created on: 6 de set de 2017 * Author: allefpablo */ #include <stdarg.h> #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include "inc/hw_adc.h" #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/debug.h" #include "driverlib/gpio.h" #include "driverlib/sysctl.h" #include "driverlib/interrupt.h" #include "driverlib/adc.h" #include "driverlib/pin_map.h" #include "board_drivers/hardware_def.h" #include "adc.h" static uint32_t pui32ADC0Value[11]; void adc_init() { SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // // Select the analog ADC function for these pins. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_0); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_1); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_4); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_5); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_6); GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_7); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2); // // Enable sample sequence 3 with a processor signal trigger. Sequence 3 // will do a single sample when the processor sends a signal to start the // conversion. Each ADC module has 4 programmable sequences, sequence 0 // to sequence 3. This example is arbitrarily using sequence 3. // //ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); // // Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in // single-ended mode (default) and configure the interrupt flag // (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic // that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence // 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and // sequence 0 has 8 programmable steps. Since we are only doing a single // conversion using sequence 3 we will only configure step 0. For more // information on the ADC sequences and steps, reference the datasheet. // ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH1); ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH2); ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH3); ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH4); ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH5); ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH6); ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH7); ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH12); ADCSequenceStepConfigure(ADC0_BASE, 0, 8, ADC_CTL_CH13); ADCSequenceStepConfigure(ADC0_BASE, 0, 9, ADC_CTL_CH14); ADCSequenceStepConfigure(ADC0_BASE, 0, 10, ADC_CTL_CH15 | ADC_CTL_IE | ADC_CTL_END); IntEnable(INT_ADC0SS0); // // Since sample sequence 3 is now configured, it must be enabled. // ADCSequenceEnable(ADC0_BASE, 0); ADCSequenceEnable(ADC0_BASE, 1); ADCSequenceEnable(ADC0_BASE, 2); ADCSequenceEnable(ADC0_BASE, 3); ADCSequenceEnable(ADC0_BASE, 4); ADCSequenceEnable(ADC0_BASE, 5); ADCSequenceEnable(ADC0_BASE, 6); ADCSequenceEnable(ADC0_BASE, 7); ADCSequenceEnable(ADC0_BASE, 8); ADCSequenceEnable(ADC0_BASE, 9); ADCSequenceEnable(ADC0_BASE, 10); // // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before we sample. // //ADCIntClear(ADC0_BASE, 0); } uint32_t read_adc(uint32_t sequence, uint32_t *values) { ADCIntClear(ADC0_BASE, sequence); ADCProcessorTrigger(ADC0_BASE, sequence); while(!ADCIntStatus(ADC0_BASE, sequence, false)){} return (ADCSequenceDataGet(ADC0_BASE, sequence, values)); } uint32_t get_voltage_ch_1() { return read_adc(4, pui32ADC0Value); } uint32_t get_voltage_ch_2() { return read_adc(3, pui32ADC0Value); } uint32_t get_voltage_ch_3() { return read_adc(5, pui32ADC0Value); } uint32_t get_voltage_ch_4() { return read_adc(6, pui32ADC0Value); } uint32_t get_current_ch_1() { return read_adc(2, pui32ADC0Value); } uint32_t get_current_ch_2() { return read_adc(1, pui32ADC0Value); } uint32_t get_current_ch_3() { return read_adc(0, pui32ADC0Value); } uint32_t get_current_ch_4() { return read_adc(7, pui32ADC0Value); } uint32_t get_lv_signal_ch_1() { return read_adc(8, pui32ADC0Value); } uint32_t get_lv_signal_ch_2() { return read_adc(9, pui32ADC0Value); } uint32_t get_lv_signal_ch_3() { return read_adc(10, pui32ADC0Value); }