cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F05 ADC Disscusson

pic_micro
Associate II
Posted on December 26, 2014 at 06:56

Dear All,

I started STM32F0 ADC configurations

select independent conversion mode (single)
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
But my CMSIS stm32f0xx.adc.c file does not have above ADC.Mode command and also it does not have

ADC_Mode_Independent;

0690X0000060MmzQAE.gif Please advice
3 REPLIES 3
Posted on December 26, 2014 at 09:06

Ok, but please provide some actual context here about what you're attempting to do, and where you pulled the independent stuff from in the first place. Cite sources.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pic_micro
Associate II
Posted on December 26, 2014 at 09:58 Dear Sir, Thanks for the reply really what I need is to setup ADC, then the result to be sent to PC using USART Expected ADC source is PA1 Therefore I directly connected the 3.3v to PA1

/* Configure ADC Channel as analog input */
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; // PA.1 ADC IN1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure); 

Clock configuration

void RCC_init(){
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE); /* USART1 Periph clock enable */
RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE); /* ADC1 Periph clock enable */
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOC | 
RCC_AHBPeriph_GPIOA,ENABLE); /* GPIOA&C Periph clock enable */
}

ADC Configuration

void ADC_init(){
ADC_InitTypeDef ADC_InitStructure;
/* Initialize ADC structure */
/* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits*/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; 
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
ADC_Init(ADC1, &ADC_InitStructure); 
/* Convert the ADC1 input with 5 Cycles as sampling time */
ADC_ChannelConfig(ADC1, 1, ADC_SampleTime_55_5Cycles); // PA.1 - IN1
ADC_GetCalibrationFactor(ADC1); /* ADC Calibration */
ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 */
// while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)); /* Wait the ADCEN falg */
ADC_StartOfConversion(ADC1); /* ADC1 regular Software Start Conv */
}

ADC read

void READ_adc(){
/* Convert the ADC1 input with 5 Cycles as sampling time */
ADC_ChannelConfig(ADC1, 1, ADC_SampleTime_55_5Cycles); // PA.1 - IN1
/* Test EOC flag */
//while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
ADC_Value = ADC_GetConversionValue(ADC1);

send data void Send_Data(){ while(1) { READ_adc(); for(i=0;i<27;i++){ while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); USART_SendData(USART1, name[i]); } Delay(Del_val); USART_SendData(USART1,ADC_Value); } } Please advice
pic_micro
Associate II
Posted on December 27, 2014 at 08:59

Dear Sir,

Following ADC program is working with TIM3 trigger, What should I need is to modify the program, except timer directly input to channel 11 ( PC1) to convert

/* Includes ------------------------------------------------------------------*/
#include ''stm32f0xx.h''
//#include ''stm32f0_discovery.h''
#include ''stm32f0xx_usart.h''
#include ''stm32f0xx_adc.h''
__IO uint32_t Del_val = 2500000;
void Delay(__IO uint32_t nCount);
char name[27]=''USART2 PA9TX -PA10RX dd- '';
int i,j;
__IO uint16_t ADC1ConvertedValue = 0, ADC1ConvertedVoltage = 0;
/* Private function prototypes -----------------------------------------------*/
void ADC1_Config(void);
void gpio_init();
void USART_gpio_Initialize();
void USART_Configuration();
void LED();
void Send_Data();
void RCC_Configuration();
int main(void)
{
RCC_Configuration();
gpio_init();
USART_Configuration();
LED();
ADC1_Config(); /* Configure ADC1 Channel 11 */
while (1){
Send_Data();
ADC1ConvertedValue = ADC_GetConversionValue(ADC1);/* Get ADC1 converted data */
ADC1ConvertedVoltage = (ADC1ConvertedValue * 3300)/0xFFF; /* Compute the voltage */
}
}
void LED(){
GPIOC->ODR ^= GPIO_Pin_8;
}
void RCC_Configuration(){
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* GPIOC Periph clock enable */ 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* ADC1 Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); /* TIM3 Periph clock enable */
}
void USART_Configuration(){
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;//9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1,ENABLE);
}
void gpio_init(){
GPIO_InitTypeDef GPIO_InitStructure; 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8 ; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure); 
/* Configure ADC Channel11 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
//Configure USART1 pins: Rx and Tx ----------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void ADC1_Config(void){ 
ADC_InitTypeDef ADC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure; 
/* TIM3 Configuration *******************************************************/
TIM_DeInit(TIM3); 
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructure); 
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* TIM3 TRGO selection */
TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);
/* ADC1 Configuration *******************************************************/
/* ADCs DeInit */ 
ADC_DeInit(ADC1);
/* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits*/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; 
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
ADC_Init(ADC1, &ADC_InitStructure); 
/* Convert the ADC1 Channel 11 with 5 Cycles as sampling time */ 
ADC_ChannelConfig(ADC1, ADC_Channel_11 , ADC_SampleTime_28_5Cycles); 
ADC_GetCalibrationFactor(ADC1); /* ADC Calibration */
ADC_WaitModeCmd(ADC1, ENABLE); /* Enable the auto delay feature */ 
ADC_AutoPowerOffCmd(ADC1, ENABLE); /* Enable the Auto power off mode */
ADC_Cmd(ADC1, ENABLE); /* Enable ADCperipheral[PerIdx] */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)); /* Wait the ADCEN falg */
TIM_Cmd(TIM3, ENABLE); /* TIM2 enable counter */
ADC_StartOfConversion(ADC1); /* ADC1 regular Software Start Conv */ 
}
void Delay(__IO uint32_t nCount){
while(nCount--)
{
}
}
void Send_Data(){ 
for(i=0;i<27;i++){
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
//USART_SendData(USART1, name[i]);
USART_SendData(USART1, ADC1ConvertedValue);
USART_SendData(USART1, ADC1ConvertedVoltage);
}
Delay(Del_val);
}