Problem Receiving Data In ATMEGA328p USART

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Everyone

Thanks to them who are reading this. I need Help .

 

Am Using an Arduino Nano board as a breakout . I have cleaned the Chip using USb ASP and using ISP to programme it now.

 

Am making a code for serial TX and Rx . Am successful with Serial Receive in Serial Monitor XCTU.  But Transmission from my laptop is not possible . Please Help

 

#include<avr/io.h>

#define F_CPU 16000000UL
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU/(USART_BAUDRATE*16UL)))-1)

void USART_Transmit( unsigned char data )
{
	/* Wait for empty transmit buffer */
	while ( !( UCSR0A & (1<<UDRE0)) )
	;
	/* Put data into buffer, sends the data */
	UDR0 = data;
}
unsigned char USART_Receive( void )
{
	/* Wait for data to be received */
	while ( !(UCSR0A & (1<<RXC0)) )
	;
	/* Get and return received data from buffer */
	return UDR0;
}

int main(void)
{
	char recieved_byte;
	
	UBRR0H = (unsigned char)(BAUD_PRESCALE>>8);
	UBRR0L = (unsigned char)BAUD_PRESCALE;
	
	UCSR0B |= (1<<RXEN0)  | (1<<TXEN0);
	UCSR0C |= (1<<UCSZ00) | (1<<UCSZ01);
	
	for(;;)
	{
		USART_Transmit('T');
		// wait until a byte is ready to read
		recieved_byte=USART_Receive();
		USART_Transmit(recieved_byte);
	}
	return 0;   /* never reached */
}

Am recieving the T once and the code Hangs ... After that nothing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your code looks fine to me.
Some terminals send a character as soon as you type it. You should see every char being echoed back to you (with an extra T)
Other terminals only send when you press the Enter key.
Why did you destroy the Nano Bootloader?
It is much easier than an external USBASP. You have now got two USB tied up plus an extra ribbon cable when the Nano works with a single USB.

David.

Last Edited: Sun. Apr 10, 2016 - 07:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Your code looks fine to me.
Some terminals send a character as soon as you type it. You should see every char being echoed back to you (with an extra T)
Other terminals only send when you press the Enter key.

 

The software in post#1 works fine.

I had a Nano sitting here and tried his code using both HyperTerminal and TeraTerm - it works with both.