ATmega2560 String Transmit

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#ifndef F_CPU
#define F_CPU 16000000UL // 16Mhz clock speed
#endif
#include <avr/io.h>
#include <util/delay.h>
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) -1)

void USART_Init( unsigned int baud )
{
	/* Set baud rate */
	UBRR2H = (unsigned char)(baud>>8);
	UBRR2L = (unsigned char)baud;
	/* Enable receiver and transmitter */
	UCSR2B = (1<<RXEN2)|(1<<TXEN2);
	/* Set frame format: 8data, 2stop bit */
	UCSR2C = (1<<USBS2)|(3<<UCSZ20);
}
unsigned char USART_Receive( void )
{
	/* Wait for data to be received */
	while ( !(UCSR2A & (1<<RXC2)) )
	;
	/* Get and return received data from buffer */
	return UDR2;
}
void USART_Transmit( unsigned char data )
{
	/* Wait for empty transmit buffer */
	while ( !( UCSR2A & (1<<UDRE2)) )
	;
	/* Put data into buffer, sends the data */
	UDR2 = data;
}
void UART_sendstring(char *str)
{
	unsigned char j=0;
	while(str[j]!=0)     // send string till null.
	{
		USART_Transmit(str[j]);
		j++;
	}
}

int main()
{
	
	USART_Init(103);
	//UART_sendstring("HELLO");
			

	while(1)
	{
 		USART_Transmit('A');
 		_delay_ms(1000);
	}
}

hello sir i am trying to transmit a string with my atmega2560. A single character transmitting works fine but when i am trying to transmit a string with my UART_sendstring function it is transmitting garbage value not only for one time, it keeps transmitting the same garbage values. i have attached a file what i am getting in my terminal.

Attachment(s): 

Rjchoudhary

Last Edited: Sat. May 30, 2020 - 09:02 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why are you starting another round about uarts sending/receiving strings?  Wasn't it already covered?
 

At a minimum, have you ensured you have the proper,accurate frequency?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Topic locked