Information Technology Reference
In-Depth Information
Table 4-4: The PIC18F4550's built-in SPI port uses three port pins (plus
additional pins as needed for CS outputs).
Port
Bit
Signal on PIC18F4550
Connection to MultiMediaCard
PORTC
7
SDO
DataIn
PORTB
0
SDI
DataOut
PORTB
1
SCK
SCLK
extern volatile near struct {
unsigned SSPM0:1;
unsigned SSPM1:1;
unsigned SSPM2:1;
unsigned SSPM3:1;
unsigned CKP:1;
unsigned SSPEN:1;
unsigned SSPOV:1;
unsigned WCOL:1;
} SSPCON1bits;
extern volatile near struct {
unsigned BF:1;
unsigned UA:1;
unsigned R_W:1;
unsigned S:1;
unsigned P:1;
unsigned D_A:1;
unsigned CKE:1;
unsigned SMP:1;
} SSPSTATbits;
Configuring the Port
Before using the SPI port, firmware must also configure the port bits as
inputs or outputs as appropriate and must configure the SPI port in the reg-
isters. The Microchip C18 compiler libraries include an OpenSPI function
that performs these tasks. The function accepts three parameters:
sync_mode sets the mode (bits 3..0 in SSPCON1), bus_mode sets the trans-
mit mode (CKE) in SSPSTAT and clock polarity (CKP) in SSPCON1, and
smp_phase sets the receive mode (SMP) in SSPSTAT.
Search WWH ::




Custom Search