Files
@ d62f0f469869
Branch filter:
Location: seniordesign-firmware/master/master/lib/serial.c
d62f0f469869
2.5 KiB
text/plain
APRS tracking functional
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 | /*
* 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>
// 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_sendChar( unsigned char byte )
{
while (!(UCSR0A & (1<<UDRE0)));
UDR0 = byte;
}
void serial1_sendChar( unsigned char byte )
{
while (!(UCSR1A & (1<<UDRE1)));
UDR1 = byte;
}
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 moduleID, char sensorID, char* data )
{
char checkSum = 0x00; //initialize checksum
serial0_sendChar('['); //bracket indicates start of command
serial0_sendChar(moduleID);
checkSum+=moduleID;
serial0_sendChar(sensorID);
checkSum+=sensorID;
// 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()
{
}
|