cancel
Showing results for 
Search instead for 
Did you mean: 

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

Krishnangshu
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

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

View solution in original post

13 REPLIES 13
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.
ONadr.1
Senior III

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.

I am hereby sending you the main and msp file.

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

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

Could you please show me how to show the output of the ADC converted value on GPIOB port. I couldn't find it in the main file. And also I am not having the actual stm32f103C6 board with me that is why I am simulating it on proteus.

Try include stdio.h library. Perharps simulator doesnt include it automatically.

For direct output of values via the serial port, you can do the conversion to strig manually by dividing by 10. x=convVal;

outstr[n]=0;

outstr[n-1]=(x%10)+'0';

x=x/10;

outstr[n-2]=(x%10)+'0';

x=x/10;

and so on, so on..... for how meny numbers do you need.

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.

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

I am not having the real board with me, thats why I am using proteus. Can you please tell me the code for showing the ADC converted value in UART because the proteus has the virtual terminal which has the receiving and transmitting lines which can be attached to the stm32 model for seeing the output