2023-10-10 04:06 AM
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.
The above is the power rails configuration .
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.
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
Then I have build my program and converted into hex file whereafter I copied its path to the proteus stm32 model's program file.
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.
Solved! Go to Solution.
2023-10-13 07:27 AM
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.
2023-10-10 04:16 AM
Hello,
Please provide with the initialization part of your code (ADC, GPIO etc..) or attach your main+msp file.
2023-10-10 05:28 AM
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.
2023-10-10 10:55 PM
2023-10-10 10:59 PM
Its not making any difference. Its still showing 0 as output.
2023-10-12 07:13 AM - edited 2023-10-12 07:20 AM
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().
2023-10-13 02:32 AM
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.
2023-10-13 03:46 AM
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.
2023-10-13 07:27 AM
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.
2023-10-16 01:34 AM
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