Files
@ a7b1f3353188
Branch filter:
Location: seniordesign-firmware/slave/slave/slave.c
a7b1f3353188
3.3 KiB
text/plain
Calibrated battery voltage measurement for master
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 | /*
* Slave Firmware
*
* Wireless Observational Modular Aerial Network
*
* Kyle Ripperger
* Ethan Zonca
* Matthew Kanning
* Matthew Kroening
*
*/
#include "config.h"
#include <stdio.h>
#include <inttypes.h>
#include <avr/io.h>
#include <compat/twi.h>
#include <util/delay.h>
#include <avr/cpufunc.h>
#include <avr/interrupt.h>
#include "modules.h"
#include "lib/serial.h"
#include "lib/serparser.h"
#include "lib/led.h"
#include "lib/inputOutput.h"
#include "lib/i2c.h"
#include "lib/spi.h"
#include "lib/geiger.h"
#include "lib/sensors.h"
#include "lib/cameras.h"
#include "lib/loopTimer.h"
#include "lib/masterComm.h"
void micro_setup()
{
// Generic microcontroller config options
sei(); // Enable interrupts
}
int main(void)
{
// Writes ID to EEPROM, change for all modules and delete after programming
// 0 is for generic setup, 1 is for sensors, 2 is for Geiger, 3 is for cameras
//i2c_write(EEPROM_ADDR, 0x05, 0x03);
// Initialize
micro_setup(); // Generic microcontroller config options
time_setup(); // Setup loop timer and interrupts (TIMER0)
led_configure(); // Configure ports and registers for LED operation
io_configure(); // Configure IO ports and registers
i2c_init(); // Setup I2C
serial0_setup(); // Config serial port
io_readModuleId();
modules_setup(io_getModuleId()); // Run setup functions for specific module
// Serial output //DEBUG
char buff[128]; //Buffer for serial output //DEBUG
serial0_sendString("Starting Slave\r\n"); //DEBUG
while(1)
{
// Master communication
masterComm_checkParser(); //Checks parser for data requests from master
// Main slave operations
if ((time_millis() % SENSOR_LOOP) == 0) // Uses program timer to run every so often. Time interval defined in config.h
{
led_on(0);
sensors_readBatt(); // Read Battery level
sensors_readBoardTemp(); // Read board temperature sensor (Common on all slaves) (Data Read)
modules_run(io_getModuleId()); // Runs specific module functions (like data reading)
io_regulateTemp(); // Gets board temperature and enables heater if below threshold
snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu |Battery: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt()); //DEBUG
serial0_sendString(buff); //DEBUG
_delay_ms(1); // Delay to prevent the sensor loop from running again before time_millis changes
led_off(0);
led_off(2);
//led_output(i2c_read(EEPROM_ADDR, 0x05)); // Debugging, delete
//led_output(io_getModuleId());
}
}
return 0;
}
/********Examples of data reading and getting******************
x = geiger_getCpm(); //Data get
x = sensors_getSpiTemp(); //Data get
x = sensors_getBoardTemp(); //Data get
sensors_readSpiTemp(); //Data Read
sensors_readBoardTemp(); //Data Read
led_output(0xFF); //Output value to LED array
i2c_write(RTC_ADDR, 0x05, 0x3A); //i2c Write Example
PORTA &= ~(1 << PA1); //OFF
PORTA |= (1 << PA1); //ON
PORTB ^= (1 << PB0); //Toggle
sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
serial0_sendString(buff);
**************************************************************/
|