2019-07-09 10:36 AM
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
Solved! Go to Solution.
2019-07-10 11:10 AM
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.
2019-07-09 11:11 AM
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.
2019-07-09 11:41 AM
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?)
2019-07-09 12:30 PM
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.
2019-07-09 12:43 PM
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()
2019-07-09 01:36 PM
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.
2019-07-09 10:07 PM
@Bob S with this code I have a problem, it said undefined statement (Error_Handler())
2019-07-10 09:45 AM
Do you have a function called Error_Handler() defined somewhere? The CubeMX/HAL code provides a function called _Error_Handler (note the leading underscore), but unless you have added code to it, that function is useless.
You would be better off storing the return value in a local variable so that you can print it so some debug device (UART, LCD, something) and/or look at it in the debugger. So you code would be something like this:
HAL_StatusTypeDef sts;
sts = HAL_ADC_Start(&hadc1);
if ( sts == HAL_OK ) {
sts = HAL_ADC_PollForConversion(&hadc1, 100);
if ( sts == HAL_OK ) {
value = HAL_ADC_GetValue(&hadc1);
itoa(value, getvalue, 10);
}
else { // Error from "poll for conversion"
// This may be HAL_TIMEOUT, or some other error
// Generate some error message here
}
}
else { // Error from HAL_ADC_Start()
// Display an error message somehow
}
Of course, compiler optimization may make the "sts" variable disappear from the debugger's standpoint (i.e. "gets optimized out").
EDIT: And if you don't get any errors from the HAL functions, then you need to go back and look at the actual ADC and GPIO configuration registers to make sure they are configured as you intend.
2019-07-10 10:21 AM
That’s great @Bob S ! Is getvalue a char*?
I have one more question please! I want to print on the CubeIDE a message like we do with C/C++, python, Java... I mean on the console! How can I do it with CubeIDE
2019-07-10 11:10 AM
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.