Changeset - 70abc5d16090
[Not reviewed]
default
0 6 0
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-11-27 19:18:07
ethanzonca@CL-SEC241-08.cedarville.edu
Added working USART library
6 files changed with 92 insertions and 44 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -9,12 +9,21 @@
 
#ifndef CONFIG_H_
 
#define CONFIG_H_
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
 
 
 
// --------------------------------------------------------------------------
 
// USART config (serial.c)
 
// --------------------------------------------------------------------------
 
 
#define USART0_BAUDRATE 115200
 
#define USART1_BAUDRATE 115200
 
 
// --------------------------------------------------------------------------
 
// AX.25 config (ax25.c)
 
// --------------------------------------------------------------------------
 

	
 
// TX delay in milliseconds
 
#define TX_DELAY      300
master/master/lib/serial.c
Show inline comments
 
@@ -7,65 +7,79 @@
 
 
#include "serial.h"
 
#include "../config.h"
 
#include <avr/io.h>
 
 
 
void serial_setup() {
 
	// Set registers!
 
	
 
	// from mnl
 
	// uart
 
	//UBRRH = (BAUD_PRESCALE >> 8); // 0
 
	//UBRRL = BAUD_PRESCALE; // 8
 
	//UCSRA = 0;
 
	//UCSRB = 0x18;
 
	//UCSRC = 0x06;
 
	//OCR0B = 0xff;
 
	//OCR0A = 0xff;
 
	//OCR1AL = 0xff;
 
	//OCR1BL = 0xff;
 
 
 
void serial0_setup() {
 
	/* Set baud rate */
 
	UBRR0H = (unsigned char)(BAUD_PRESCALE>>8);
 
	UBRR0L = (unsigned char)BAUD_PRESCALE;
 
	UBRR0H = (unsigned char)(USART0_BAUD_PRESCALE>>8);
 
	UBRR0L = (unsigned char)USART0_BAUD_PRESCALE;
 
	/* Enable receiver and transmitter */
 
	UCSR0B = (1<<RXEN0)|(1<<TXEN0);
 
	/* Set frame format: 8data, 2stop bit */
 
	UCSR0C = (3<<UCSZ00);
 
 
	/* Set frame format: 8data, 1stop bit */
 
	UCSR0C = (3<<UCSZ00); // - 1 stop bit
 
}
 
 
void serial1_setup() {
 
	/* Set baud rate */
 
	UBRR1H = (unsigned char)(USART1_BAUD_PRESCALE>>8);
 
	UBRR1L = (unsigned char)USART1_BAUD_PRESCALE;
 
	/* Enable receiver and transmitter */
 
	UCSR1B = (1<<RXEN1)|(1<<TXEN1);
 
	/* Set frame format: 8data, 1stop bit */
 
	UCSR1C = (3<<UCSZ10); // - 1 stop bit
 
}
 
 
void serial_SendChar( char byte )
 
void serial0_sendChar( unsigned char byte )
 
{
 
	while (!(UCSR0A & (1<<UDRE0)));
 
	UDR0 = byte;
 
}
 
 
void serial_SendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data )
 
void serial1_sendChar( unsigned char byte )
 
{
 
	while (!(UCSR1A & (1<<UDRE1)));
 
	UDR1 = byte;
 
}
 
 
void serial0_sendString(char* stringPtr){
 
	while(*stringPtr != 0x00){
 
		serial0_sendChar(*stringPtr);
 
		stringPtr++;
 
	}
 
}
 
 
void serial1_sendString(char* stringPtr){
 
	while(*stringPtr != 0x00){
 
		serial1_sendChar(*stringPtr);
 
		stringPtr++;
 
	}
 
}
 
 
 
void serial_sendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data )
 
{
 
	char checkSum = 0x00; //initialize checksum
 
	
 
	serial_SendChar('['); //bracket indicates start of command
 
	serial_SendChar(moduleID);
 
	serial0_sendChar('['); //bracket indicates start of command
 
	serial0_sendChar(moduleID);
 
	checkSum+=moduleID;
 
	
 
	serial_SendChar(sensorID);
 
	serial0_sendChar(sensorID);
 
	checkSum+=sensorID;
 
	
 
	//send each character of data individually
 
	for (int i=0; i<dataLength; i++)
 
	{
 
		serial_SendChar(data[i]);
 
		serial0_sendChar(data[i]);
 
		checkSum+=data[i];
 
	}
 
	
 
	serial_SendChar(checkSum);
 
	serial_SendChar(']'); //bracket indicates end of command
 
	serial0_sendChar(checkSum);
 
	serial0_sendChar(']'); //bracket indicates end of command
 
}
 
 
void serial_SendResponseData(){
 
void serial_sendResponseData(){
 
	
 
}
 
master/master/lib/serial.h
Show inline comments
 
@@ -8,15 +8,23 @@
 
 
#ifndef SERIAL_H_
 
#define SERIAL_H_
 
 
#include <inttypes.h>
 
 
#define USART_BAUDRATE 19200
 
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) -1 )
 
#define USART0_BAUD_PRESCALE (((F_CPU / (USART0_BAUDRATE * 16UL))) -1 )
 
#define USART1_BAUD_PRESCALE (((F_CPU / (USART1_BAUDRATE * 16UL))) -1 )
 
 
void serial0_sendChar( unsigned char byte );
 
void serial1_sendChar( unsigned char byte );
 
 
void serial_SendChar( char byte );
 
void serial_SendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data );
 
void serial_SendResponseData();
 
void serial_setup();
 
void serial0_setup();
 
void serial1_setup();
 
 
void serial0_sendString(char* stringPtr);
 
void serial1_sendString(char* stringPtr);
 
 
void serial_sendCommand( char moduleID, char sensorID, uint8_t dataLength, char* data );
 
void serial_sendResponseData();
 
 
 
#endif /* SERIAL_H_ */
 
\ No newline at end of file
master/master/lib/trackuinoGPS/config.h
Show inline comments
 
@@ -75,18 +75,18 @@
 
// the formula:
 
//
 
//         APRS_SLOT (seconds) + n * APRS_PERIOD (seconds)
 
//
 
// When launching multiple balloons, use the same APRS_PERIOD in all balloons
 
// and set APRS_SLOT so that the packets are spaced equally in time.
 
// Eg. for two balloons and APRS_PERIOD = 60, set APRS_SLOT to 0 and 30, 
 
// E.g. for two balloons and APRS_PERIOD = 60, set APRS_SLOT to 0 and 30, 
 
// respectively. The first balloon will transmit at 00:00:00, 00:01:00, 
 
// 00:02:00, etc. amd the second balloon will transmit at 00:00:30, 00:01:30,
 
// 00:02:00, etc. and the second balloon will transmit at 00:00:30, 00:01:30,
 
// 00:02:30, etc.
 
#define APRS_SLOT     0     // seconds. -1 disables slotted transmissions
 
#define APRS_PERIOD   60    // seconds
 
#define APRS_PERIOD   5    // seconds
 

	
 
// GPS baud rate (in bits per second). This is also the baud rate at which
 
// debug data will be printed out the serial port.
 
#define GPS_BAUDRATE  9600
 

	
 

	
master/master/lib/trackuinoGPS/gpsMKa.c
Show inline comments
 
/*
 
* gpsMKa.c
 
*
 
* Created: 11/15/2012 12:02:38 PM
 
*  Author: mkanning
 
*/
 
/*
 
#include <stdbool.h>
 
#include <avr/io.h>
 
#include "gpsMKa.h"
 

	
 
// holds the byte ALREADY PARSED. includes starting character
 
int bytesReceived = 0;
 
@@ -287,8 +288,8 @@ void parse_gps_transmission(void){
 
			checksum[numBytes] = byte;
 
			numBytes++;
 
		}
 
	}
 
	
 
}
 

	
 
*/
 
/// MKa GPS transmission parser END
 
\ No newline at end of file
master/master/master.c
Show inline comments
 
@@ -36,36 +36,52 @@ int main(void)
 
    
 
	// Initialize. If this takes more than 4 seconds, be sure to reset the WDT
 
	time_setup();
 
	micro_setup();
 
	watchdog_setup();
 
	led_setup();
 
	serial_setup(); // Config serial ports
 
	serial0_setup(); // Config serial ports
 
	serial1_setup(); // Config serial ports
 
	logger_setup(); // this takes a few ms
 
	afsk_setup(); // can take a few ms
 
	
 
	
 
	//led_on(POWER);
 
	led_on(POWER);
 
	
 
	uint16_t ctr1 = 0;
 
	uint16_t ctr2 = 255;
 
		
 
	char logbuf[32];
 
	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	
 
	while(1)
 
    {
 
		
 
		if(time_millis() - lastLog > 1000) {
 
		led_on(STAT);
 
		//sprintf(logbuf, "%d,%d,%d,%d,%d,%d\n", time_millis(),5*ctr1,ctr2, 12*ctr2,43*ctr1,5*ctr2);
 
		sprintf(logbuf, "%d,\n", time_millis());
 
			sprintf(logbuf, "%lu,%u,%u,%u,%u,%u\r\n", time_millis(),5*ctr1,ctr2, 12*ctr2,43*ctr1,5*ctr2);
 
		logger_log(logbuf);
 
			serial0_sendString("I am serial port 0!\r\n");
 
			serial1_sendString("I am serial port 1!\r\n");
 
		led_off(STAT);
 
			lastLog = time_millis();
 
		}		
 
		
 
		// Wait for transmission to complete before starting another.
 
		// Hopefully this will never delay because it should issue on a timed schedule. Software timers!
 
		
 
		// 8 second periodic for APRS transmission
 
		// for some reason this seems to lock up and the WDT resets everything when the period exceeds 8 seconds. Which is the WDTimeout. Weird.
 
		// If we want ~8+ seconds, then we'll need to do something fun here. Maybe reset the wdt...
 
		if(time_millis() - lastAprsBroadcast > 10000) {
 
		while(afsk_busy());
 
		aprs_send(); // non-blocking
 
			lastAprsBroadcast = time_millis();
 
		}			
 
		
 
		ctr1++;
 
		ctr2-=6;
 
		wdt_reset();
 
    }
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)