Hi All,
So I've been succesfully reading data from UART RX Register and toring it to an array of characvters. However, I'd like to do the same with a pointer and the code is not working properly. I'm sure I've done something wrong as I am rusty with my programming skills.
So here I have my UART interrupt handler
void USART2_IRQHandler(void)
{
if(USART2->ISR & USART_ISR_RXNE)
{
//Puts the value from the receive register to the string by checking the length of the array and incrementing it by that length
*(Serial_Data_Array_Received + strlen(Serial_Data_Array_Received)) = USART2->RDR;
int x = 1;
}
}
and here is how I am declaring my variable
char* Serial_Data_Array_Received;
When I run it on the debugger, the code goes to a Hard fault routine in assambly language.
I'm not sure what I'm doing wrong
I am using C99 and an STM32 uC
Cheers
Firstly have you initialised the pointer to point to a buffer where the characters are stored? Secondly, you should not be using strlen to find where the end of the valid characters are, because the NUL character is a valid character in serial transmission. You'll need to keep track how much of your buffer has been used separately.
Hey thanks for the response! I've just realized what you said after refreshing my memory on pointers! It's all sorted now! Thanks for your help