i am working on project with ATMEGA8 and Bluetooth module HC-05 . I want to send char ‘a’ to the Bluetooth module and then make PORTB in the micro controller high but it never gets high, i tasted the bluetooth module and the program that sends the char on arduino and it worked fine but it is not working with the micro controller. any help please?
the micro controller code:
#include <stdint.h>
#include <avr/io.h>
//#include <util/delay.h>
// Define baud rate
#define F_CPU 8000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
void USART_vInit(void)
{
// Set baud rate
UBRRH = (uint8_t)(51>>8);
UBRRL = (uint8_t)51;
// Set frame format to 8 data bits, no parity, 1 stop bit
UCSRC = (0<<USBS)|(3<<UCSZ0);
// Enable receiver and transmitter
UCSRB = (1<<RXEN)|(1<<TXEN);
}
uint8_t USART_vReceiveByte()
{
// Wait until a byte has been received
while((UCSRA&(1<<RXC)) == 0);
// Return received data
return UDR;
}
int main(void)
{
DDRB = 0xFF ;
uint8_t u8Data;
// Initialize USART
USART_vInit();
// Repeat indefinitely
for(; //forever
{
// Echo received characters
u8Data = USART_vReceiveByte();
switch (u8Data) { // decode what char just came in
case ‘a’ :
PORTB =0xff;
break;
case ‘b’ :
PORTB =0x00;
break;
}
}
}