Skip to main content
Associate
October 10, 2023
Solved

Why is my ADC only showing zero as an output while simulating the stm32f103C6 model in proteus?

  • October 10, 2023
  • 2 replies
  • 19395 views

Krishnangshu_0-1696934804825.png

The above is my schematic layout of ,STM32F103C6 Series, attached to a virtual terminal with transmitting and receiving lines mentioned and the pin PA2 is used as an ADC input pin.

Krishnangshu_1-1696935020724.png

The above is the power rails configuration .

Krishnangshu_2-1696935105658.png

The above is the pinout view where PA9 and PA10 are used for transmitting and receiving which are attached to the virtual terminal as showed.

Krishnangshu_3-1696935358908.png

The above is the code where I declared test as an unsigned integer of 16 bits and character msg of length 10.

Then I have written the code for starting the ADC and then stopping for Conversion whereafter I have retrieved the values from HAL_ADC_GetValue and transmited to the virtual monitor by the help of UART Transmit function

Krishnangshu_4-1696935626017.png

Then I have build my program and converted into hex file whereafter I copied its path to the proteus stm32 model's program file.

Krishnangshu_5-1696935761308.png

The above is the output I am getting.

I am very confused on what went wrong in my program and simulation,

It would be very helpful If you guyz could assist me on this issue.

This topic has been closed for replies.
Best answer by mƎALLEm

Hello;

I didn't say I tested the example with GPIO output I just tested the ADC conversion without printf (on a real board) and seeing the converted values on debug watch.

Outputting ADC converted is simple just write to the GPIO ODR register.

Attached the main file using GPIOs. I didn't test it.

2 replies

mƎALLEm
Technical Moderator
October 10, 2023

Hello,

Please provide with the initialization part of your code (ADC, GPIO etc..) or attach your main+msp file.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Associate
October 11, 2023

I am hereby sending you the main and msp file.

ONadr.1
Senior III
October 10, 2023

Why are you retyping msg to (uint16_t) in HAL_UART_Transmit ? It should be (uint8_t). And why is use "%hu" in your formated string? Try only %u.

Associate
October 11, 2023

Its not making any difference. Its still showing 0 as output.

mƎALLEm
Technical Moderator
October 12, 2023

Hello,

I tested the attached code on pin PC4/channel 14 with almost your code and the conversion is OK. I didn't test with printf.

I suggest you, before going to use printf, try to output the ADC converted value on GPIOB port. If it's ok then add printf after.

As said by @ONadr.1 , you have to use the same type uint8_t with HAL_UART_Transmit().

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.