Files
@ be853f009bb8
Branch filter:
Location: seniordesign-firmware/master/master/lib/serial.c
be853f009bb8
3.0 KiB
text/plain
Started new infrastructure for requesting slave data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | /*
* Master Firmware: USART Send/Recieve
*
* Wireless Observational Modular Aerial Network
*
* Ethan Zonca
* Matthew Kanning
* Kyle Ripperger
* Matthew Kroening
*
*/
#include "serial.h"
#include "led.h"
#include "../config.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
// NOTE: USART ISRs for character reception are included in serparser.c
void serial0_setup() {
//PORTD &= ~(1<<PD0);
//PORTD |= (1<<PD1);
/* Enable receiver and transmitter */
UCSR0B |= (1<<RXEN0)|(1<<TXEN0); // Enable rx/tx
/* Set frame format: 8data, 1stop bit */
UCSR0C |= (1 << UCSZ00) | (1 << UCSZ01); // - 1 stop bit
/* Set baud rate */
UBRR0H = (unsigned char)(USART0_BAUD_PRESCALE>>8);
UBRR0L = (unsigned char)USART0_BAUD_PRESCALE;
UCSR0B |= (1 << RXCIE0); // Enable interrupt
//UCSR0A |= (1<<RXC0);
}
void serial1_setup() {
//PROVEN in test project
/* Enable receiver and transmitter */
UCSR1B |= (1<<RXEN1)|(1<<TXEN1); // Enable rx/tx
/* Set frame format: 8data, 1stop bit */
UCSR1C |= (1 << UCSZ10) | (1 << UCSZ11); // - 1 stop bit
/* Set baud rate */
UBRR1H = (unsigned char)(USART1_BAUD_PRESCALE>>8);
UBRR1L = (unsigned char)USART1_BAUD_PRESCALE;
UCSR1B |= (1 << RXCIE1); // Enable interrupt
}
void serial1_ion() {
UCSR1B |= (1<<RXEN1); // Enable rx
UCSR1B |= (1 << RXCIE1); // Enable interrupt
}
void serial1_ioff() {
UCSR1B &= ~(1<<RXEN1); // Disable rx
UCSR1B &= ~(1 << RXCIE1); // Disable interrupt
}
void serial0_ion() {
UCSR0B |= (1 << RXCIE0); // Enable interrupt
}
void serial0_ioff() {
UCSR0B &= ~(1 << RXCIE0); // Disable interrupt
}
void serial0_sendChar( unsigned char byte )
{
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = byte;
}
void serial1_sendChar( unsigned char byte )
{
while (!(UCSR1A & (1<<UDRE1)));
UDR1 = byte;
}
unsigned char serial0_readChar()
{
while(!(UCSR0A &(1<<RXC0)));
//char c = UDR0;
//serial0_sendString("Read: ");
//serial0_sendChar(c);
//serial0_sendChar('\n');
return UDR0;
}
uint8_t serial0_hasChar() {
return (UCSR0A &(1<<RXC0));
}
char readBuf[128];
char* serial0_readLine() {
char c;
int i = 0;
while(i < 128) {
c = serial0_readChar();
if(c == 0x0D) break;
readBuf[i] = c;
i++;
}
readBuf[i] = '\0';
return readBuf;
}
void serial0_sendString(const char* stringPtr){
while(*stringPtr != 0x00)
{
serial0_sendChar(*stringPtr);
stringPtr++;
}
}
void serial1_sendString(const char* stringPtr){
while(*stringPtr != 0x00)
{
serial1_sendChar(*stringPtr);
stringPtr++;
}
}
void serial_sendCommand(char* data )
{
char checkSum = 0x00; //initialize checksum
serial0_sendChar('['); //bracket indicates start of command
// send data, null-terminated
while(*data != 0x00)
{
serial0_sendChar(*data);
checkSum += *data;
data++;
}
serial0_sendChar(']'); //bracket indicates end of command
serial0_sendChar(checkSum); // checksum moved behind bracket to solve bug FS#29
}
void serial_sendResponseData()
{
}
|