Troubleshoot simple IR Xfer on Atmega328

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

Sorry to ask for help troubleshooting, but this is a very short bit of code.

I followed the instructions for http://tthheessiiss.wordpress.com/2009/08/05/dirt-cheap-wireless/, a very small Arduino project, and had success, but when I try to replicate it in c, my transmission drops a LOT of bytes, and after hours and hours of troubleshooting, I can't find my error. Can anyone spot it?

I didn't change the recieving arduino; it is still programmed as an Arduino, using the code given on the 'dirt cheap wireless' blog post.

Here's my code:

#include 
#define F_CPU = 16000000

char text[] = "testing\n";
int i = 0;

/* Write a character to USART */
void usartOut(char data)
{
	// Wait until the transmitter is ready
  while ( !(UCSR0A & (1<<UDRE0)) )
  	;
  // Now write the data to USART buffer
  UDR0 = data;
}

int main(void)
{
	/*set up carrier wave*/
	DDRB |= (1 << PB1);
	TCCR1B |= (1 << WGM12);
	TCCR1A |= (1 << COM1A0);
	TCCR1B |= (1 << CS10);
	OCR1A = 210;// 38KHz = F_CPU / ( 2 * PRESCALER * (1 + OCR0A)

	/*set up usart*/
	UBRR0 = 416;
	UCSR0B = (1 << RXEN0) | (1 << TXEN0);
	UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);

	while (1) {
		usartOut(text[i]);
		i = (i + 1) % 8;
	}
}

I get reception like the following, but when I use the Arduino IDE and Arduino code, the message received is flawless.

testing
testing
testing
testing
testingetntsn
eigetntsn
sigetgtsn
sigetgttn
Last Edited: Fri. Oct 16, 2015 - 02:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...It appears that when I include a delay after every so many characters, the transmission is received properly. That seems a bit wasteful, though: every 8 characters, a delay of 80 milliseconds does the fix.

Can anyone explain a proper fix for this?