atmega8 + HC-05

Thread Starter

devjeetmandal

Joined May 7, 2017
48
hello everyone..
i was trying to interface HC-05 bluetooth module with atmega8. F_CPU=1MHz and baud rate for communication is 9600. i have a led at PORTB pin 0 and i will use any bluetooth app from play store to turn the led on or off.

usart.h
Code:
void usart_init(uint16_t ubrr_value)
{
UBRRL = ubrr_value;
UBRRH = (ubrr_value>>8);
UCSRB|= (1<<RXEN)|(1<<TXEN);
UCSRC |= (1 << URSEL)|(3<<UCSZ0);
}


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


hc-05.h
Code:
char hc_05_bluetooth_receive_byte(void)
{
return usart_data_receive();
}

main.c
Code:
int main(void)
{
DDRB=0x01;
char received_data;
usart_init(6);
while(1)
{
received_data=hc_05_bluetooth_receive_byte();
if(received_data == '1')
{
PORTB=0x01;
}
else if(received_data == '2')
{
PORTB=0x00;
}
else
{

}
}
}
Moderator edit: inserted code tags



any guess why its not working?
 

MrChips

Joined Oct 2, 2009
30,621
I can see lots wrong.
  1. You didn't turn on the power.
  2. Your bluetooth app is not working.
  3. Your bluetooth app is not sending '1' nor '2'.
  4. Your baud is wrong.
  5. Your protocol is wrong.
  6. Your code is wrong.
 

Thread Starter

devjeetmandal

Joined May 7, 2017
48
I can see lots wrong.
  1. You didn't turn on the power.
  2. Your bluetooth app is not working.
  3. Your bluetooth app is not sending '1' nor '2'.
  4. Your baud is wrong.
  5. Your protocol is wrong.
  6. Your code is wrong.

1. power is turned on
2. with the help of app i can connect to HC-05 i cn tell it by the way HC-05 led blinks. it blinks with some delay
3. from app i m sending 1 and 2 but nothing is recieved by HC-05
4. there are several website which says 9600 is communication baud and 384000 for at mode. i also tried other baud but same as above.
5-6. please correct me where m going wrong.

thank you
 

spinnaker

Joined Oct 29, 2009
7,830
What have you done to troubleshoot the issue? Do you have a scope or logic analyzer that you can see if you are getting data from the HC05?
 
Top