Sign In

My Trouble Is That My Atmega16 Can't Receive From Android App Using Hc-05 Blutooth Module

Amr Mostafa amr.joby@gmail.com

Hardware: Atmega16 , 16MHZ Ext Crystal , 9600 Baud Rate , No Parityy , 1 Stop Bit , 8 Bits Character Software: C Project Using Atmel Studio 6

I'm working since a week on a project where I transmit a character from an android Mobile App (such as Bluetooth terminal) , and receive this data through hc-05 bluetooth module to the atmega16 uart .
when I transmit a character or string from atmega16 to android , it works fine but when reverse as I send a character from android , I i can't receive any thing on atmega16,, so from that i'm sure all my connections and wires are right , but i don't understand how to receive data form android , this is the point.

so I would appreciate if you could help me solve this problems with instructions or code to receive from android.

note : I've read that android send data as string ,not as character ,, so maybe this is the problem as I'm receiving data as character not string.

Images

Program

here is the function I made to receive character data from android :

unsigned char uart_data_receive()
{
	while ( !( UCSRA & (1<<RXC) ) );
		return UDR;
}

how can I use it to actually receive string data or what ever android data form , from android ??

thanks for being patient and help

Replies

R Avinash
2016-07-11 12:43:26
Post complete program. It is not clear where you are calling this function.
R Amr Mostafa
2016-07-11 13:14:56
ok , anyway I call it as a function that return a character , and then use this character as my received data from android
//this code for receiving data from android using hc-05 bluetooth module
// data received is checked by switch case statement , then select a led to toggle based on the data received
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
//******************* UART functions ***********************************************************

void uart_init()
{
	//asynchronous serial communication settings
	unsigned int UBRR_value = 103;						//9600 Baud Rate
	UBRRL = (unsigned char)(UBRR_value);
	UBRRH = (unsigned char)(UBRR_value>>8);
	UCSRB |= (1<<TXEN)|(1<<RXEN);						//enable trans & receive
	UCSRC |=(3<<UCSZ0)|(1<<URSEL);						//enable 8bit character size & 1 stop bit
}
void uart_data_transmit(unsigned char d)
{
	while ( !( UCSRA & (1<<UDRE) ) );
		UDR = d;
}
unsigned char uart_data_receive()
{
	while ( !( UCSRA & (1<<RXC) ) );
		return UDR;
}

int main(void)
{
	_delay_ms(1000);
	//UART initialization
	uart_init();
	DDRA = 0xff;	//set port A as output
	unsigned char data;
	while (1)
	{	
		data = uart_data_receive();
		//data received is checked and then toggle a led choosed based on data received
		switch (data)
		{
			case 'a':	{ PORTA ^=1<<PINA0;}
			break;
			case 'b':	{ PORTA ^=1<<PINA1;}
			break;
			case 'c':	{ PORTA ^=1<<PINA2;}
			break;
			case 'd':	{ PORTA ^=1<<PINA3;}
			break;
			case 'e':	{ PORTA ^=1<<PINA4;}
			break;
			default:	PORTA = 0x00;
		}
	}
}
R Avinash Gupta
2016-07-12 06:15:26
Few things I can suggest you to troubleshoot the situation

Connect the output of Bluetooth module to any USB to Serial Converter and then to PC. And on PC end using some terminal software (like Realterm) check if any data is being received or not.

R Avinash Gupta
2016-07-13 05:29:23
we are waiting for your response ...
R Amr Mostafa
2016-07-14 18:10:48
excuse me for being late ,, but i finally solved the problem and I think it was about the crystal and the using of decimal instead of ascii to receive the data , then I transfer it to ascii or hex..
So, thank you anyway and if I've such kind of issue,I'll try your suggestion ..
Amr

Post a reply to Amr Mostafa

Think you can help Amr Mostafa ? Then post your thoughts that might help Amr Mostafa. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.