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 @@ -22,12 +22,11 @@ ISR(TIMER2_OVF_vect) // Timer 2 overf { // This executes every second. Update real-time clocks. // Used only in Geiger module - seconds++; - if (seconds==60) + if (seconds>=30) { + cpm = (counts*2); seconds = 0; - cpm = counts; counts = 0; } } @@ -38,7 +37,13 @@ ISR(PCINT0_vect) // Interrupt on PA0 counts++; // Increment counter. } -inline uint16_t geiger_getCpm() +uint16_t geiger_getCpm() { return cpm; -} \ No newline at end of file +} + +uint8_t geiger_getCount() //DEBUG +{ + return seconds; +} + diff --git a/slave/slave/lib/geiger.h b/slave/slave/lib/geiger.h --- a/slave/slave/lib/geiger.h +++ b/slave/slave/lib/geiger.h @@ -9,7 +9,7 @@ #ifndef GEIGER_H_ #define GEIGER_H_ -inline uint16_t geiger_getCpm(); - +uint16_t geiger_getCpm(); +uint8_t geiger_getCount(); //DEBUG #endif /* GEIGER_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 @@ -7,6 +7,19 @@ #include + void io_configure() + { + + // Configure ports/pins + DDRB |= (1 << DDB4); // Set PB4 to Output for Heater (also allows SCK to operate) + + DDRC &= ~(1 << DDC2); // Set PC2 to input for rotary dip //TEMPORARY// + DDRC &= ~(1 << DDC3); // Set PC3 to input for rotary dip //TEMPORARY// + DDRC &= ~(1 << DDC4); // Set PC4 to input for rotary dip //TEMPORARY// + DDRC &= ~(1 << DDC5); // Set PC5 to input for rotary dip //TEMPORARY// + + } + uint8_t io_getModuleId() { @@ -15,17 +28,14 @@ id = 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 - PORTC |= (1 << PC4); // Pull pins on rotary dip high - PORTC |= (1 << PC5); // Pull pins on rotary dip high + PORTC |= (1 << PC2); // Pull pins on rotary dip high + PORTC |= (1 << PC3); // Pull pins on rotary dip high + PORTC |= (1 << PC4); // Pull pins on rotary dip high + PORTC |= (1 << PC5); // Pull pins on rotary dip high - //while (id == 0) // Keep reading until valid ID is read - //{ - id = ((PINC & 0b00111100) >> 2); // Read Dip Encoder + id = ((PINC & 0b00011100) >> 2); // Read Dip Encoder id = ~id; //Invert Dip reading - id = (id & 0b1111); //Mask bits - //} + id = (id & 0b0111); //Mask bits return id; } \ No newline at end of file diff --git a/slave/slave/lib/inputOutput.h b/slave/slave/lib/inputOutput.h --- a/slave/slave/lib/inputOutput.h +++ b/slave/slave/lib/inputOutput.h @@ -8,7 +8,8 @@ #ifndef IO_H_ #define IO_H_ - + + void io_configure(); uint8_t io_getModuleId(); // Get ID from rotary dip and return it. diff --git a/slave/slave/lib/led.c b/slave/slave/lib/led.c --- a/slave/slave/lib/led.c +++ b/slave/slave/lib/led.c @@ -11,10 +11,10 @@ void led_configure() { // Configure ports/pins for LEDs - DDRB |= (1 << DDB0); // Set PB0 to Output - DDRB |= (1 << DDB1); // Set PB1 to Output - DDRB |= (1 << DDB2); // Set PB2 to Output - DDRB |= (1 << DDB3); // Set PB3 to Output + DDRB |= (1 << DDB0); // Set PB0 to Output for LED0 + DDRB |= (1 << DDB1); // Set PB1 to Output for LED1 + DDRB |= (1 << DDB2); // Set PB2 to Output for LED2 + DDRB |= (1 << DDB3); // Set PB3 to Output for LED3 // Setup PWM //TODO @@ -37,4 +37,12 @@ void led_toggle(uint8_t led) { // Toggle the specified LED +} + +void led_output(uint8_t led) +{ + // Output variable to LED array + PORTB &= ~(0b1111); // Clears the bottom 4 bits of PortB + PORTB |= (led & 0b1111); // Masks variable to 4 bits and assigns it to PortB + } \ No newline at end of file diff --git a/slave/slave/lib/led.h b/slave/slave/lib/led.h --- a/slave/slave/lib/led.h +++ b/slave/slave/lib/led.h @@ -18,6 +18,7 @@ void led_on(uint8_t led); void led_off(uint8_t led); void led_toggle(uint8_t led); + void led_output(uint8_t led); #endif /* LED_H_ */ 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 @@ -46,9 +46,9 @@ void sensors_readSpiTemp() void sensors_readBoardTemp() { - int8_t temperature = i2c_read(BOARDTEMP_ADDR, 0x00); // Read only the first byte of data (we don't need the resolution here) - - boardTemp = temperature; + boardTemp = i2c_read(BOARDTEMP_ADDR, 0x00); // Read only the first byte of data (we don't need the resolution here) + boardTemp = ((boardTemp*18)/10) + (32); // Converting Celsius to Fahrenheit + boardTemp = boardTemp - 1; // Linear offset } int16_t sensors_getSpiTemp(void) // Gets spi 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 @@ -16,7 +16,6 @@ void modules_setup(uint8_t id) { - switch(id) { case 0: @@ -44,29 +43,29 @@ void modules_run(uint8_t id) { - - switch(id) - { - case 0: + sensors_readBoardTemp(); // Read board temperature sensor (Common on all slaves) (Data Read) + switch(id) + { + case 0: modules_generic(); break; - case 1: + case 1: modules_sensors(); break; - case 2: + case 2: modules_geiger(); break; - case 3: + case 3: modules_cameras(); break; - default: + default: modules_generic(); break; - } + } } @@ -121,15 +120,16 @@ void modules_sensors() { // Gathers data and performs functions for sensor daughter board + sensors_readBoardTemp(); //Data Read sensors_readSpiTemp(); //Data Read - sensors_readBoardTemp(); //Data Read + } void modules_geiger() { - // Gathers data and performs functions for geiger daughter board - // This is taken care of in interrupt + // No data gatering function needed for geiger daughter board + // This is taken care of in interrupt (See geiger.c) } diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "modules.h" #include "lib/serial.h" @@ -34,33 +35,25 @@ void micro_setup() // Generic microcontroller config options sei(); // Enable interrupts - DDRB |= (1 << DDB0); // Set PB0 to Output for LED0 - DDRB |= (1 << DDB1); // Set PB1 to Output for LED1 - DDRB |= (1 << DDB2); // Set PB2 to Output for LED2 - DDRB |= (1 << DDB3); // Set PB3 to Output for LED3 - - DDRB |= (1 << DDB4); // Set PB4 to Output for Heater (also allows SCK to operate) - - DDRC &= ~(1 << DDC2); // Set PC2 to input for rotary dip //TEMPORARY// - DDRC &= ~(1 << DDC3); // Set PC3 to input for rotary dip //TEMPORARY// - DDRC &= ~(1 << DDC4); // Set PC4 to input for rotary dip //TEMPORARY// - DDRC &= ~(1 << DDC5); // Set PC5 to input for rotary dip //TEMPORARY// - } int main(void) { - // Initialize + // Initialize micro_setup(); // Generic microcontroller config options 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 uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch - //modules_setup(moduleID); // Run setup functions for specific module - + modules_setup(moduleID); // Run setup functions for specific module + + uint8_t test; //Debug + uint8_t test2; //Debug @@ -68,39 +61,30 @@ int main(void) //PORTA |= (1 << PA1); //DEBUG///////////////ON//////////////////////////////////////////////////////////////// - //char buff[32]; //DEBUG/////////////////////////////////////////////////////////////////////////////////////// - //serial0_sendString("Starting\r\n"); + // This is just a serial output example + char buff[32]; //DEBUG/////////////////////////////////////////////////////////////////////////////////////// + serial0_sendString("Starting\r\n"); + while(1) - { - - //modules_run(moduleID); // Runs specific module functions (like data reading) - // Use program timer to run every so often. Time interval defined in config.h - -//Note to future kyle: Investigate why things lock up in when ID=1 when no node is attached and fix it so that it never frezes. + { + modules_run(moduleID); // Runs specific module functions (like data reading) + // Use program timer to run every so often. Time interval defined in config.h (TODO) + // This is just a serial output example //sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4); - //serial0_sendString(buff); + //i2c_write(RTC_ADDR, 0x05, 0x3A); //DEBUG: EXAMPLE////////////////////////////////////////////////////// - _delay_ms(10); //DEBUG + _delay_ms(10); //DEBUG///////////// - //PORTB |= (1 << PB0); //DEBUG///////////////ON//////////////////////////////////////////////////////////////// - //PORTB |= (1 << PB1); //DEBUG///////////////ON//////////////////////////////////////////////////////////////// - //PORTB |= (1 << PB2); //DEBUG///////////////ON//////////////////////////////////////////////////////////////// - //PORTB |= (1 << PB3); //DEBUG///////////////ON//////////////////////////////////////////////////////////////// - - //PORTB |= (1 << PB4); //DEBUG///////////////ON//////HEATER///////////////////////////////////////////////////// + test = geiger_getCount(); //Debug////////// + led_output(test);//DEBUG////////// - moduleID = io_getModuleId(); //Debug - - PORTB &= ~(0b1111); // Clears the bottom 4 bits of PortB - PORTB |= (moduleID & 0b1111); // Masks Module ID and assigns it to PortB - /********Examples of data reading and getting****************** x = geiger_getCpm(); //Data get @@ -111,8 +95,14 @@ int main(void) sensors_readBoardTemp(); //Data Read - ***************************************************/ + **************************************************************/ + + test2 = sensors_getBoardTemp(); //DEBUG/////////////////////////////////////////////////////////////////////////// + + + sprintf(buff, "|ModuleID: %u |BoardTemp: %u |Seconds: %u\r\n",moduleID,test2,test); //DEBUG + serial0_sendString(buff); //DEBUG }