ADC single conversion on STM32

跟風遠走 提交于 2019-12-05 16:22:52

i'll try to explain what's going on with source code.

1- definition of disable is zero : typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;

2- so when you write "ADC_InitStructure.ADC_ExternalTrigConv = DISABLE;" you actually assign it to zero like this "ADC_InitStructure.ADC_ExternalTrigConv = 0;

3- this means your assigning the EXTSEL of ADC_CR2 register to zero.

4-if EXTSEL is zero, adc conversion depends on the timers to start.

5-if you want adc to be started by software, EXTSEL must be 0x000E0000;

6- and as you can guess the value of "ADC_ExternalTrigConv_None" is defined as 0x000E0000;

so while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); code will hung up here because it depens on the timers to start, it cannot end if it is not started.

Problem solved! It's my fault to disable external trigger. Instead of using:

ADC_InitStructure.ADC_ExternalTrigConv = DISABLE;

It shoud be like this:

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

What a silly!

I will not invent a wheel here by saing that you are hanging in one of those three while() loops. Make some output before each of then then you will know where you are hanging.

If you have debugger (it is present on every ST development board, and possibly you are using it to download program) don't hesitate to use it :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!