Changeset - 0e169f68c994
[Not reviewed]
default
0 13 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-01-09 22:10:43
ethanzonca@CL-ENS241-08.cedarville.edu
Added support for UART1, added numerous fixes. Introduction of GPS has caused several difficulties. Lowering baud rate to 4800 has made problems worse, probably change back to 115200 baud and disable serial1 interrupts when AFSK transmitting / logging.
13 files changed with 136 insertions and 84 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -28,6 +28,7 @@
 
// SD Card
 
#define ERROR_SD_INIT 2
 
#define ERROR_SD_PARTITION 3
 
#define ERROR_CRAP 6
 
 
// --------------------------------------------------------------------------
 
// Slave Sensors config (slavesensors.c)
 
@@ -66,7 +67,7 @@
 
// --------------------------------------------------------------------------
 
 
#define USART0_BAUDRATE 115200
 
#define USART1_BAUDRATE 115200
 
#define USART1_BAUDRATE 4800
 
 
 
// --------------------------------------------------------------------------
 
@@ -92,7 +93,7 @@
 
// - Home:       0
 
// - IGate:      5
 
#define S_CALLSIGN      "KD8TDF"
 
#define S_CALLSIGN_ID   11
 
#define S_CALLSIGN_ID   9 // 11
 

	
 
// Destination callsign: APRS (with SSID=0) is usually okay.
 
#define D_CALLSIGN      "APRS"
 
@@ -108,10 +109,10 @@
 
// APRS comment: this goes in the comment portion of the APRS message. You
 
// might want to keep this short. The longer the packet, the more vulnerable
 
// it is to noise.
 
#define APRS_COMMENT    "Payload data..."
 
#define APRS_COMMENT    "CedarvilleUniversity HAB"
 
 
// Transmit the APRS sentence every X milliseconds
 
#define APRS_TRANSMIT_PERIOD 5000
 
#define APRS_TRANSMIT_PERIOD 10000
 

	
 

	
 
// --------------------------------------------------------------------------
 
@@ -126,4 +127,7 @@
 
// Log to SD card every X milliseconds
 
#define LOGGER_RATE 1000 
 
 
// LED cycle indicator speed
 
#define LEDCYCLE_RATE 100 
 
 
#endif /* CONFIG_H_ */
 
\ No newline at end of file
master/master/lib/afsk.c
Show inline comments
 
@@ -71,8 +71,11 @@ extern const uint16_t TABLE_SIZE = sizeo
 

	
 
// phase offset of 1800 gives ~1900 Hz
 
// phase offset of 3300 gives ~2200 Hz
 
//#define PHASE_DELTA_1200 1800
 
//#define PHASE_DELTA_2200 2200
 
#define PHASE_DELTA_1200 1800
 
#define PHASE_DELTA_2200 2200
 
#define PHASE_DELTA_2200 3300
 

	
 

	
 
// Module globals
 
volatile unsigned char current_byte;
 
@@ -225,7 +228,7 @@ void afsk_setup()
 
	
 
	// todo: init radio, maybe in main
 
	
 
	sei();
 
	</i>
 
	
 
	while(afsk_busy());
 
}
 
\ No newline at end of file
master/master/lib/aprs.c
Show inline comments
 
@@ -15,9 +15,9 @@
 
#include "ax25.h"
 
#include <stdio.h>
 

	
 
const char *gps_aprs_lat = "latitude";
 
const char *gps_aprs_lon = "longitude";
 
const char *gps_time = "gpstime";
 
const char *gps_aprs_lat = "39.74744N";
 
const char *gps_aprs_lon = "-83.81249W";
 
const char *gps_time = "081533/";
 
float gps_altitude = 123.5;
 
int gps_course = 5;
 
int gps_speed = 13;
master/master/lib/led.c
Show inline comments
 
@@ -33,7 +33,7 @@ void led_on(uint8_t led)
 
	// Turn the specified LED off
 
void led_off(uint8_t led) 
 
{
 
	*(ledList[led].direction) &= ~(1<<ledList[led].pin);
 
	*(ledList[led].port) &= ~(1<<ledList[led].pin);
 
}
 
 
// Flashes error LED a set amount of times, then leaves it on
master/master/lib/led.h
Show inline comments
 
@@ -27,34 +27,36 @@ enum leds {
 
	LED_ERROR,
 
	LED_SIDEBOARD,
 
	LED_ACTIVITY,
 
	LED_CYCLE
 
	LED_CYCLE,
 
	LED_HEAT
 
};
 
 
typedef struct {uint8_t* direction; uint8_t* port; uint8_t pin;} led_t;
 
 
// Match order of leds enum
 
static led_t ledList[] = {
 
	{&DDRA, &PORTA, PA4}, // ACT0
 
	{&DDRA, &PORTA, PA5}, // ACT1
 
	{&DDRA, &PORTA, PA6}, // ACT2
 
	{&DDRA, &PORTA, PA7}, // ACT3
 
	{&DDRA, &PORTA, PA1}, // ACT0
 
	{&DDRA, &PORTA, PA2}, // ACT1
 
	{&DDRA, &PORTA, PA3}, // ACT2
 
	{&DDRA, &PORTA, PA4}, // ACT3
 
 
//pcb:
 
//	{&DDRB, &PORTB, PB4}, // POWER
 
//	{&DDRB, &PORTB, PB3}, // STATUS
 
//	{&DDRB, &PORTB, PB2}, // ERROR
 
	{&DDRB, &PORTB, PB4}, // POWER
 
	{&DDRB, &PORTB, PB3}, // STATUS
 
	{&DDRB, &PORTB, PB2}, // ERROR
 
 
//breadboard:
 
	{&DDRA, &PORTA, PA2}, // POWER
 
	{&DDRA, &PORTA, PA0}, // STATUS
 
	{&DDRA, &PORTA, PA1}, // ERROR
 
//	{&DDRA, &PORTA, PA2}, // POWER
 
//	{&DDRA, &PORTA, PA0}, // STATUS
 
//	{&DDRA, &PORTA, PA1}, // ERROR
 
 
	{&DDRD, &PORTD, PD6}, // SIDEBOARD
 
	{&DDRD, &PORTD, PD5}, // ACTIVITY
 
	{&DDRD, &PORTD, PD4}, // CYCLE
 
	{&DDRA, &PORTA, PD6}, // HEAT
 
};
 
 
#define NUM_LEDS 10
 
#define NUM_LEDS 11
 
 
void led_setup();
 
void led_on(uint8_t led);
master/master/lib/logger.c
Show inline comments
 
@@ -38,7 +38,7 @@ void logger_setup()
 
	if(!sd_raw_init())
 
	{
 
		// Initializing SD card failed!
 
		// Error opening partition. MBR might be screwed up.
 
		serial0_sendString("SD: Error initializing.\r\n");
 
		led_errorcode(ERROR_SD_INIT);
 
		return;
 
	}
 
@@ -52,6 +52,7 @@ void logger_setup()
 
	// Check that partition was created correctly
 
	if(!partition)
 
	{
 
		serial0_sendString("SD: Error opening partition.\r\n");
 
		// Error opening partition. MBR might be screwed up.
 
		led_errorcode(ERROR_SD_PARTITION);
 
		return;
master/master/lib/serial.c
Show inline comments
 
@@ -34,26 +34,28 @@ void serial0_setup() {
 
	UCSR0B |= (1 << RXCIE0); // Enable interrupt
 
	
 
	//UCSR0A |= (1<<RXC0);
 
}
 
 
volatile uint8_t charTest;
 
 
ISR(USART1_RX_vect)
 
{
 
	serial1_sendChar(UDR1);
 
}
 
 
/*
 
uint8_t test = 0;
 
ISR(USART0__RX_vect)
 
{
 
	led_on(POWER);
 
	test = UDR0;
 
}*/
 
void serial1_setup() {
 
//PROVEN in test project
 
 
void serial1_setup() {
 
	/* 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;
 
	/* Enable receiver and transmitter */
 
	UCSR1B = (1<<RXEN1)|(1<<TXEN1);
 
	/* Set frame format: 8data, 1stop bit */
 
	UCSR1C = (3<<UCSZ10); // - 1 stop bit
 
	
 
	UCSR1B |= (1 << RXCIE1); // Enable interrupt
 
}
 
 
void serial0_sendChar( unsigned char byte )
 
@@ -68,18 +70,6 @@ void serial1_sendChar( unsigned char byt
 
	UDR1 = byte;
 
}
 
 
unsigned char serial0_readChar()
 
{
 
	while(!(UCSR0A &(1<<RXC0)));
 
	return UDR0;
 
}
 
 
unsigned char serial1_readChar()
 
{
 
	while(!(UCSR1A &(1<<RXC1)));
 
	return UDR1;
 
}
 
 
void serial0_sendString(const char* stringPtr){
 
	while(*stringPtr != 0x00)
 
	{
 
@@ -96,7 +86,6 @@ void serial1_sendString(const char* stri
 
	}
 
}
 
 
 
void serial_sendCommand( char moduleID, char sensorID, char* data )
 
{
 
	char checkSum = 0x00; //initialize checksum
master/master/lib/serial.h
Show inline comments
 
@@ -22,9 +22,6 @@
 
void serial0_sendChar( unsigned char byte );
 
void serial1_sendChar( unsigned char byte );
 
 
unsigned char serial0_readChar();
 
unsigned char serial1_readChar();
 
 
void serial0_setup();
 
void serial1_setup();
 
master/master/lib/serparser.c
Show inline comments
 
@@ -78,16 +78,18 @@ static void setParserState(uint8_t state
 
 
char debugBuff[16];
 
 
ISR(USART0__RX_vect)
 
 
ISR(USART0_RX_vect)
 
{
 
	buffer[bufferDataPosition % BUFFER_SIZE] = UDR0;
 
	bufferDataPosition = (bufferDataPosition + 1) % BUFFER_SIZE;
 
	/*sprintf(debugBuff, "bdp: %d, bpp: %d \r\n", bufferDataPosition, bufferParsePosition);
 
	serial0_sendString((debugBuff)); */
 
	//sprintf(debugBuff, "bdp: %d, bpp: %d \r\n", bufferDataPosition, bufferParsePosition);
 
	//serial0_sendString((debugBuff)); 
 
}
 
 
 
 
 
//#define DEBUG
 
 
// Parse data from circular buffer
master/master/lib/trackuinoGPS/gpsMKa.c
Show inline comments
 
@@ -10,6 +10,7 @@
 
#include "gpsMKa.h"
 
#include "../serial.h"
 

	
 

	
 
// holds the byte ALREADY PARSED. includes starting character
 
int bytesReceived = 0;
 

	
 
@@ -71,11 +72,13 @@ enum decodeState {
 
	
 
}decodeState;
 

	
 

	
 

	
 
//// MKa GPS transmission parser START
 
void parse_gps_transmission(void){
 
	
 
	// Pull byte off of the buffer
 
	char byte = serial1_readChar();
 
	char byte = 'a';// serial1_readChar();
 
	
 
	if(byte == '$') //start of transmission sentence
 
	{
master/master/lib/watchdog.c
Show inline comments
 
@@ -24,7 +24,7 @@ void watchdog_setup(void)
 
	// Set change enable bit, enable the WDT
 
	WDTCSR = (1<<WDCE)|(1<<WDE);
 
	// Start watchdog, 4 second timeout
 
	WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0);
 
	WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0);
 
	sei();
 
}
 
master/master/master.c
Show inline comments
 
@@ -24,8 +24,9 @@
 
#include "lib/aprs.h"
 
#include "lib/afsk.h"
 
#include "lib/led.h"
 
#include "lib/logger.h"
 
//#include "lib/logger.h"
 
#include "lib/watchdog.h"
 
//!
 
#include "lib/sd/sd_raw_config.h"
 
#include "lib/looptime.h"
 
#include "lib/slavesensors.h"
 
@@ -39,29 +40,35 @@ void micro_setup()
 

	
 
int main(void)
 
{
 
    
 
    _delay_ms(1500); // warmup
 
	// Initialize libraries
 
	time_setup();
 
	
 
	micro_setup();
 
	watchdog_setup();
 
	
 
	watchdog_setup(); // enables interrupts
 
	
 
	led_setup();
 
	
 
	serial0_setup();
 
	_delay_ms(10);
 
	
 
	serial1_setup();
 
	
 
	sensordata_setup(); // must happen before sensors/logger/afsk
 
	slavesensors_setup();
 
	logger_setup();
 
	
 
	afsk_setup();
 

	
 
	//serial0_sendString("\r\n\r\n---------------------------------\r\n");
 
	//serial0_sendString("HAB Controller 1.0 - Initialized!\r\n");
 
	//serial0_sendString("---------------------------------\r\n\r\n");
 
	//serial0_sendString("\f\r\n\r\Hello.\r\n\r\n");
 
	serial0_sendString("\r\n\r\n---------------------------------\r\n");
 
	serial0_sendString("HAB Controller 1.0 - Initialized!\r\n");
 
	serial0_sendString("---------------------------------\r\n\r\n");
 
	serial0_sendString("\f\r\n\r\Hello.\r\n\r\n");
 
	
 
	led_on(LED_POWER);
 
	led_off(LED_SIDEBOARD);
 

	
 
	
 
	// Buffer for string operations
 
	char logbuf[16];
 
@@ -69,6 +76,7 @@ int main(void)
 
	// Software timers	
 
	uint32_t lastAprsBroadcast = 0;
 
	uint32_t lastLog = 0;
 
	uint32_t lastLedCycle = 0;
 
	
 
	// Result of last parser run
 
	int parseResult = PARSERESULT_NODATA;
 
@@ -76,23 +84,66 @@ int main(void)
 
	// Write CSV header to SD card
 
	//logger_log("ProgramTime,LastAprsBroadcast,LastLog\n");
 
	
 
	uint8_t ctr = 0;
 
	void spin() {
 
		if(ctr == 0) {
 
			led_on(LED_ACT0);
 
			led_off(LED_ACT1);
 
			led_off(LED_ACT2);
 
			led_off(LED_ACT3);
 
		}			
 
		else if (ctr == 1) {
 
			led_on(LED_ACT1);
 
			led_off(LED_ACT0);
 
			led_off(LED_ACT2);
 
			led_off(LED_ACT3);
 
		}			
 
		else if (ctr == 2) {
 
			led_on(LED_ACT2);
 
			led_off(LED_ACT1);
 
			led_off(LED_ACT0);
 
			led_off(LED_ACT3);
 
		}			
 
		else if (ctr == 3) {
 
			led_on(LED_ACT3);
 
			led_off(LED_ACT1);
 
			led_off(LED_ACT2);
 
			led_off(LED_ACT0);
 
		}			
 
		ctr = (ctr + 1) % 4;
 
	}
 
	
 
	while(1)
 
    {
 
		
 
		if(time_millis() - lastLedCycle > LEDCYCLE_RATE) {
 
			spin();
 
			
 
			lastLedCycle = time_millis();	
 
		}
 
		
 
		// Periodic: Logging
 
		if(time_millis() - lastLog > LOGGER_RATE) 
 
		{
 
			led_on(LED_STATUS);
 
			snprintf(logbuf, 16, "%lu,%d,\r\n", time_millis(), sensordata_get(HUMIDITY));
 
			logger_log(logbuf);
 
			//serial0_sendString("Logging: ");
 
			//serial0_sendString(logbuf);
 
			led_off(LED_STATUS);
 
			
 
			lastLog = time_millis();
 
		}		
 
		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
 
			serial0_sendString(":: APRS Periodic\r\n");
 
			
 
			while(afsk_busy());
 
			aprs_send(); // non-blocking
 
			
 
			//serial0_sendString("Initiating APRS transmission...\r\n");
 
			
 
			// Start getting values for next transmission
 
@@ -108,7 +159,10 @@ int main(void)
 
			lastAprsBroadcast = time_millis();
 
		}			
 
		
 

	
 
		parseResult = serparser_parse();
 
		
 

	
 
		slavesensors_process(parseResult);
 

	
 
		wdt_reset();
master/master/master.cproj
Show inline comments
 
@@ -5,7 +5,7 @@
 
    <ProjectVersion>6.0</ProjectVersion>
 
    <ToolchainName>com.Atmel.AVRGCC8</ToolchainName>
 
    <ProjectGuid>{8579ec2d-5815-40db-84e0-1d14239c7aea}</ProjectGuid>
 
    <avrdevice>ATmega324P</avrdevice>
 
    <avrdevice>ATmega644PA</avrdevice>
 
    <avrdeviceseries>none</avrdeviceseries>
 
    <OutputType>Executable</OutputType>
 
    <Language>C</Language>
 
@@ -48,7 +48,7 @@
 
      </OverrideVtorValue>
 
      <Channel>
 
        <host>127.0.0.1</host>
 
        <port>61309</port>
 
        <port>49512</port>
 
        <ssl>False</ssl>
 
      </Channel>
 
      <ToolOptions>
 
@@ -132,15 +132,15 @@
 
    <Compile Include="lib\ax25.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\logger.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\logger.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\logger.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
@@ -150,40 +150,40 @@
 
    <Compile Include="lib\looptime.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\byteordering.c">
 
    <Compile Include="lib\SDa\byteordering.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\byteordering.h">
 
    <Compile Include="lib\SDa\byteordering.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\fat.c">
 
    <Compile Include="lib\SDa\fat.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\fat.h">
 
    <Compile Include="lib\SDa\fat.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\fat_config.h">
 
    <Compile Include="lib\SDa\fat_config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\partition.c">
 
    <Compile Include="lib\SDa\partition.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\partition.h">
 
    <Compile Include="lib\SDa\partition.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\partition_config.h">
 
    <Compile Include="lib\SDa\partition_config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\sd-reader_config.h">
 
    <Compile Include="lib\SDa\sd-reader_config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\sd_raw.c">
 
    <Compile Include="lib\SDa\sd_raw.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\sd_raw.h">
 
    <Compile Include="lib\SDa\sd_raw.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sd\sd_raw_config.h">
 
    <Compile Include="lib\SDa\sd_raw_config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sensordata.c">
 
@@ -210,9 +210,6 @@
 
    <Compile Include="lib\slavesensors.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\trackuinoGPS\config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\trackuinoGPS\gpsMKa.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
@@ -231,8 +228,8 @@
 
  </ItemGroup>
 
  <ItemGroup>
 
    <Folder Include="lib" />
 
    <Folder Include="lib\SDa" />
 
    <Folder Include="lib\trackuinoGPS" />
 
    <Folder Include="lib\sd" />
 
  </ItemGroup>
 
  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
 
</Project>
 
\ No newline at end of file
0 comments (0 inline, 0 general)