PIC Microcontoller Input / Output Methods

for SPI

Tony Kübek, Flintab AB says:

According to the data for the F876, regarding the SPI module I paraphrase ( DS30292-A page 66 ):
" - SDI is automatically controlled by the SPI module "

Then after the table it states:

"Any serial port function that is not desired may be overridden by programming the ....TRIS register to the opposite value"

I just spent 3 hour tracking down the obvious bug of setting the SDI as an output ( as I only read the first paragraph ). Is it only me ( I'm not native English ) but aren't these statements actually wrong ? ( they opposite each other ).

Anyway, if anyone cares here the lesson: ALWAYS ( exept UART TX/RX ;-) ) set the pin they way you will use it, i.e. outputs ( ex. SDO ) should have TRIS bit cleared, inputs ( ex. SDI ) should have TRIS bit set.

Galen O'Grady askes

I am using a 16C63 as an SPI slave (with SS* enabled). When doing multi-byte transfers, does the SS* pin need to be cycled (by the master) after each byte, or can it remain low for the entire transfer?

David Kott [dkott at TESTPROD.COM] answers:

No. You do not need to cycle it between each byte transfer. To wit, to test this notion, setup your SPI in slave mode with SS control enabled, and ground the SS line. The SPI will function identically, provided you are transferring 8 bits per word (as you implied when you described the data as a "byte")

Recently, I was having an issue with my SPI Slave code. I had SS control enabled. However, it seems that the device sourcing the SS signal was not conforming to the timing requirements for the PIC. Merely grounding the SS line allowed the SPI subsystem to function properly. Subsequently, I configured my SPI to not use SS control.

The PICmicro Mid-Range MCU Family manual says this:

"When the SPI is in Slave Mode with SS pin control enabled, (SSPCON<3:0> = 0100) the SPI module will reset if the SS pin is set to VDD. If the SPI is used in Slave Mode with the CKE bit is set, then the SS pin control must be enabled. When the SPI module resets, the bit counter is forced to 0. This can be done by either by forcing the SS pin to a high level or clearing the SSPEN bit..." (c) Microchip Technology Inc.

Sample 16F876 code with SPI master setup as well as RS232, etc... by Tony Kübek

SPI interface to AD7730 by Tony Kübek

SPI Slave for PIC 16c73 by Josef Hanzal, M. S.

SPI to MAX7221 LED Driver by Marcel Birthelmer

cover"Serial PIC'n : PIC Microcontroller Serial Communications" by David Benson

General SPI (not PIC specific)

Questions:

See also:

Archive:

Comments:

Interested: