Files @ 79192435782d
Branch filter:

Location: seniordesign-firmware/slave/slave/lib/sensors.c

kripperger@CL-SEC241-09.cedarville.edu
Spi temp
/*
 * 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<<6)&(two>>2));
	temperature = (temperature & (0x2000)) ? (temperature & 0xC000) : temperature;	// Sign extend
	
	
			sprintf(buff, "log: %u,%u,%u,%u\r\n", one,two,three,four);
			serial0_sendString(buff);
	
	return temperature;
}