Changeset - dc6296adf348
[Not reviewed]
default
0 1 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2012-11-28 11:49:58
kripperger@CL-SEC241-09.cedarville.edu
External Temperature Sensor Output Config.
1 file changed with 8 insertions and 7 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/sensors.c
Show inline comments
 
@@ -11,36 +11,37 @@
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#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);
 
	_delay_us(100);
 
	uint8_t two = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t three = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t four = send_spi(0xFF);
 
	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
0 comments (0 inline, 0 general)