diff --git a/slave/slave/config.h b/slave/slave/config.h --- a/slave/slave/config.h +++ b/slave/slave/config.h @@ -15,10 +15,10 @@ #define USART1_BAUDRATE 115200 //I2C Addresses - #define BOARDTEMP_ADDR 0xA5 //THIS VALUE IS WRONG + #define BOARDTEMP_ADDR 0x90 // Read 0x91 - Write 0x90 #define PRESSURE_ADDR 0xA1 //THIS VALUE IS WRONG #define HUMID_ADDR 0xA4 //THIS VALUE IS WRONG - #define RTC_ADDR 0xA2 //DEBUG //read A3 - write A2 + #define RTC_ADDR 0xA2 //DEBUG [Used for testing] // Read 0xA3 - Write 0xA2 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 @@ -38,7 +38,7 @@ ISR(PCINT0_vect) // Interrupt on PA0 counts++; // Increment counter. } -uint16_t geiger_getCpm() +inline uint16_t geiger_getCpm() { return cpm; } \ No newline at end of file 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_ -uint16_t geiger_getCpm(); +inline uint16_t geiger_getCpm(); #endif /* GEIGER_H_ */ \ No newline at end of file diff --git a/slave/slave/lib/i2c.c b/slave/slave/lib/i2c.c --- a/slave/slave/lib/i2c.c +++ b/slave/slave/lib/i2c.c @@ -15,7 +15,6 @@ #define SCL_CLOCK 100000L - /************************************************************************* Initialization of the I2C bus interface. Need to be called only once *************************************************************************/ diff --git a/slave/slave/lib/i2c.h b/slave/slave/lib/i2c.h --- a/slave/slave/lib/i2c.h +++ b/slave/slave/lib/i2c.h @@ -9,25 +9,20 @@ #ifndef I2C_H_ #define I2C_H_ - #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304 #error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !" #endif - #include /** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */ #define I2C_READ 1 - /** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */ #define I2C_WRITE 0 - void i2c_init(void); //initialize the I2C master interace. Need to be called only once - void i2c_stop(void); //Terminates the data transfer and releases the I2C bus unsigned char i2c_start(unsigned char addr); //Issues a start condition and sends address and transfer direction 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 @@ -8,9 +8,9 @@ #include uint8_t io_getModuleId() { + // Get ID from rotary dip and return it. uint8_t id; - id = 0; //DEBUG return id; 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 @@ -12,5 +12,4 @@ uint8_t io_getModuleId(); // Get ID from rotary dip and return it. - #endif /* IO_H_ */ \ No newline at end of file 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 @@ -16,6 +16,8 @@ void led_configure() DDRB |= (1 << DDRB2); // Set PB2 to Output DDRB |= (1 << DDRB3); // Set PB3 to Output + // Setup PWM + //TODO } 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 @@ -14,13 +14,12 @@ #include "sensors.h" #include "spi.h" -#include "serial.h" //DEBUG//////////////////////////////////////////////////////////////////////////// +int16_t spiTemp; // Thermocouple Temperature (from spi) +int8_t boardTemp; // Board Temperature (from i2c) -int16_t readSpiTemp() + +void sensors_readSpiTemp() { - - char buff[32]; //DEBUG//////////////////////////////////////////////////////////////////////// - // Select TEMP wait 100 microseconds then read four bytes SELECT_TEMP; _delay_us(100); @@ -33,14 +32,32 @@ int16_t readSpiTemp() uint8_t four = send_spi(0xFF); DESELECT_TEMP; - int16_t temperature = ((one<<4)|(two>>4)); + int16_t temperature = ((one<<4)|(two>>4)); // Shift and place into larger int. (Cuts off Decimal) temperature = (temperature & (0x0800)) ? (temperature & 0xF000) : temperature; // Sign extend + //int16_t temperature = ((one<<6)|(two>>2)); // Shift and place into larger int. (Includes Decimal) + //temperature = (temperature & (0x2000)) ? (temperature & 0xC000) : temperature; // Sign extend + temperature = (two & 0x01) ? 0x00DE : temperature; // Error Condition. If error is detected output is set to 222 degrees (0x00DE) + // Note: Temperature still needs to be scaled in order to be accurate (eg. boil water). Do this before implementing. + spiTemp = temperature; +} + +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) - sprintf(buff, "Temperature: %d Error: %u\r\n", temperature,(two & 0x01)); //DEBUG///////////////////////////// - serial0_sendString(buff); //DEBUG///////////////////////////// - - return temperature; -} \ No newline at end of file + boardTemp = temperature; +} + +int16_t sensors_getSpiTemp(void) // Gets spi temperature from variable +{ + return spiTemp; +} + +int8_t sensors_getBoardTemp(void) // Gets board temperature from variable +{ + return boardTemp; +} + 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 @@ -9,8 +9,11 @@ #ifndef SENSORS_H_ #define SENSORS_H_ -int16_t readSpiTemp(void); +void sensors_readSpiTemp(void); // Reads spi temperature +void sensors_readBoardTemp(void); // Reads board temperature +int16_t sensors_getSpiTemp(void); // Gets spi temperature from variable +int8_t sensors_getBoardTemp(void); // Gets board temperature from variable #endif /* SENSORS_H_ */ \ No newline at end of file diff --git a/slave/slave/lib/spi.c b/slave/slave/lib/spi.c --- a/slave/slave/lib/spi.c +++ b/slave/slave/lib/spi.c @@ -13,8 +13,6 @@ void setup_spi() { - DESELECT_TEMP; - // specify pin directions for SPI pins on port B DDRB |= (1< #include #include "modules.h" -#include "lib/serial.h" //DEBUG +#include "lib/serial.h" #include "lib/led.h" #include "lib/inputOutput.h" #include "lib/i2c.h" @@ -32,8 +32,9 @@ void micro_setup() { // Generic microcontroller config options - sei(); - DDRB |= (1 << DDRB4); // Set PB4 to Output for Heater + sei(); // Enable interrupts + DDRB |= (1 << DDRB4); // Set PB4 to Output for Heater (also allows SCK to operate) + } @@ -41,48 +42,53 @@ int main(void) { // Initialize micro_setup(); // Generic microcontroller config options - led_configure(); // + led_configure(); // Configure ports and registers for LED operation i2c_init(); // Setup I2C - serial0_setup(); // Config serial ports //DEBUG + serial0_setup(); // Config serial port uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch - moduleID=1; //DEBUG/////////////////////////////////////////////////////////////////////////////////////////// - modules_setup(moduleID); + //moduleID=1; //DEBUG/////////////////////////////////////////////////////////////////////////////////////////// + modules_setup(moduleID); // Run setup functions for specific module - - //char buff[32]; //DEBUG/////////////////////////////////////////////////////////////////////////////////////// - uint8_t temp; //DEBUG/////////////////////////////////////////////////////////////////////////////////////// + //PORTA &= ~(1 << PA1); //DEBUG////////////////OFF/////////////////////////////////////////////////////////////// + //PORTA |= (1 << PA1); //DEBUG///////////////ON//////////////////////////////////////////////////////////////// - //PORTA &= ~(1 << PA1); //DEBUG/////////////////////////////////////////////////////////////////////////////// - //PORTA |= (1 << PA1); //DEBUG/////////////////////////////////////////////////////////////////////////////// - //PORTA=0;//DEBUG///////////////////////////////////////////////////////////////////////////////////////////// - temp=0;//DEBUG//////////////////////////////////////////////////////////////////////////////////////////////// + //char buff[32]; //DEBUG/////////////////////////////////////////////////////////////////////////////////////// //serial0_sendString("Starting\r\n"); while(1) { - - modules_run(moduleID); + + modules_run(moduleID); // Runs specific module functions (like data reading) + // Use program timer to run every so often. Time interval defined in config.h + + //sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4); //serial0_sendString(buff); - temp=readSpiTemp(); - - //serial_SendCommand('0','A',0,0); //DEBUG: EXAMPLE////////////////////////////////////////////////////// - //i2c_write(RTC_ADDR, 0x05, 0x3A); //DEBUG: EXAMPLE////////////////////////////////////////////////////// - - _delay_ms(10); - //temp = i2c_read(RTC_ADDR, 0x02); //DEBUG: EXAMPLE: seconds///////////////////////////////////////// - - // PORTA = temp; //DEBUG/////////////////////////////////////////////////////////////////////////////// - - + + _delay_ms(10); //DEBUG + + + + + /********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 + + + ***************************************************/ + }