2011-08-24 04:35 PM
Hi all,
I'm trying to work with the ADC of the Discovery board but I've some problem.At the end of my test I can only read something from an4 to an9.There is no way to read the first 4 channel, from an0 to an3.If I connect the pins from ain0 to ain3 to gnd or vcc then the value read is always a random value, the same that I have if I leave the pin floating.Please help to find a solution......Here below some lines of my code:main: GPIO_DeInit(GPIOE); GPIO_DeInit(GPIOB); GPIO_Init(GPIOE, GPIO_PIN_6, GPIO_MODE_IN_FL_NO_IT); //ain9 GPIO_Init(GPIOE, GPIO_PIN_7, GPIO_MODE_IN_FL_NO_IT); //ain8 GPIO_Init(GPIOB, GPIO_PIN_ALL, GPIO_MODE_IN_FL_NO_IT); //ain0-ain7 ADC1_DeInit(); ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_9, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_LEFT, ADC1_SCHMITTTRIG_ALL, DISABLE); ADC1_ScanModeCmd(ENABLE); //ENABLE ADC1_ITConfig(ADC1_IT_EOCIE,ENABLE); ADC1_Cmd(ENABLE); ADC1_StartConversion();ADC1_ISR: for(i=0; i<=9;i++) Conversion_Values[i] = ADC1_GetBufferValue(i); csr_temp = ADC1->CSR; csr_temp &= (uint8_t)~ADC1_IT_EOC; csr_temp |= (uint8_t)(ADC1_CHANNEL_9); ADC1->CSR = csr_temp; ADC1_StartConversion();2011-08-25 12:37 AM
1. Check cpu clock frequency and adc prescaler settings. ADC clock max frequency can't be exceeded (see datasheet).
2. Try to replace last part of your code with the following one:// Wait until the conversion is done (no timeout => ... to be done)
while ( ADC1_GetFlagStatus(ADC1_FLAG_EOC) == RESET );
// EOC <- 1 then retrieves data from ADC buffers
for (i=0; i<9; i++)
Conversion_Values [9+i] = (unsigned int)ADC1_GetBufferValue(i); // 10 bit
// SW Clear the EOC flag to get the ADC ready for the next start conversion command
ADC1_ClearFlag(ADC1_FLAG_EOC);
ADC1_StartConversion(); brazov2