# HG changeset patch # User kripperger@CL-SEC241-09.cedarville.edu # Date 2012-11-28 11:49:58 # Node ID dc6296adf348d548d0915c20a181ad8f437d3ca9 # Parent 79192435782d96b13b39cc3f70a1e6c3c992b91f External Temperature Sensor Output Config. 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,14 +14,14 @@ #include "sensors.h" #include "spi.h" -#include "serial.h" //Debug +#include "serial.h" //DEBUG//////////////////////////////////////////////////////////////////////////// int16_t readSpiTemp() { - char buff[32];//DEBUG + char buff[32]; //DEBUG//////////////////////////////////////////////////////////////////////// - // select TEMP wait 100 microseconds then read four bytes + // Select TEMP wait 100 microseconds then read four bytes SELECT_TEMP; _delay_us(100); uint8_t one = send_spi(0xFF); @@ -34,13 +34,14 @@ int16_t readSpiTemp() DESELECT_TEMP; uint8_t error = (two & 0x01); + int16_t temperature = ((one<<4)|(two>>4)); + temperature = (temperature & (0x0800)) ? (temperature & 0xF000) : temperature; // Sign extend - int16_t temperature = ((one<<6)&(two>>2)); - temperature = (temperature & (0x2000)) ? (temperature & 0xC000) : temperature; // Sign extend + temperature = error ? 0x00DE : temperature; // Error Condition. If error is detected output is set to 222 degrees (0x00DE) - sprintf(buff, "log: %u,%u,%u,%u\r\n", one,two,three,four); - serial0_sendString(buff); + sprintf(buff, "Temperature: %d Error: %u\r\n", temperature,error); //DEBUG///////////////////////////// + serial0_sendString(buff); //DEBUG///////////////////////////// return temperature; } \ No newline at end of file