Author Topic: Unable to store value from UART Rx Regsiter to *Char  (Read 1098 times)

0 Members and 1 Guest are viewing this topic.

Offline Glenn0010Topic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: mt
Unable to store value from UART Rx Regsiter to *Char
« on: May 20, 2020, 01:17:38 pm »
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
Code: [Select]
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

Code: [Select]
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
« Last Edit: May 20, 2020, 01:19:11 pm by Glenn0010 »
 

Offline greenpossum

  • Frequent Contributor
  • **
  • Posts: 408
  • Country: au
Re: Unable to store value from UART Rx Regsiter to *Char
« Reply #1 on: May 20, 2020, 01:39:02 pm »
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.
 

Offline Glenn0010Topic starter

  • Regular Contributor
  • *
  • Posts: 225
  • Country: mt
Re: Unable to store value from UART Rx Regsiter to *Char
« Reply #2 on: May 20, 2020, 02:00:22 pm »
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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf