aboutsummaryrefslogtreecommitdiffstats
path: root/fw/spi.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-08-16 14:59:36 -0230
committerSam Anthony <sam@samanthony.xyz>2025-08-16 14:59:36 -0230
commitee61ef56f775e44fd0b857a960102148910e6dce (patch)
tree9063a6a74af17d9a0ef45392dc28eaf770a22d69 /fw/spi.c
parent478a91bd82e27d8d6b2e597fd659e484ca6b205a (diff)
downloadcan-gauge-interface-ee61ef56f775e44fd0b857a960102148910e6dce.zip
usbcom: modified libusb example
Diffstat (limited to 'fw/spi.c')
-rw-r--r--fw/spi.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/fw/spi.c b/fw/spi.c
new file mode 100644
index 0000000..1793c4d
--- /dev/null
+++ b/fw/spi.c
@@ -0,0 +1,30 @@
+#include <xc.h>
+
+#include <stdint.h>
+
+#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;
+}