About Starting ADC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 12:37 AM
Hello.​
I am using the STM32L4 series.
I want to send the ADC converted sensor value to the PC via UART communication.
​
I started ADC in /* USER CODE BEGIN 2 */ zone of "main.c" output from CubeIDE, but it failed.
When the start instruction is given twice as shown below, the code is executed, but the sensor value cannot be obtained.
​
if(HAL_ADC_Start_IT(&hadc2)!=HAL_OK){ //result: TRUE
int aaa=0;
aaa=1;
if(HAL_ADC_Start_IT(&hadc2)!=HAL_OK){ //result: FALSE...why?
aaa=0;
}
}
​
I am at a loss because I have no idea what the cause is.
I am sorry to trouble you, but please reply regarding this matter.
- Labels:
-
ADC
-
STM32L4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 3:02 AM
If the result is not HAL_OK, find out what it is. And/or debug-step into the second call. HAL_ADC_Start_IT - do you have interrupt enabled and a callback?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 4:13 AM
Does the first ADC "process" finished by the time you try to run it the second time?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 8:30 AM
I'll try check the details of the result.
​
I have enabled ADC2, but not specifically enabled interrupts (see image).
​I am thinking to enable continuous conversion and get the value as below with timer interrupt.
​
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim == &htim7){ //1ms timer
​
iAdVal=HAL_ADC_GetValue(&hadc2); �? this
sprintf(sbuff, ",%d", iAdVal);
memcpy(&td[strlen(td)],sbuff,strlen(sbuff));
cnt_tim7++;
if (cnt_tim7>=TD_CNT_MAX)
{
if(huart2.gState==HAL_UART_STATE_READY){
HAL_UART_Transmit(&huart2, (uint8_t*)td, strlen(td), 0xFFFF);
memset(td, '\0', cnt_tim7);
cnt_tim7=0;
​
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 8:37 AM
The ADC is set to continuous conversion mode. Need to care about the timing of the process?
The ADC value is obtained in the timer interrupt process.
iAdVal=HAL_ADC_GetValue(&hadc2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 8:39 AM
The ADC is set to continuous conversion mode. Need to care about the timing of the process?
The ADC value is obtained in the timer interrupt process.
iAdVal=HAL_ADC_GetValue(&hadc2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 8:55 AM
> The ADC is set to continuous conversion mode.
Then why do you start it the second time?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 10:41 AM
When you start IT version then ADC runs on background. Your code continues immediately to next start end return false = cant start twice.
Plus continuos mode dont need next start without any stop used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-22 10:48 AM
When parenthes in code is ok second start never occur when first is true, But if example code is repeated then both results is false,..
