AnsweredAssumed Answered

STM8L DISCOVERY ADC

Question asked by _ago_ski.Artur on May 14, 2017

Hello,
I want to create program that:
1. Measure time
2. Start one conversion of ADC
3. After conversion show it on LCD (it's optional, but it would be great if it works)
The 2nd point is problematic. I want to realize all on interrupts and my program doesn't jump into adc int handling.
Here is a ADC configuration:
void ADC_Periph_Init(void)
{
  CLK->PCKENR2|=0x01; //adc clock en
  ADC1->CR1|=0x01;  //adc ADON
  ADC1->SQR[0]|=0x81;  //select channel 24, DMA disable for single conversion
  GPIOF->DDR&=0xFE;
  GPIOF->CR1&=0xFE;
  GPIOF->CR2&=0xFE;  //gpio for adc configutation for PF0
  ADC1->CR1|=0x68;   //resolution, single conversion, enable interrupt end of conversion
  ADC1->CR2&=0x78; //sample time, PRESC=0
  ADC1->CR3=0x1F;  //sample time
  ADC1->CR1&=0xFE;
}
Here is TIM4 int
INTERRUPT_HANDLER(TIM4_UPD_OVF_TRG_IRQHandler, 25)
{
  TIM4->SR1&=0xFE; //clear flag from ovf
  if(((GPIOC->ODR&0x80)>>7)==0x01){
  GPIOC->ODR&=0x7F;
  }
  else{
  GPIOC->ODR|=0x80;  
  }
  if((GPIOA->IDR&0x08)==0x08)licznik2++;
  else licznik2=0;
  if ((licznik2==10)&&(~ADC_start_conv)){
  ADC1->CR1|=0x01;
  ADC_start_conv=TRUE;
  for(i=0;i>16000;i++)
  ADC1->CR1|=0x02;
  }
 
  TIM4->CNTR=0xFF-488;
return;
}

generally ADC->CR1|=0x01 is done when switch is on for a period of time.
I use IAR.
Where is the fault and how it should look properly?

Outcomes