I find it difficult to believe that I haven't get my Xmega ADC working for 2 days already. My task is simple, I just need to sample ADC from ADCA1 of xmegaA3BU.
I had the code
PORTA.DIRCLR = PIN1_bm; PORTA.PIN1CTRL = PORT_OPC_TOTEM_gc | PORT_ISC_INPUT_DISABLE_gc; PR.PRPA &= ~PR_ADC_bm; ADCA.CTRLB = ADC_CONMODE_bm | ADC_RESOLUTION_12BIT_gc; ADCA.EVCTRL = 0; ADCA.REFCTRL = ADC_BANDGAP_bm | ADC_REFSEL_INT1V_gc; ADCA.PRESCALER = ADC_PRESCALER_DIV32_gc; ADCA.CH1.CTRL = ADC_CH_INPUTMODE_SINGLEENDED_gc; ADCA.CH1.MUXCTRL = ADC_CH_MUXPOS_PIN1_gc; ADCA.CH1.INTCTRL = 0; ADCA.CTRLA = ADC_ENABLE_bm; timer_delay_us(400); ADCA.CH1.INTFLAGS = ADC_CH_CHIF_bm; ADCA.CH1.CTRL = ADC_CH_START_bm; while (!(ADCA.CH1.INTFLAGS & ADC_CH_CHIF_bm)); dbg_printf("ADC %u\n", ADCA.CH1.RES);
I left the pin floating, or tied to ground, and the value remains the same. It is around 1360 and 2360 in unsigned mode. I tried internal inputs, the result is good, but not the external input. Neither differential mode nor single ended mode makes differences.
M suspecting that is it possible the multiplexer did not route the PA1 pin to the pipeline for some reason?
By the way, I also tried to put PA1 output and HIGH when ADCA is enabled and connecting to PA1 at channel 1. Is it normal?