# HG changeset patch # User kripperger@CL-SEC241-09.cedarville.edu # Date 2013-04-29 17:17:13 # Node ID 7021dff6a9f00b6c786c6779cfaa7d0d3d0046fe # Parent a9cad9614abd22215f836bb96f9d37e4c944a01b Added generic voltage reading function diff --git a/slave/slave/config.h b/slave/slave/config.h --- a/slave/slave/config.h +++ b/slave/slave/config.h @@ -21,7 +21,7 @@ // Maximum payload size of command #define MAX_PAYLOAD_LEN 16 -// Number of datatypes to transmit per module type +// Number of datatypes to transmit per module type. This should match what is being sent in masterComm.c #define DATATYPES_GENERIC 3 #define DATATYPES_SENSOR 8 #define DATATYPES_GEIGER 4 diff --git a/slave/slave/lib/geiger.c b/slave/slave/lib/geiger.c --- a/slave/slave/lib/geiger.c +++ b/slave/slave/lib/geiger.c @@ -13,6 +13,8 @@ #include #include "geiger.h" #include "loopTimer.h" +#include "led.h" +#include "inputOutput.h" volatile uint8_t seconds; // Counts Seconds from Timer2 interrupt volatile uint16_t counts; // Counts the pulses diff --git a/slave/slave/lib/inputOutput.c b/slave/slave/lib/inputOutput.c --- a/slave/slave/lib/inputOutput.c +++ b/slave/slave/lib/inputOutput.c @@ -10,6 +10,7 @@ #include "inputOutput.h" #include "led.h" #include "sensors.h" +#include "i2c.h" int8_t moduleID; // Slave Module ID from rotary dip switch (or EEPROM) diff --git a/slave/slave/lib/masterComm.c b/slave/slave/lib/masterComm.c --- a/slave/slave/lib/masterComm.c +++ b/slave/slave/lib/masterComm.c @@ -67,7 +67,7 @@ void masterComm_types() } -void masterComm_packetSend_unsigned(uint8_t id, uint32_t data) +void masterComm_packetSend_unsigned(uint8_t id, uint32_t data) //Sends the data type and data to master for unsigned data { serial0_sendChar('['); snprintf(buff2,64,"%u%lu",id,data); @@ -76,7 +76,7 @@ void masterComm_packetSend_unsigned(uint serial0_sendChar(masterComm_checksum(buff2)); } -void masterComm_packetSend_signed(uint8_t id, int32_t data) +void masterComm_packetSend_signed(uint8_t id, int32_t data) //Sends the data type and data to master for signed data { serial0_sendChar('['); snprintf(buff2,64,"%u%ld",id,data); @@ -104,7 +104,7 @@ void masterComm_modules() { case 0: // Generic - + break; case 1: @@ -152,7 +152,7 @@ void masterComm_send() // Return request with number of data types to be sent serial0_sendChar('['); // Send opening bracket - snprintf(buff2,64,"@%u",dataTypes); // Send package (@ reply and number of data types) + snprintf(buff2,64,"@%u",dataTypes); // Send package (@ reply and number of data types) serial0_sendString(buff2); serial0_sendChar(']'); // Send closing bracket serial0_sendChar(masterComm_checksum(buff2)); // Calculate and send checksum diff --git a/slave/slave/lib/sensors.c b/slave/slave/lib/sensors.c --- a/slave/slave/lib/sensors.c +++ b/slave/slave/lib/sensors.c @@ -30,6 +30,9 @@ uint8_t battL; // Low byte of ADC uint16_t batt; // Read battery voltage from ADC uint16_t vBatt; // battery voltage +int8_t analogL; // Low byte of ADC +int16_t analog; // Read analog voltage from ADC + int16_t ac1; // The following 11 variables are the calibration values for the BMP085 int16_t ac2; int16_t ac3; @@ -220,6 +223,7 @@ void sensors_readLux() void sensors_readBatt() { + ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0); // Select ADC7 as the conversion channel battL = ADCL; // Read low battery byte from ADC (all 8 bits) batt = ADCH; // Read high battery byte from ADC (only two LSBs) batt = batt << 8; @@ -228,7 +232,25 @@ void sensors_readBatt() } - +void sensors_readAnalog(uint8_t pin) +{ + // Reads analog input on PORTA on the pin (0-7) specified. + + DDRA &= ~(1 << pin); // Set pin to input + + ADMUX &= 0xF8; + ADMUX |= pin; + + analogL = ADCL; // Read low battery byte from ADC (all 8 bits) + analog = ADCH; // Read high battery byte from ADC (only two LSBs) + + analogL = ADCL; // Second Read low battery byte from ADC (all 8 bits) + analog = ADCH; // Second Read high battery byte from ADC (only two LSBs) + + analog = analog << 8; + analog |= analogL; + analog = (analog * 10.0) / 67.4; +} @@ -264,6 +286,11 @@ uint16_t sensors_getBatt(void) // Gets return vBatt; } +int16_t sensors_getAnalog(void) // Gets battery voltage from variable +{ + return analog; +} + uint32_t sensors_getAltitude(void) { return altitude; diff --git a/slave/slave/lib/sensors.h b/slave/slave/lib/sensors.h --- a/slave/slave/lib/sensors.h +++ b/slave/slave/lib/sensors.h @@ -17,6 +17,7 @@ void sensors_readPressure(void); // Read void sensors_readHumid(void); // Reads humidity void sensors_readLux(void); // Reads lux void sensors_readBatt(void); // Reads battery voltage from ADC +void sensors_readAnalog(uint8_t pin); // Reads generic analog voltage from ADC int16_t sensors_getSpiTemp(void); // Gets spi temperature from variable int8_t sensors_getBoardTemp(void); // Gets board temperature from variable @@ -24,6 +25,7 @@ int32_t sensors_getPressure(void); // Ge uint16_t sensors_getHumid(void); // Gets humidity from variable uint32_t sensors_getLux(void); // Gets lux from variable uint16_t sensors_getBatt(void); // Gets battery voltage from variable +int16_t sensors_getAnalog(void); // Gets battery voltage from variable uint32_t sensors_getAltitude(void); // Gets altitude from variable #endif /* SENSORS_H_ */ \ No newline at end of file diff --git a/slave/slave/modules.c b/slave/slave/modules.c --- a/slave/slave/modules.c +++ b/slave/slave/modules.c @@ -146,6 +146,7 @@ // No data gatering function needed for geiger daughter board // This is taken care of in interrupt (See geiger.c) + //lastRefresh = time_millis(); //if ((time_millis() - lastRefresh) > 1000000) //{