# avr python serial communication all data \xff

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


}

• 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? – brhans Mar 26 '15 at 15:53

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)

• 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 ? – ironstein Mar 19 '15 at 9:16
• You would need a pull-up at the logic input (i.e. RS-232 idles at Mark which is logic high.) – sawdust Mar 19 '15 at 10:05
• @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 ! – ironstein Mar 19 '15 at 10:30
• do i have to do any initialization before using the bluetooth module (HC-05) or is it simply plug and play ? – ironstein Mar 19 '15 at 11:33
• 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. – Damien Aug 23 '15 at 7:27