Android to RN-42 + ATmega328

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

This is one of those questions that is hard (at least for me) to research simply due to phrasing the question correctly.

I am working on a project for school that uses, among a multitude of other modules, an RN-42 Bluetooth module and an ATmega328. I am currently trying to send a string from the Android to the AVR system, however I can only receive about 3 bytes before the transmission seems to die. So, far me and one of my teammates have narrowed down the possibilities to one main theme, the Android/Bluetooth combo is trying to give the information to the microcontroller much too quickly.

Right now, the PCB I designed has RTS and CTS tied together and it works just fine for BlueTerm in the Android to send bytes, one by one, to the ATmega, and for sending strings from the ATmega to the Android device. I can also successfully sent a string from the Android app that our group created to a computer and the entire string is printed in the terminal. However, when I send a string longer than 3 bytes from the Android app to my ATmega, something happens that only three characters are added to the string (I'm picturing my ATmega drowning in a kiddie pool at this point). I should probably note that the Android is sending the information in ASCII.

I think handshaking is where the problem lies, but I really don't want to have to implement a fix for CTS and RTS since the end of the semester is coming up pretty quickly. My hope is that I might be doing something wrong within my code to receive this full string.

ISR(USART_RX_vect)
{
	/* Wait for data to be received */
	/* Get and return received data from buffer 
	
	uint8_t i = 0;
	unsigned char received = 0;
	while ( !(UCSR0A & (1<<RXC0)) );
	received = UDR0;
	while(received != ';')
	{
		if( received != 10)
		{
			command[i] = received;			
			i++;
			while ( !(UCSR0A & (1<<RXC0)) );
			received = UDR0;
		}
	}
	command[i] = '\0';
	print(command);
} 

PS Some may be wondering why it's all in an interrupt service routine. This is simply due to the issue that I'm having and I wanted to try and run this as fast as possible, with nothing else happening.

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

You took enough time to write this rather long post and didn't find time to try to write your code properly even though you know that it's broken by design. That's funny.

Normally you put your incoming chars to a ring buffer in the ISR and read them as they come in your normal code. Try doing that first.

What happens if you send 3 3-character-long strings from your android app? Do you receive them fine? Do they get chopped? Or everything is stuck after the first one? What if you try sending a text file from the PC? What if you send commands char by char with pace?

The Dark Boxes are coming.