Android to RN-42 + ATmega328

This is one of those questions that is hard (at least for me) to research simply due to phrasing the question correctly. This is also more of a USART/UART question, rather than strictly RF.

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. However, when I attempt to receive information from an app that has pre-built strings, only the first three bytes appear. From the android app to a computer, the output is read just fine. 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 a string from the module.

Here is my interrupt-driven receive code (the print function is a self-baked output to bluetooth).

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);
}

Hi iamchris,

I have been having similar problems with the RN-42. I am using a Parallax Propeller to send/receive data to the RN-42, but it seems like the Propeller is sending data too quickly. This is surprising as 115200 baud isnt super fast by todays standards. Anyway, I see parts of my data come across OK, but too many bytes sent too quickly will result in not all of it getting there. I made some of my own serial routines that slow down the data sent and it seems to work OK.

I’m not sure if this is an interrupt issue or a small buffer on the RN-42, but it is a little frustrating working with the module. Looking around online, I think I saw that the module has a 512 byte buffer, and I am not sending anywhere near that amount of data before it stops sending properly. Both the send and receive buffers seem to have problems with data speed. Are you experiencing these problems too?

As I remember there is a pin on the RN-42 when it is left low is 115K and high is 9600 baud. Why don’t you slow the speed down. Once you get that working start bumping the speed up.