Skip to main content
idrissmc
Associate III
July 9, 2019
Solved

Displaying the value of a temperature on the LCD

  • July 9, 2019
  • 2 replies
  • 2317 views

Hello everyone,

so what I’m going to do is displaying the value of the temperature on the LCD of the STM32F413H-Disco with a PT100, i wrote this code:

int value;

char getvalue[20];

...

MX_ADC_Init();

HAL_ADC_Start_IT(&hadc1); (I choose Interruption because in reality i started with a simple potentiometer so I think that if I turn it faster I have to see the right value, I don’t want that the program run all the code and then display the value, that’s why I used the interruption )

HAL_ADC_PollForConversion(&hadc1, 100);

value = HAL_ADC_GetValue(&hadc1);

itoa(value, getvalue, 10);

..

GUI_Clear();

GUI_SetFont(....);

GUI_DisplayStringAt(...);

I declared the MX_ADC_Init function

but it displays 0 on the LCD.

Clive Two.Zero can you help me to resolve this please?

thanks

    This topic has been closed for replies.
    Best answer by Bob S

    I don't use CubeIDE (or the predecessor Atollic), so I can't tell you exactly how. Check the CubeIDE quick start and debugging guides on the CubeIDE web page (search the docs for "SWV"). In your code, you need to call ITM_SendChar() to output each character to the debugger console.

    2 replies

    Tesla DeLorean
    Guru
    July 9, 2019

    Guess you need to make a decision about polling or interrupting, and then use one consistent method. The HAL examples might provide something useful, I don't use CubeMX

    Is the problem with the value you are reading, or how it displays?

    If you set value=1234 do you get "1234" on the screen? Might help you focus on where the problem is.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    idrissmc
    idrissmcAuthor
    Associate III
    July 9, 2019

    Yes yes Clive Two.Zero, I tried the basic method so I declared an int =12 then declared a char and it displays “12�?, but when I use the ADCs function it’s shows 0 all time, and when I put the potentiometer to the critic value (0K) the LCD Goes out( here I think I’ve done a short circuit is this right?)

    Bob S
    Super User
    July 9, 2019

    As @Community member​ said - you are mixing interrupt and polling functions. I suggest changing HAL_ADC_Start_IT() to HAL_ADC_Start(). Then you can use your existing HAL_ADC_PollForConversion() call to determine when the conversion is done. BUT.... please check the return status from HAL_ADC_PollForConversion(), and for that matter, HAL_ADC_Start() as well.

    Then, you should be able to see if you are getting expected data from the ADC. If not, then you need to debug either your hardware or MC_ADC_Init() code. See the examples in your Cube library directory tree (STM32Cube_FW_XXXX\Projects). There may not be any ADC examples for your exact board, but there should be some for another DISCO or Nucleo board.

    idrissmc
    idrissmcAuthor
    Associate III
    July 9, 2019

    Ok @Bob S​  but how can I check the status from HAL_ADC_PollForConvertion()? According to the datasheet of HAL & LL Drivers it returns a status but how can I do it?

    and what’s MC_ADC_Init().. :( I know only HAL_ADC_...() or MX_ADC_Init()

    Bob S
    Super User
    July 9, 2019

    Sorry, MC_ADC_Init() was a typo on my part - should have been MX_ADC_Init().

    As for checking the return value - The HAL functions return a status, such as HAL_OK, HAL_ERROR, HAL_TIMEOUT, etc. Just like HAL_ADC_GetValue() returns the ADC reading. Test that return value to see if it is HAL_OK. If not, you got some kind of error.