analogRead() Freezes the program

Post here first, or if you can't find a relevant section!
saini999
Posts: 8
Joined: Sat May 06, 2023 5:36 am

analogRead() Freezes the program

Post by saini999 »

The Code:
code.png
code.png (39.31 KiB) Viewed 1031 times
and Proteus Simulation:
freeze.jpg
freeze.jpg (69.7 KiB) Viewed 1031 times
Im using STM32Duino Core, Arduino-CLI with VSCode Arduino Extension

When the code reaches analogRead() function it just freezes the Chip

Please let me know what could be the issue?
saini999
Posts: 8
Joined: Sat May 06, 2023 5:36 am

Re: analogRead() Freezes the program

Post by saini999 »

also the baud generated by the MCU is 8 times less than real baud, MCU Clock is working fine but i have to multiply baud by 8 to get correct Serial Baud Rate

i.e : Serial.begin(9600) works with Baud1200 in proteus
and Serial.begin(9600 * 8) works with baud 9600 in proteus
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: analogRead() Freezes the program

Post by fpiSTM »

You probably have to redefine HSE_VALUE if you use it.
This would explain issue with baudrate.
saini999
Posts: 8
Joined: Sat May 06, 2023 5:36 am

Re: analogRead() Freezes the program

Post by saini999 »

fpiSTM wrote: Sat May 06, 2023 9:17 am You probably have to redefine HSE_VALUE if you use it.
This would explain issue with baudrate.
I tried this but still didnt work
I tried setting HSE_VALUE to 16m and 8m to see if baudrate changes but no, same with HSI_VALUE
saini999
Posts: 8
Joined: Sat May 06, 2023 5:36 am

Re: analogRead() Freezes the program

Post by saini999 »

just Checked interrupts dont work either .-.

With code: attachInterrupt(digitalPinToInterrupt(PA0), update, CHANGE);
and update function with Serial.println("Tick"); but no response from interrupt, i tried using direct pin name instead of digitalPinToInterrupt() and didnt work either.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: analogRead() Freezes the program

Post by fpiSTM »

Which mcu you used and target you select?
saini999
Posts: 8
Joined: Sat May 06, 2023 5:36 am

Re: analogRead() Freezes the program

Post by saini999 »

fpiSTM wrote: Sat May 06, 2023 11:03 am Which mcu you used and target you select?
I'm using STM32F401VE MCU in Proteus

and STM32F401VETx Generic in Arduino IDE
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: analogRead() Freezes the program

Post by GonzoG »

Have you checked if board setup in stm32duino (clocks, etc) is same are your hardware ??
saini999
Posts: 8
Joined: Sat May 06, 2023 5:36 am

Re: analogRead() Freezes the program

Post by saini999 »

GonzoG wrote: Sat May 06, 2023 2:51 pm Have you checked if board setup in stm32duino (clocks, etc) is same are your hardware ??
Proteus only has External Clock Frequency for STM which is set to 8Mhz by default

Idk about board setup, please let me know what files have configs
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: analogRead() Freezes the program

Post by fpiSTM »

Generic uses HSI. So not an HSE issue.
https://github.com/stm32duino/Arduino_C ... lock.c#L22
Post Reply

Return to “General discussion”