From 4a99ede565fa61005f2a6202669adaa87a8ce0ee Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 16 Aug 2025 12:19:09 -0230 Subject: spi and eeprom modules --- sw/spi.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sw/spi.c (limited to 'sw/spi.c') diff --git a/sw/spi.c b/sw/spi.c new file mode 100644 index 0000000..1793c4d --- /dev/null +++ b/sw/spi.c @@ -0,0 +1,30 @@ +#include + +#include + +#include "sys.h" +#include "types.h" + +#include "spi.h" + +void +spiInit(void) { + U8 junk; + + TRISBbits.TRISB4 = IN; // SDI + TRISCbits.TRISC7 = OUT; // SDO + TRISBbits.TRISB6 = OUT; // SCK + + SSPSTAT = 0x00; + SSPCON1 = 0x01; // FOSC/16 => 3MHz SPI clock + SSPCON1bits.SSPEN = 1; // enable + junk = SSPBUF; // dummy read to clear BF + (void)junk; +} + +U8 +spiTx(U8 c) { + SSPBUF = c; + while (!SSPSTATbits.BF) {} + return SSPBUF; +} -- cgit v1.2.3