Changeset - e26676bc539c
[Not reviewed]
default
0 1 0
kripperger@CL-SEC241-09.cedarville.edu - 13 years ago 2012-11-28 11:58:22
kripperger@CL-SEC241-09.cedarville.edu
Optimization (temp sense)
1 file changed with 2 insertions and 3 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/sensors.c
Show inline comments
 
/*
 
 * sensors.c
 
 *
 
 * Created: 11/19/2012 9:25:01 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "sensors.h"
 
#include "spi.h"
 
 
#include "serial.h"	//DEBUG////////////////////////////////////////////////////////////////////////////
 
 
int16_t readSpiTemp()
 
{
 

	
 
	char buff[32];		//DEBUG////////////////////////////////////////////////////////////////////////
 

	
 
	// 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
 
	
 
	temperature = error ? 0x00DE : temperature;	// Error Condition. If error is detected output is set to 222 degrees (0x00DE)
 
	temperature = (two & 0x01) ? 0x00DE : temperature;	// Error Condition. If error is detected output is set to 222 degrees (0x00DE)
 
	
 
	
 
			sprintf(buff, "Temperature: %d     Error: %u\r\n", temperature,error);		//DEBUG/////////////////////////////
 
			sprintf(buff, "Temperature: %d     Error: %u\r\n", temperature,(two & 0x01));		//DEBUG/////////////////////////////
 
			serial0_sendString(buff);													//DEBUG/////////////////////////////
 
	
 
	return temperature;
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)