29.08.2013 Views

Autonom robotväckarklocka med trådlös basstation - KTH

Autonom robotväckarklocka med trådlös basstation - KTH

Autonom robotväckarklocka med trådlös basstation - KTH

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

------------------------------------------------------------<br />

// Bluetooth/USART<br />

//------------------------------------------------------------<br />

// USART Example Application<br />

// Johan Egneblad<br />

// 2010-03-02<br />

// modified for MJAAO-project 2011<br />

#define F_CPU 8000000 // Define the processor clock frequency<br />

#define BAUD 9138 // The baud rate (bits per second) of the communication<br />

#define BAUD_REG F_CPU/16/BAUD-1 // The settings for the usart register<br />

#define BUFFER_SIZE 32 // Maximum message length<br />

#include "transmitter.h"<br />

// Global variables for RX buffering<br />

volatile char rx_buffer[BUFFER_SIZE]; // A text buffer for incoming text<br />

volatile unsigned char rx_recieved_bytes; // A byte counter for the incomming<br />

text<br />

volatile unsigned char rx_eol; // An "end of line" indicator that is set to<br />

one ones a full line is read<br />

// Interrupt vector for USART Recieve Complete<br />

ISR(USART0_RX_vect) {<br />

unsigned char data;<br />

// Read the USART buffer<br />

data = UDR0;<br />

// Check if the old msg has been read (rx_eol should be cleared)<br />

/*if (rx_eol == 0) {<br />

rx_buffer[rx_recieved_bytes] = data;<br />

rx_recieved_bytes++;<br />

// If there is a line break or null character<br />

if (data==0x0d || data==0x0a || data==0x00 || rx_recieved_bytes >=<br />

(BUFFER_SIZE-1)) {<br />

rx_eol = 1; // Tell the end of line is reached<br />

rx_buffer[rx_recieved_bytes] = 0; // Terminate the string correctly<br />

rx_recieved_bytes = 0; // Clear the received bytes counter<br />

}<br />

}*/<br />

//dataRecieved((unsigned char)data);<br />

}<br />

// Initialization function for usart<br />

// inputs:<br />

// ubrr - (unsigned int) the future contents of the UBRR register<br />

void usart_init(unsigned int ubrr) {<br />

// Set the communication speed register UBRR<br />

UBRR0H = (unsigned char)(ubrr>>8); // the most significant byte<br />

UBRR0L = (unsigned char)ubrr; // the least significant byte

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!