cancel
Showing results for 
Search instead for 
Did you mean: 

With STM8S005C6 How to program ADC Interrupt with a range of ADC_WG with continuos mode, with the scanning?

SBosc
Associate II

Hello, I would like help to have configurating the ADC peripheric to use it in continuos mode with three channels of the micro stm8s005c6, could you hand me an example made with the FWL from ST? Im using it right now with no success.

I have being reading the Reference Manual and all the guides to act directly with the registers but if I can save time using the library that could be vey helpfull.

This is my actual configuration on ADC channel 3:

#include "stm8s.h"
#include "hal_adc.h"
#include "stm8s_adc1.h"
 
 /**
  * @brief ADC1 configuration
  * @param None
  * @retval None
  */
 
void adc_config(void){
  ADC1_DeInit();
  ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS,
      ADC1_CHANNEL_3,
      ADC1_PRESSEL_FCPU_D18,
      ADC1_EXTTRIG_GPIO,
      DISABLE,
      ADC1_ALIGN_RIGHT,
      ADC1_SCHMITTTRIG_CHANNEL3,
      DISABLE);
 
 ADC1_AWDChannelConfig(ADC1_CHANNEL_3, ENABLE);
 ADC1_SetHighThreshold(50);
 ADC1_SetLowThreshold(0);
 ADC1_ITConfig(ADC1_IT_AWDIE, ENABLE);
 ADC1_Cmd(ENABLE);
 ADC1_ScanModeCmd(ENABLE);
}

  This is what I do inside the interrupt:

void @interrupt @svlreg ADC_IRQHandler(void){
 uint8_t i;
 
 if (ADC1_GetAWDChannelStatus(ADC1_CHANNEL_3)){
  GPIO_WriteLow(GPIOD, GPIO_PIN_0);
 }
 
 n++;
 ADC1_ClearFlag(ADC1_FLAG_AWD);
 ADC1_ClearFlag(ADC1_FLAG_EOC);
}

0 REPLIES 0