# HG changeset patch # User kripperger@CL-SEC241-09.cedarville.edu # Date 2012-11-27 21:55:17 # Node ID 79192435782d96b13b39cc3f70a1e6c3c992b91f # Parent 48acfcb35ad3ace5a7cf7cf4377e8e49b0f12dd6 Spi temp diff --git a/slave/slave/config.h b/slave/slave/config.h --- a/slave/slave/config.h +++ b/slave/slave/config.h @@ -10,8 +10,9 @@ #define CONFIG_H_ #define F_CPU 11059200 - #define USART_BAUDRATE 19200 +#define USART0_BAUDRATE 115200 +#define USART1_BAUDRATE 115200 //I2C Addresses #define BOARDTEMP_ADDR 0xA5 //THIS VALUE IS WRONG 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 @@ -1,33 +1,38 @@ /* - * led.c - * - * Created: 10/25/2012 10:03:22 PM - * Author: mkanning - */ +* led.c +* +* Created: 10/25/2012 10:03:22 PM +* Author: mkanning +*/ - #include - #include "led.h" - - void led_configure() - { - // Configure ports/pins for LEDs - - } +#include +#include "led.h" - void led_on(uint8_t led) - { - // Turn the specified LED on - - } +void led_configure() +{ + // Configure ports/pins for LEDs + DDRB |= (1 << DDRB0); // Set PB0 to Output + DDRB |= (1 << DDRB1); // Set PB1 to Output + DDRB |= (1 << DDRB2); // Set PB2 to Output + DDRB |= (1 << DDRB3); // Set PB3 to Output + + +} - void led_off(uint8_t led) - { - // Turn the specified LED off +void led_on(uint8_t led) +{ + // Turn the specified LED on - } +} - void led_toggle(uint8_t led) - { - // Toggle the specified LED +void led_off(uint8_t led) +{ + // Turn the specified LED off - } \ No newline at end of file +} + +void led_toggle(uint8_t led) +{ + // Toggle the specified LED + +} \ No newline at end of file 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,22 +14,33 @@ #include "sensors.h" #include "spi.h" +#include "serial.h" //Debug -uint8_t readSpiTemp() +int16_t readSpiTemp() { + + char buff[32];//DEBUG + // select TEMP wait 100 microseconds then read four bytes SELECT_TEMP; _delay_us(100); - unsigned char one = send_spi(0xFF); + uint8_t one = send_spi(0xFF); _delay_us(100); - unsigned char two = send_spi(0xFF); + uint8_t two = send_spi(0xFF); _delay_us(100); - unsigned char three = send_spi(0xFF); + uint8_t three = send_spi(0xFF); _delay_us(100); - unsigned char four = send_spi(0xFF); + uint8_t four = send_spi(0xFF); DESELECT_TEMP; + uint8_t error = (two & 0x01); - //return ((0x1F & one) << 7) | (two >> 1); - return 0; //DEBUG + 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; } \ No newline at end of file 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,7 +9,7 @@ #ifndef SENSORS_H_ #define SENSORS_H_ -uint8_t readSpiTemp(void); +int16_t readSpiTemp(void); 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 @@ -11,31 +11,28 @@ #include "spi.h" -void setup_spi(uint8_t mode, int dord, int interrupt, uint8_t clock) +void setup_spi() { DESELECT_TEMP; - // specify pin directions for SPI pins on port B - if (clock == SPI_SLAVE) { // if slave SS and SCK is input - DDRB &= ~(1< -#define SPI_SS_PIN PORTA1 -#define SPI_SCK_PIN PORTB7 -#define SPI_MOSI_PIN PORTB5 -#define SPI_MISO_PIN PORTB6 +#define SPI_SS_PIN PA1 +#define SPI_SCK_PIN PB7 +#define SPI_MOSI_PIN PB5 +#define SPI_MISO_PIN PB6 #define SELECT_TEMP PORTA &= ~(1< #include #include "modules.h" -//#include "lib/serial.h" //Not made yet +#include "lib/serial.h" //DEBUG #include "lib/led.h" #include "lib/inputOutput.h" #include "lib/i2c.h" @@ -32,10 +32,8 @@ void micro_setup() { // Generic microcontroller config options - - //DDRA = 0xFE; //PORTA is output //DEBUG - - + sei(); + DDRB |= (1 << DDRB4); // Set PB4 to Output for Heater } @@ -45,15 +43,15 @@ int main(void) micro_setup(); // Generic microcontroller config options led_configure(); // i2c_init(); // Setup I2C - //serial_setup(); // Config serial ports + serial0_setup(); // Config serial ports //DEBUG uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch - //moduleID=2; //DEBUG/////////////////////////////////////////////////////////////////////////////////////////// + moduleID=1; //DEBUG/////////////////////////////////////////////////////////////////////////////////////////// modules_setup(moduleID); - + //char buff[32]; //DEBUG/////////////////////////////////////////////////////////////////////////////////////// uint8_t temp; //DEBUG/////////////////////////////////////////////////////////////////////////////////////// @@ -62,6 +60,7 @@ int main(void) //PORTA |= (1 << PA1); //DEBUG/////////////////////////////////////////////////////////////////////////////// //PORTA=0;//DEBUG///////////////////////////////////////////////////////////////////////////////////////////// temp=0;//DEBUG//////////////////////////////////////////////////////////////////////////////////////////////// + //serial0_sendString("Starting\r\n"); while(1) { @@ -69,9 +68,10 @@ int main(void) modules_run(moduleID); - + //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////////////////////////////////////////////////////// diff --git a/slave/slave/slave.cproj b/slave/slave/slave.cproj --- a/slave/slave/slave.cproj +++ b/slave/slave/slave.cproj @@ -150,6 +150,12 @@ compile + + compile + + + compile + compile