2024-04-03 01:18 AM
Hello,
I am currently using a Nucleo F446RE board and i am facing problem while trying to read an analog pin using ADC functions. When i start running or debugging the project, i immediately fall down into Hardfault_handler function. I don't know what i exactly did wrong, and don't know how to figure it out...
Thanks in advance for help!
Please find attached the main file i wrote.
2024-04-03 01:23 AM
Hello,
At a first glance you declared this table with one element:
uint16_t uiADCRawValueBuffer[1];
Then you access two elements.
uint16_t uiADCRawValueBuffer[1];
for (int var = 0; var < 2; ++var) {
uiADCRawValueBuffer[var] = HAL_ADC_GetValue(&hadc1); // Store converted values
}
buffer_throttle = uiADCRawValueBuffer[0];
buffer_brake = uiADCRawValueBuffer[1];
Please check.
2024-04-03 01:49 AM
2024-04-03 01:59 AM - edited 2024-04-03 04:54 AM
Not obvious to find the problem with the info you provide.
This kind of issue needs a debug. So go step by step and find at which step you get the hardfault.
You can comment out the code and uncomment line by line and find at which level the hardfault occurs.
2024-04-03 05:25 AM
Yes, i did what you told me and i found out that the debug mode starts not working anymore as soon as i uncomment the MX_CAN_Init();
What a joke! since i was able to send CAN frames a few days ago using the same config :(
2024-04-03 10:04 AM
> What a joke!
Jeeze, really?
Sigh... as with all "fault handler" issues, the answer is to look at the fault registers and figure out what caused the fault. There are many (MANY) posts on this forum describing how to do that. CubeIDE even has a built-in fault analyzer.
Typically when the issue moves around like this, you either have a stack issue or uninitialized/null pointer dereference. The fault registers will help you figure out where.