Sign In

Trouble In Sending Strings Via Usart To Avr

muhammed zafran mohdzfn94@gmail.com India

Hardware: Atmega 8 Running On 16 Mhz Software: C Project Atmel Studio 6

i need to recieve strings from the usart to the avr .the strings are bieng sent to atmega 8 usart via esp 8266 module.the characters needs to be recieved in strings and store it in an array .whenever a special character like $ is encountered the reception is stopped and characters needs to be written into the string .

i googled a lot for one week and didnt get the code to store characters into string array.i just need the strings to be stored in an array when .later the array can passed to a function for display.
PLEASE HELP ME ..!!

Images

Program





#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>

void USARTInit(uint16_t ubrr_value)
{

   
   UBRRL = ubrr_value;
   UBRRH = (ubrr_value>>8);

  
   UCSRC=(1<<URSEL)|(3<<UCSZ0);

      UCSRB=(1<<RXEN)

char USARTReadChar()
{
  
   while(!(UCSRA & (1<<RXC)))
   {
      //Do nothing
   }

   
   return UDR;
}



void USARTWriteChar(char data)
{
   

   while(!(UCSRA & (1<<UDRE)))
   {
      //Do nothing
   }

 
   UDR=data;
}

int main()
{
  
   char data;

   

   UBRR value = 51

   
   USARTInit(51);    //UBRR = 51

   

   while(1)
   {
      //Read data
      data=USARTReadChar();
	  _delay_ms(50000);  

         
      USARTWriteChar(data);
   
   }
}

Replies

R Avinash Gupta
2017-03-27 05:18:47
The program that you have posted, you are NOT storing in string any data that is received from USART.

Post a reply to muhammed zafran

Think you can help muhammed zafran ? Then post your thoughts that might help muhammed zafran. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.