aboutsummaryrefslogtreecommitdiffstats
path: root/fw/spi.c
blob: 9198ab1d78953f3be6ba931953cdbae53db36038 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <xc.h>

#include <stdint.h>

#include "system.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 = 0x22; // FOSC/64 => 750kHz SPI clock
	junk = SSPBUF; // dummy read to clear BF
	(void)junk;
}

U8
spiTx(U8 c) {
	SSPBUF = c;
	while (!SSPSTATbits.BF) {}
	return SSPBUF;
}