2023-01-28 10:10 AM
I have the array of character strings that I am trying to printout to Real Term using a Nucleo -F072. The code compiles with no warnings or errors, yet every time I run this it jumps into the HardFault_Handler....Can someone please tell me what am I doing incorrectly??? My lack of knowledge on pointers and casting is somehow the cause.......
char t[][4] = {"1234", "3455", "1121", "0032", "0621"};
for (k = 0; k < NO_ADC_CH; k++)
{
//test = hex2Ascii(stream + k);
HAL_UART_Transmit_IT(&huart2, (uint8_t*)(&test[k]), sizeof(test[k]));
//HAL_Delay(1);
while(!ISR.UART_TxComplete);
ISR.UART_TxComplete = F;
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
ISR.UART_TxComplete = T;
}
Solved! Go to Solution.
2023-01-28 10:59 AM
Are test and t the same thing?
Strings tend to NUL terminate so at least a 5 x 5 array there.
What's actually Faulting here?
The sizeof(test[k]) is a bit awkward in this context, but probably Ok
ISR.UART_TxComplete needs to be volatile
Try something like
int k;
for (k = 0; k < 10; k++)
{
static char string[8];
ISR.UART_TxComplete = F;
HAL_UART_Transmit_IT(&huart2, (uint8_t*)string, sprintf(string, "%04X\n", k));
while(!ISR.UART_TxComplete);
}
2023-01-28 10:54 AM
what is : NO_ADC_CH ? and : test[] ? only t[] shown.
and use xx-transmit without INT , because you wait anyway for finish.
2023-01-28 10:55 AM
How about looking at brisk sif.c code which works on STM32C0 and manage usart by interrupt to send adc data to teraterm and bluetooth electronics android app? Here
2023-01-28 10:59 AM
Are test and t the same thing?
Strings tend to NUL terminate so at least a 5 x 5 array there.
What's actually Faulting here?
The sizeof(test[k]) is a bit awkward in this context, but probably Ok
ISR.UART_TxComplete needs to be volatile
Try something like
int k;
for (k = 0; k < 10; k++)
{
static char string[8];
ISR.UART_TxComplete = F;
HAL_UART_Transmit_IT(&huart2, (uint8_t*)string, sprintf(string, "%04X\n", k));
while(!ISR.UART_TxComplete);
}
2023-01-28 11:20 AM
Wow!!! That works great...would have never thought of the sprintf thing....
I apologize for above as test should have been t....
Anyway I substituted k with analog data in your line 6 and added \r and now it seems to work fine....I will do some more testing just to convince myself but .....
thank you everyone for the help!!
2023-01-28 04:43 PM
> I substituted k with analog data in your line 6
I can already see in my mind how the sprintf() writes past the buffer... Instead it is higly recommended to use snprintf() and check it's return value.