forked from interactive-matter/Blinken-Button
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPI support (slave): receive and display frames
- Loading branch information
Showing
5 changed files
with
79 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* SPI support | ||
*/ | ||
|
||
#include <avr/io.h> | ||
#include <avr/interrupt.h> | ||
#include <util/delay.h> | ||
|
||
#include "display.h" | ||
|
||
#define SS PB2 | ||
#define MOSI PB3 | ||
#define MISO PB4 | ||
#define SCK PB5 | ||
|
||
// Sprite buffer | ||
uint8_t sprite[8] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
uint8_t i = 0; | ||
|
||
/** | ||
* Initialize SPI in slave mode | ||
*/ | ||
void spi_init(void) | ||
{ | ||
volatile char IOReg; | ||
|
||
// Set MISO output | ||
DDRB |= (1<<MISO); | ||
|
||
// Enable SPI (slave) and SPI interrupts | ||
SPCR = (1<<SPE) | (1<<SPIE); | ||
|
||
// Clear SPIF bit in SPSR | ||
IOReg = SPSR; | ||
IOReg = SPDR; | ||
} | ||
|
||
/** | ||
* SPI interrupt routine | ||
*/ | ||
ISR(SPI_STC_vect) | ||
{ | ||
// Save sprite into buffer | ||
sprite[i++] = SPDR; | ||
|
||
if (i == 8) { | ||
// Sprite completed | ||
i = 0; | ||
|
||
display_load_sprite(sprite); | ||
display_advance_buffer(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* SPI support | ||
*/ | ||
|
||
#ifndef SPI_H_ | ||
#define SPI_H_ | ||
|
||
void spi_init(void); | ||
|
||
#endif /* SPI_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters