Roomba Tank
CSC 460 Project 3
uart.c
Go to the documentation of this file.
1 #define F_CPU 16000000
2 #include <util/delay.h>
3 #include "uart.h"
4 #include <string.h>
5 #include <avr/io.h>
6 
11  // Set baud rate to 19.2k
12  UBRR3 = 0x33;
13 
14  // Enable receiver, transmitter
15  UCSR3B = (1<<RXEN3) | (1<<TXEN3);
16 
17  // 8-bit data
18  UCSR3C = ((1<<UCSZ31)|(1<<UCSZ30));
19 
20  // disable 2x speed
21  UCSR3A &= ~(1<<U2X3);
22 }
23 
27 void Roomba_Send_Byte(uint8_t data_out){
28  // Wait for empty transmit buffer
29  while(!( UCSR3A & (1<<UDRE3)));
30  // Put data into buffer
31  UDR3 = data_out;
32 }
33 
37 unsigned char Roomba_Receive_Byte(){
38  // Wait for data to be received
39  while(!( UCSR3A & (1<<RXC3)));
40  // Get and return data from buffer
41  return UDR3;
42 }
43 
47 void Roomba_Send_String(char *string_out){
48  for(; *string_out; string_out++){
49  Roomba_Send_Byte(*string_out);
50  }
51 }
52 
57  // Set baud rate to 19.2k
58  UBRR1 = 103;
59 
60  // Enable receiver, transmitter
61  UCSR1B = (1<<RXEN1) | (1<<TXEN1);
62 
63  // 8-bit data
64  UCSR1C = ((1<<UCSZ11)|(1<<UCSZ10));
65 
66  // disable 2x speed
67  UCSR1A &= ~(1<<U2X1);
68 }
69 
73 void Bluetooth_Send_Byte(uint8_t data_out){
74  // Wait for empty transmit buffer
75  while(!( UCSR1A & (1<<UDRE1)));
76  // Put data into buffer
77  UDR1 = data_out;
78 }
79 
83 unsigned char Bluetooth_Receive_Byte(){
84  // Wait for data to be received
85  while(!( UCSR1A & (1<<RXC1)));
86  // Get and return data from buffer
87  return UDR1;
88 }
89 
93 void Bluetooth_Send_String(char *string_out){
94  for(; *string_out; string_out++){
95  _delay_ms(10);
96  Bluetooth_Send_Byte(*string_out);
97  }
98 }
void Bluetooth_Send_String(char *string_out)
Definition: uart.c:93
void Roomba_UART_Init()
Definition: uart.c:10
void Bluetooth_Send_Byte(uint8_t data_out)
Definition: uart.c:73
unsigned char Bluetooth_Receive_Byte()
Definition: uart.c:83
unsigned char Roomba_Receive_Byte()
Definition: uart.c:37
void Bluetooth_UART_Init()
Definition: uart.c:56
void Roomba_Send_String(char *string_out)
Definition: uart.c:47
void Roomba_Send_Byte(uint8_t data_out)
Definition: uart.c:27