diff --git a/slave/slave/lib/inputOutput.c b/slave/slave/lib/inputOutput.c --- a/slave/slave/lib/inputOutput.c +++ b/slave/slave/lib/inputOutput.c @@ -8,8 +8,7 @@ #include uint8_t io_getModuleId() { - //get ID from rotary dip and return it. - + // Get ID from rotary dip and return it. uint8_t id; id = 0; //DEBUG diff --git a/slave/slave/lib/inputOutput.h b/slave/slave/lib/inputOutput.h --- a/slave/slave/lib/inputOutput.h +++ b/slave/slave/lib/inputOutput.h @@ -9,7 +9,7 @@ #ifndef IO_H_ #define IO_H_ - uint8_t io_getModuleId(); //get ID from rotary dip and return it. + uint8_t io_getModuleId(); // Get ID from rotary dip and return it. diff --git a/slave/slave/lib/spi.c b/slave/slave/lib/spi.c new file mode 100644 --- /dev/null +++ b/slave/slave/lib/spi.c @@ -0,0 +1,55 @@ +/* + * + * + * + * + * + * + */ + + +#include "spi.h" + + +void setup_spi(uint8_t mode, int dord, int interrupt, uint8_t clock) +{ + // 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 PORTB4 +#define SPI_SCK_PIN PORTB7 +#define SPI_MOSI_PIN PORTB5 +#define SPI_MISO_PIN PORTB6 + + +// SPI clock modes +#define SPI_MODE_0 0x00 /* Sample (Rising) Setup (Falling) CPOL=0, CPHA=0 */ +#define SPI_MODE_1 0x01 /* Setup (Rising) Sample (Falling) CPOL=0, CPHA=1 */ +#define SPI_MODE_2 0x02 /* Sample (Falling) Setup (Rising) CPOL=1, CPHA=0 */ +#define SPI_MODE_3 0x03 /* Setup (Falling) Sample (Rising) CPOL=1, CPHA=1 */ + +// data direction +#define SPI_LSB 1 /* send least significant bit (bit 0) first */ +#define SPI_MSB 0 /* send most significant bit (bit 7) first */ + +// whether to raise interrupt when data received (SPIF bit received) +#define SPI_NO_INTERRUPT 0 +#define SPI_INTERRUPT 1 + +// slave or master with clock diviser +#define SPI_SLAVE 0xF0 +#define SPI_MSTR_CLK4 0x00 /* chip clock/4 */ +#define SPI_MSTR_CLK16 0x01 /* chip clock/16 */ +#define SPI_MSTR_CLK64 0x02 /* chip clock/64 */ +#define SPI_MSTR_CLK128 0x03 /* chip clock/128 */ +#define SPI_MSTR_CLK2 0x04 /* chip clock/2 */ +#define SPI_MSTR_CLK8 0x05 /* chip clock/8 */ +#define SPI_MSTR_CLK32 0x06 /* chip clock/32 */ + + + +// setup spi +void setup_spi(uint8_t mode, // timing mode SPI_MODE[0-4] + int dord, // data direction SPI_LSB|SPI_MSB + int interrupt, // whether to raise interrupt on recieve + uint8_t clock); // clock diviser + +// disable spi +void disable_spi(void); + +// send and receive a byte of data (master mode) +uint8_t send_spi(uint8_t out); + +// receive the byte of data waiting on the SPI buffer and +// set the next byte to transfer - for use in slave mode +// when interrupts are enabled. +uint8_t received_from_spi(uint8_t out); + + + +#endif /* SPI_H_ */ + diff --git a/slave/slave/modules.c b/slave/slave/modules.c --- a/slave/slave/modules.c +++ b/slave/slave/modules.c @@ -5,28 +5,113 @@ * Author: kripperger */ + #include #include #include "modules.h" + void modules_setup(uint8_t id) + { + + switch(id) + { + case 0: + modules_generic_setup(); + break; + + case 1: + modules_sensors_setup(); + break; + + case 2: + modules_geiger_setup(); + break; + + case 3: + modules_cameras_setup(); + break; + + default: + modules_generic_setup(); + break; + } + + } + + void modules_run(uint8_t id) + { + + switch(id) + { + case 0: + modules_generic(); + break; + + case 1: + modules_sensors(); + break; + + case 2: + modules_geiger(); + break; + + case 3: + modules_cameras(); + break; + + default: + modules_generic(); + break; + } + + } + + + void modules_generic_setup() + { + + } + + void modules_sensors_setup() + { + + } + + void modules_geiger_setup() + { + + } + + void modules_cameras_setup() + { + + } + + + + void modules_generic() { - + // Gathers data and performs functions for generic daughter board + } void modules_sensors() { + // Gathers data and performs functions for sensor daughter board } void modules_geiger() { + // Gathers data and performs functions for geiger daughter board } void modules_cameras() { + // Gathers data and performs functions for cameras daughter board } \ No newline at end of file diff --git a/slave/slave/modules.h b/slave/slave/modules.h --- a/slave/slave/modules.h +++ b/slave/slave/modules.h @@ -9,6 +9,16 @@ #ifndef MODULES_H_ #define MODULES_H_ + void modules_setup(uint8_t id); + void modules_run(uint8_t id); + + // Setup functions for microcontroller configuration per specific daughter board + void modules_generic_setup(); + void modules_sensors_setup(); + void modules_geiger_setup(); + void modules_cameras_setup(); + + // Data acquisition for specific daughter board void modules_generic(); void modules_sensors(); void modules_geiger(); diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -12,18 +12,18 @@ #include "config.h" -#include "modules.h" #include #include #include #include +#include "modules.h" //#include "lib/serial.h" //Not made yet #include "lib/led.h" #include "lib/inputOutput.h" #include "lib/i2c.h" - +#include "lib/spi.h" void micro_setup() { @@ -31,6 +31,7 @@ void micro_setup() DDRA=0xFF; //PORTA is output //DEBUG + } @@ -44,6 +45,8 @@ int main(void) //serial_setup(); // Config serial ports uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch + modules_setup(moduleID); + uint8_t temp; //DEBUG @@ -53,39 +56,26 @@ int main(void) while(1) { - - //serial_SendCommand('0','A',0,0); //DEBUG: EXAMPLE - - //i2c_write(RTC_ADDR, 0x05, 0x3A); //DEBUG: EXAMPLE + + + modules_run(moduleID); - _delay_ms(10); - temp = i2c_read(RTC_ADDR, 0x02); //DEBUG: EXAMPLE: seconds - - PORTA = temp; + + + + - switch(moduleID) - { - case 0: - - break; - - case 1: - - break; - - case 2: - - break; - - case 3: - - break; - - default: - - break; - } + + + //serial_SendCommand('0','A',0,0); //DEBUG: EXAMPLE + + //i2c_write(RTC_ADDR, 0x05, 0x3A); //DEBUG: EXAMPLE + + _delay_ms(10); + temp = i2c_read(RTC_ADDR, 0x02); //DEBUG: EXAMPLE: seconds + + PORTA = temp; //DEBUG diff --git a/slave/slave/slave.cproj b/slave/slave/slave.cproj --- a/slave/slave/slave.cproj +++ b/slave/slave/slave.cproj @@ -132,6 +132,12 @@ compile + + compile + + + compile + compile