master
Paul Goeser 15 years ago
parent 25e646555c
commit 505405c2c8

@ -0,0 +1,7 @@
#define SPI_BAUDRATE 1000000
#ifdef SPI_MASTER
#undef SPI_MASTER
#endif //SPI_MASTER
//#define SPI_SS_PORT D
//#define SPI_SS_PIN 7

@ -1,8 +1,12 @@
#include <avr/io.h>
#include <stdint.h>
#include <math.h>
#include <avr/interrupt.h>
#include "main.h"
#include <spi.h>
uint16_t *spi_proto_globals8[] = {
@ -80,6 +84,10 @@ void spi_init(){
#endif
SPSR = spsr;
SPCR = spcr;
#ifndef SPI_MASTER
SPCR |= _BV(SPIE); //enable interrupts
#endif
}
@ -114,7 +122,7 @@ void spi_mst_read(uint8_t len, uint8_t *data){
void spi_sla_handle_packet(){
void __attribute__((always_inline)) spi_sla_handle_packet(){
// TODO: make slave not hangup in case of partial read
uint8_t opcode, addr, do_write;
uint16_t data;
@ -141,7 +149,13 @@ void spi_sla_handle_packet(){
}
}
#ifndef SPI_MASTER
ISR(SPI_vect){
SPCR &= ~(_BV(SPIE)); //disable spi interrupts
spi_sla_handle_packet();
SPCR |= _BV(SPIE);
}
#endif //not SPI_MASTER

@ -3,12 +3,7 @@
#include "spi_proto.h"
#define SPI_BAUDRATE 1000000
#define SPI_MASTER 1
#define SPI_READBUF_LEN 32
#define SPI_SS_PORT D
#define SPI_SS_PIN 7
#include "spi_config.h"
// copied/adapted from usbdrv.h

@ -24,7 +24,7 @@ flash: all
avrdude -c usbasp -p m88 -U flash:w:firmware.hex
fuses:
avrdude -c usbasp -p m88 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m -U efuse:w:0xf9:m
avrdude -c usbasp -p m88 -U lfuse:w:0xe2:m -U hfuse:w:0xdf:m
## what are the source dependencies

@ -0,0 +1,5 @@
#define SPI_BAUDRATE 1000000
#define SPI_MASTER
#define SPI_SS_PORT D
#define SPI_SS_PIN 7
Loading…
Cancel
Save