0
\$\begingroup\$

I have an ATtiny AVR imicrocontroller connected to HC-05 bluetooth module via USART(TX and RX) of the microcontroller. The microcontroller is sending constant data (for right now) to the bluetooth module, which I am viewing as serial data using python.

The problem is that i am seeing all data as '\xff' ,or '\xfd' or ... i.e. the MSB is always f. I don't see a reason why this should happen. Somebody please help!

This is my code :

void USART_initialize(int baud_value) {

//int baud_rate = (unsigned int)(((16000000)/(16*baud_value))-1);
UCSRC = ~(1<<UMSEL);                        // MODE OF COMMUNICATION 
UBRRH = (unsigned char)(25 >> 8);   // SETTING BAUD
UBRRL = (unsigned char)(25);        // RATE

UCSRC |= (3<<UCSZ0);                         // 8-BIT DATA
UCSRC |= (1<<UPM1);                         // EVEN PARITY
UCSRC &= ~(1<<USBS);                        // 1 STOP BIT

UCSRA &= ~(1<<U2X);                        // NORMAL ASYNCHRONOUS MODE OF COMMUNICATION

UCSRB = (1<<RXEN)|(1<<TXEN);               // ENABLE RECEIVER & TRANSMITTER

} int main (void) {

DDRB = 0xFF;
DDRA = 0x00;
DDRD = 0xFF;
int8_t data;

USART_initialize(9600);
while(1) {

    while(!(UCSRA & (1<< UDRE)));
    UDR = ('0b00000001');
    data = '\n';

}

return(0);

}

\$\endgroup\$
  • \$\begingroup\$ Are you sure that the value of 25 you're loading into your baud rate divisor register is correct for the rate you're aiming for? \$\endgroup\$ – brhans Mar 26 '15 at 15:53
1
\$\begingroup\$

Possibility 1

Your avr-to-bluetooth connection does not have flow control and receiving side does not verify the stop bit.

There should be a compounding problem of wrong baud rate or just broken transmission.

In this case you'll see bursts of broken data when you expect data and nothing otherwise.

Possibility 2

You are missing a pull-up or pull-down (depending on ttl/rs232 signal), thus every little bit of noise triggers reception of a character.

If this is the case, you will receive a lot more data than you expect, in fact you'll probably receive continuous stream of data. Check number of characters received per second against baud rate / 10 (start, 8 data, stop)

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ i modified the code to send only one byte per second but then too i get a lot more data. What could be the problem ? Do i have to use a pullup/ pulldown resistor at the TX/RX pins ? \$\endgroup\$ – ironstein Mar 19 '15 at 9:16
  • \$\begingroup\$ You would need a pull-up at the logic input (i.e. RS-232 idles at Mark which is logic high.) \$\endgroup\$ – sawdust Mar 19 '15 at 10:05
  • \$\begingroup\$ @sawdust i connected a pullup resistor of 1.2K to the RX of the bluetooth module but to no use. Still reading senseless data. Please help ! \$\endgroup\$ – ironstein Mar 19 '15 at 10:30
  • \$\begingroup\$ do i have to do any initialization before using the bluetooth module (HC-05) or is it simply plug and play ? \$\endgroup\$ – ironstein Mar 19 '15 at 11:33
  • \$\begingroup\$ I used a similar HC-something module and though you don't need to initialise it explicitly every time, these is a protocol to configure it the first time, in particular the bauds rate. Check the datasheet for that. \$\endgroup\$ – Damien Aug 23 '15 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.