diff --git a/slave/slave/config.h b/slave/slave/config.h --- a/slave/slave/config.h +++ b/slave/slave/config.h @@ -37,6 +37,7 @@ #define PRESSURE_ADDR 0xEE // Read 0xEF - Write 0xEE #define HUMID_ADDR 0x26 // Read 0x27 - Write 0x26 #define LIGHT_ADDR 0x94 // Read 0x95 - Write 0x94 + #define ACCEL_ADDR 0x38 // Read 0x39 - Write 0x38 #define RTC_ADDR 0xB2 //DEBUG [Used for testing] // Read 0xA3 - Write 0xA2 diff --git a/slave/slave/lib/cameras.c b/slave/slave/lib/cameras.c --- a/slave/slave/lib/cameras.c +++ b/slave/slave/lib/cameras.c @@ -13,5 +13,32 @@ #include #include "cameras.h" + #include "i2c.h" - \ No newline at end of file + int8_t xmsb; // Acceleration data in x-direction (MSB) + int8_t ymsb; // Acceleration data in y-direction (MSB) + int8_t zmsb; // Acceleration data in z-direction (MSB) + + + + void cameras_readAccelXYZ() + { + xmsb = i2c_read(ACCEL_ADDR, 0x01); + ymsb = i2c_read(ACCEL_ADDR, 0x03); + zmsb = i2c_read(ACCEL_ADDR, 0x05); + } + + int8_t cameras_getAccelX() + { + return xmsb; + } + + int8_t cameras_getAccelY() + { + return ymsb; + } + + int8_t cameras_getAccelZ() + { + return zmsb; + } \ No newline at end of file diff --git a/slave/slave/lib/cameras.h b/slave/slave/lib/cameras.h --- a/slave/slave/lib/cameras.h +++ b/slave/slave/lib/cameras.h @@ -10,7 +10,10 @@ #define CAMERAS_H_ +void cameras_readAccelXYZ(void); // Reads acceleration values - +int8_t cameras_getAccelX(void); // Returns x-acceleration +int8_t cameras_getAccelY(void); // Returns y-acceleration +int8_t cameras_getAccelZ(void); // Returns z-acceleration #endif /* CAMERAS_H_ */ \ No newline at end of file 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 @@ -24,16 +24,15 @@ int8_t moduleID; // Slave Module ID from DDRC &= ~(1 << DDC5); // Set PC5 to input for rotary dip DDRA &= ~(1 << DDA7); // Set PA7 to input for battery voltage divider - //ADC register configurations for battery level detection on PA7 ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // Set prescaler for ADC, 128 gives ADC freq of 125 KHz ADMUX |= (1 << REFS0); // Set ADC reference voltage to AVCC - //ADMUX |= (1 << ADLAR); // Sets 10 bit ADC to 8 bit + //ADMUX |= (1 << ADLAR); // Sets 10 bit ADC to 8 bit ADMUX |= (1 << MUX2) | (1 << MUX1) | (1 << MUX0); // Select ADC7 as the conversion channel ADCSRA |= (1 << ADATE); // Enables auto trigger, determined in ADCSRB bits ADTS - //ADCSRA |= (1 << ADIF); // - //ADCSRA |= (1 << ADIE); // ADC interrupt enable set + //ADCSRA |= (1 << ADIF); // + //ADCSRA |= (1 << ADIE); // ADC interrupt enable set ADCSRB &= ~((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0));// Set ADC auto trigger source to free running mode ADCSRA |= (1 << ADEN); // Enable ADC ADCSRA |= (1 << ADSC); // Start ADC measurements. ADC should now continuously run conversions, which are stored in ADCH 0x79 @@ -46,6 +45,7 @@ int8_t moduleID; // Slave Module ID from // Get ID from rotary dip and return it. moduleID = 0; + /* // This method is temporary as the next release will read the module ID from EEPROM PORTC |= (1 << PC2); // Pull pins on rotary dip high PORTC |= (1 << PC3); // Pull pins on rotary dip high @@ -55,17 +55,12 @@ int8_t moduleID; // Slave Module ID from moduleID = ((PINC & 0b00011100) >> 2); // Read Dip Encoder moduleID = ~moduleID; //Invert Dip reading moduleID = (moduleID & 0b0111); //Mask bits - + */ -/* while(moduleID==0) { moduleID = i2c_read(EEPROM_ADDR, 0x05); } -*/ - //moduleID = i2c_read(EEPROM_ADDR, 0x05); - - } 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 @@ -16,7 +16,7 @@ void sensors_readBoardTemp(void); // Rea void sensors_readPressure(void); // Reads pressure void sensors_readHumid(void); // Reads humidity void sensors_readLux(void); // Reads lux -void sensors_readBatt(void); +void sensors_readBatt(void); // Reads battery voltage from ADC int16_t sensors_getSpiTemp(void); // Gets spi temperature from variable int8_t sensors_getBoardTemp(void); // Gets board temperature from variable diff --git a/slave/slave/modules.c b/slave/slave/modules.c --- a/slave/slave/modules.c +++ b/slave/slave/modules.c @@ -139,6 +139,7 @@ void modules_cameras() { // Gathers data and performs functions for cameras daughter board + cameras_readAccelXYZ(); } \ No newline at end of file diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -47,7 +47,7 @@ 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 @@ -81,17 +81,17 @@ int main(void) sensors_readBoardTemp(); // Read board temperature sensor (Common on all slaves) (Data Read) modules_run(io_getModuleId()); // Runs specific module functions (like data reading) - i2c_write(EEPROM_ADDR, 0x05, 0x01); - 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 + 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)); + + //led_output(i2c_read(EEPROM_ADDR, 0x05)); // Debugging, delete + //led_output(io_getModuleId()); } }