Read an analog PIN for Mikromedia STM32

Post Reply
Author
Message
antoniodati@hotmail.com
Posts: 4
Joined: 02 Jan 2024 20:24

Read an analog PIN for Mikromedia STM32

#1 Post by antoniodati@hotmail.com » 03 Jan 2024 11:15

Hello Mikroe,
I'm working with the mikromedia for STM32 (STM32F407VGT6).
I ask you like read an analog PIN and allocate the value to floating point variable.
I tried to execute it creating the follow code:

void Screen2_DA (){
float an;
char bant[15];

GPIO_Set_Pin_Mode(&GPIOA_BASE, _GPIO_PIN_1, _GPIO_CFG_MODE_ANALOG); // PA1 like an analog pin

an= GPIOA_BASE; // I try to allocate the analog value from PA1 to an (I think that there is my problem)

FloatToStr(an, bant);
TFT_Write_Char(bant[0], 100, 30);
TFT_Write_Char(bant[1], 110, 30);
TFT_Write_Char(bant[2], 120, 30);
TFT_Write_Char(bant[3], 130, 30);
}

After the bulded firmware there aren't syntax errors but after programming the display doesn't view the update from PA1.
Trank you so much

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Read an analog PIN for Mikromedia STM32

#2 Post by IvanJeremic » 03 Jan 2024 15:24

Hi,

Try using our ADC library and then try to display the data.

I have attached an example below:
ADC Demo.rar
(69.91 KiB) Downloaded 47 times
Also try debugging the code, see if it freezes somewhere or it just cant display the data.

Regards,

Ivan.

antoniodati@hotmail.com
Posts: 4
Joined: 02 Jan 2024 20:24

Re: Read an analog PIN for Mikromedia STM32

#3 Post by antoniodati@hotmail.com » 11 Jan 2024 21:19

Hi Ivan,
I thank you so much for your answer but my problem is to read from an analog input voltage (PA6 for example) and not set a digital output. However your demo rar was important for to remember the ADC module. Next you can see my code to read from an analog voltage PIN without syntax error, but it doesn't view on the display the correct number.

void Screen2_DA (){
float a;
char b[100];
unsigned adc_value;

GPIO_Analog_Input(&GPIOA_BASE, _GPIO_PINMASK_6); // Set PORTA as input PA6

ADC_Set_Input_Channel(6); // Choose ADC channel
ADC1_Init();
adc_value= ADC1_Get_Sample(6);
Delay_ms(1000);

a=adc_value;
FloatToStr(a, b);
TFT_Write_Char(b[0], 100, 30);
TFT_Write_Char(b[1], 110, 30);
TFT_Write_Char(b[2], 120, 30);
}

What should be the best solution for you?
Thank you again

Antonio Dati

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Read an analog PIN for Mikromedia STM32

#4 Post by IvanJeremic » 15 Jan 2024 12:22

Hi,

"but it doesn't view on the display the correct number", can you explain in more detail what exactly happens?

How is the data displayed not correct, can you send me a picture of your display?

Regards,

Ivan.

antoniodati@hotmail.com
Posts: 4
Joined: 02 Jan 2024 20:24

Re: Read an analog PIN for Mikromedia STM32

#5 Post by antoniodati@hotmail.com » 16 Jan 2024 21:54

Hello Ivan,
In the attachment you can find the picture.
I want only displays the voltage input from multimeter to the Mikromedia display.

I don't find any reference on the library help document (library GPIO)

Thank you so much for the patience.
Antonio Dati
Attachments
Analog input
Analog input
IMG_20240116_214847.jpg (5.88 MiB) Viewed 470 times

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: Read an analog PIN for Mikromedia STM32

#6 Post by IvanJeremic » 23 Jan 2024 14:47

Hi,

Sorry for the delay.

You need to convert the raw data into voltage.

You can use the forum below as a reference:
viewtopic.php?t=18427

Regards,

Ivan.

antoniodati@hotmail.com
Posts: 4
Joined: 02 Jan 2024 20:24

Re: Read an analog PIN for Mikromedia STM32

#7 Post by antoniodati@hotmail.com » 24 Jan 2024 16:09

Hi Ivan,
No problem for delay and thank you.
Antonio

Post Reply

Return to “Mikromedia”