Information Technology Reference
In-Depth Information
Table 4-6: The SSPCON1 register contains configuration and status information
for the SPI port.
Bit
Name
Description
3..0
SSPM3..
SSPM0
Synchronous serial port mode select:
0101: slave, clock = SCK input, /SS disabled
0100: slave, clock = SCK input, /SS enabled
0011: master, clock = (TMR2 output) / 2
0010: master, clock = FOSC / 64
0001: master, clock = FOSC / 16
0000: master, clock = FOSC / 4
4
CKP
Clock polarity: 1 = clock idle state is high; 0 = clock idle state is low.
5
SSPEN
Synchronous serial port enable. 1= enabled; 0 = disabled.
6
SSPOV
Receive overflow.
Slave mode: 1 = overflow. 0 = no overflow.
Master mode: 0.
7
WCOL
Write collision detect.
1 = SSPBUF was written to while transmitting.
0 = no collision.
lision, the byte being sent continues to transmit, but the attempted new
write operation fails and the WCOL bit in SSPCON1 is set to 1. After writ-
ing a byte, device firmware should check WCOL to verify that the write was
successful and if not, clear the bit and try again.
Microchip's C18 compiler libraries include a WriteSPI function, which
writes a byte to the SPI bus. The function accepts a byte to write (data_out),
writes the byte to SSPBUF, and checks WCOL. If there was no collision, the
function waits for the byte to transmit. A return value of zero means the
write was successful.
unsigned char WriteSPI( unsigned char data_out )
{
// Write the passed byte to the SPI buffer.
SSPBUF = data_out;
if ( SSPCON1 & 0x80 )
// WCOL = 1, so there was a write collision.
return ( -1 );
Search WWH ::




Custom Search