STM32 Beginner: needs help on ADC with STM32F103r8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-01 6:27 AM
Hi,
I am a beginner for stm32. I am using stm32f103r8 , IAR-ARM IDE.
I have attached my celow , this is not working , i am checking it in Proteus 8.8v ( with stm32f103r6). Can anyone help me out with this ?
PROGRAM:
#include "stm32f10x.h"
#include "stm32f10x_adc.h"
void main()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); //Enable ADC1..//
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //Enable Port C..//
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;;
GPIO_Init(GPIOC, &GPIO_InitStruct);
//----------------------------ADC Initialize------------------------------//
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ExternalTrigConv = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Cmd(ADC1, ENABLE);
//----------------------Selecting input Channel--------------------------//
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 1, ADC_SampleTime_1Cycles5);
//-------------------------Start Conversion------------------------------//
for(;;)
{
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
ADC = ADC_GetConversionValue(ADC1);
if(ADC > 500)
{
GPIOC->BSRR = 0X0000000F;
}
else
{
GPIOC->BRR = 0X0000000F;
}
}
}
- Labels:
-
ADC
-
STM32F1 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2019-06-01 6:35 AM
When using as local/auto variables I'd recommend clearing them properly
GPIO_InitTypeDef GPIO_InitStruct ={0};
ADC_InitTypeDef ADC_InitStructure = {0};
>>this is not working
Yeah that's not very enlightening, use the debug step the code, review the settings in side the peripherals, try to understand the mechanics of the failure.
Up vote any posts that you find helpful, it shows what's working..
