cancel
Showing results for 
Search instead for 
Did you mean: 

Timer and ADC on STM32F429

DetlefS
Senior

Hi,

I want to kick ADC1 IN5 with the Timer TIM2. 

I'm working with CubeIDE.

I select:

ADC1 -> ADC_Regular_Conversion_Mode -> External Trigger Conversion Source  -> Timer 2 Trigger Out event

TIM2 ->  Trigger Output (TRGO) Parameters -> Update Event

But ADC1 does not run, Data Register is constant.

If I kick ADC1 by software everything is fine, I get some noisy numbers.

TIM2 is running, the count register is counting.

Why does TIM2 not kick ADC1 by the TRGO event?

This setup used to work fine on STM32F303. 

What do I miss on the STM32F429?

THX Cheers

Detlef 

18 REPLIES 18

I looked at your ioc file. You didn't enable Timer interrupt for update event.

KarlYamashita_1-1769790084741.png

 

 

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

Karl Yamashita
Principal

I took your IOC file and generated a project. I'm not sure if there is a reason you're using PWM with no output for Timer1 but I don't see an Option for the ADC to use an appropriate trigger from Timer1.  I used Timer 3 which the ADC can trigger off the Trigger Out Event. I attached the updated IOC file.

 

I always use DMA so i use HAL_ADC_Start_DMA. But I noticed that you're using  HAL_ADC_Start in which the DR register value does not update. But if I use HAL_ADC_Start_IT, the DR register value updates. 

Either HAL_TIM_Base_Start_IT or HAL_TIM_Base_Start works. But with your Counter Period at 71 (1.69us), it is too fast so the Timer Interrupt keeps the main while loop from running. If you plan to send this ADC value as telemetry data, then HAL_TIM_Base_Start will work best.

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

Hi,

sorry for the somewhat delayed answer, I crashed my development environment and had to set it up anew. The problem is solved . The ADC needs interrupt capabilities, both in the .ioc file and with HAL_ADC_Start_IT . This is not necessary for the Timer. It worked for STM32F303 because there I started from the beginning with DMA. This will be next, stay tuned ;) .

THX Cheers

Detlef

Hi,

DMA does not work :( . I added DMA 2 Stream 0 to ADC1. DMA 2 Stream 0 is configured as a circular buffer. In NVIC settings of ADC1 global interrupts  ADC1, ADC2 and ADC3  are enabled. DMA 2 Stream 0 is greyed out, I can not enable it.

I replaced

HAL_ADC_Start_IT(&hadc1);

with

HAL_ADC_Start_DMA (&hadc1, (uint8_t *) hugbuf, (uint16_t)HUGBUFLEN); 

I added 

HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef * hadc1)

HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc1)

 

but HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef * hadc1) is only called once.

 

What am I missing?

THX Cheers

Detlef

 

 

 

TDK
Super User

The code you shared doesn't use DMA at all.

The function HAL_ADC_Start_DMA works as intended. You can see an example of it being used here:

STM32CubeF4/Projects/STM324xG_EVAL/Examples/ADC/ADC_RegularConversion_DMA/Src/main.c at 7c6a0a09ecb81b360de396479e048907563f1d10 · STMicroelectronics/STM32CubeF4

 

> What am I missing?

Should we just guess or do you want to share relevant code? My crystal ball suggests DMA isn't configured in circular mode.

If you feel a post has answered your question, please click "Accept as Solution".

It could be possible that you didn't enable DMA Continuous Requests as you didn't mention that you did.

I redid your IOC project to use DMA. I've configured for 2 channels so you can see how it's done with more than 1 channel. I've tested and validated on an STM32F411 which only has ADC1 but all the ADC configurations are the same as the STM32F429. Hopefully i didn't miss copying any of the F411 parameters to your IOC. I did change the Timer3 period so you may need to adjust to what you need.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

Hi,

can not enable continuous DMA requests, it is greyed out. The same for DMA 2 stream 0 !!??  

I will check the code tomorrow, thx. Attached my latest effort.

Cheers

Detlef

I opened your latest IOC file and i was able to enable the DMA Continuous Requests. Maybe you tried it before you went to DMA Settings and enabled DMA? If so, then you would not be able to enable it.

 

KarlYamashita_0-1770106127281.png

 

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

Hi,

I returned to my home development environment and i was able to enable the DMA Continuous Requests as well. May be itis  an issue with my MxCube.Version=6.14.0, at home I use MxCube.Version=6.15.0. With my MxCube.Version=6.14.0  after editing .ioc and generating code my open main.c was frozen !?

OK, I will update. I want to fire up STM32F429I-Disc, still lots of traps, stay tuned :|   .

THX a lot.

Cheers Detlef