cancel
Showing results for 
Search instead for 
Did you mean: 

UART

bhavesh
Associate II
Posted on April 02, 2016 at 12:40

Hi,

I am facing some weird problem in UART.

Whenever i am using UART in polling to receive the data followed by storing the data into some array.

But what is happening is that the array is sometimes(mostly) starts to fill from some random index that is sometimes it start to fill the data from array index 5 or sometimes 6 and so on. It does not fill the array from the starting indices of the array that is from index 0.

My code is all right, checked many times but couldn't resolve the issue.

Please help!

#uart #stm32 #uart #standard-peripheral
4 REPLIES 4
pkumar1883
Associate II
Posted on April 02, 2016 at 13:52

Dear moradiya.bhavesh,

What are the values filled at initial indexes of array. Are these similar every time or different.

Are you taking care of Array overflow?Could you share your polling code?

 

/*Please

 mark helpfull

 if this post helps you or solves your problem.*/

/* If you need any personal support for your work please contact at 

embeddeddesign.help@gmail.com*/

Posted on April 02, 2016 at 15:01

The microcontroller has evaluated your code and disagrees. Show enough of the salient code so it can be evaluated here.

What tests have you done to prove two way communication with the usart is working properly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bhavesh
Associate II
Posted on April 05, 2016 at 09:17

Hello,

Thanks for your time.

Actually when I am receiving data from serial terminal using USART receive function & data is captured in an array, then first few location were getting skipped & then I am able to receive the data.

Secondly, when data is received then first byte of data from serial terminal was lost using USART receive function.

NOTE: Complete data is important for me because I am performing OTA update or you can say IAP to reprogram the flash memory from GPRS.

j = 0;

for (int p = 0; p<=1024; p++)

{

  while(1)

  {

      while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);

      data_receive2[j]= USART_ReceiveData(USART2);

      if(j == 1024)

      {

        j = 0;

        break;

      }

      j++;

      //if (j != 1024)

      //break;   

   }

}

can i use pointer instead of array ?

if yes, then how pointer can be beneficial for directly copying data into flash memory?

Please suggest some suitable solution to resolve this issue.

Posted on April 05, 2016 at 18:44

You increment j in the wrong spot, causing blocks of 1025 bytes to overflow a 1024 buffer. And will cause the data to appear to precess from block to block.

You just seem to be pulling a stream of 1MB of data, I think you need to packetize and manage it in some manner, especially if you are considering writing to flash, as this stalls the processor and will result in data loss, unless you have some form of flow control.

Coding solutions is beyond the scope of my participation here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..