Wednesday, 9 July 2014

Microchip have released a new family of 18F microcontroller devices that support a new feature called PPS-Lite. Peripheral Pin Select (PPS) allows the various digital IO functions such as UARTs onto pins of your choice.

In this post I will show you how to communicate between two PICs using SPI and how to set up the PPS registers.

Schematic

Both PICs are the same type 18F65J94, one is designated the Master the other the SLAVE. The master and slave SPI pins are connected as shown in the image below. Note that here we do not use the slave select line.

Source Code

I wanted to be able to use the same binary for both PICs to help make programming of both chips easier as there is only one choice of hex file. The PICs will check pin E1 to see if they are a master or slave and behave accordingly.

One difficulty I faced is that the Master SCLK is an output and the Slave SCLK is an input. So SCLK is actually two different hardware functions SCLKOUT and SCLKIN. PPS uses two types of registers, output and input, so I needed to set the master clock pin to output register RPOR23 and the slave to input register RPINR8. Luckily the CCS compiler makes setting up these registers easy and I was able to use the same code/binary for both pics:

About Me

Pig Dog Bay was born in an inn deep in the Staffordshire moorlands. He lived in a small box under the pool table and was fed on pork scratchings left in the ash trays.

One day a raucous rock band called Motorhead played at the inn causing mayhem, so Pig Dog spied his chance and had it away on his trotters.

The nights were cold and after many days of trotting, a weary Pig Dog took shelter in a green house where big ripe tomatoes grew. The next day the owners son spotted Pig Dog and took pity on the hungry creature. Together they played computer games on a dusty old ZX Spectrum, eventually the son left and Pig Dog was all alone. Dabbing at the rubber keys, Pig Dog had made a computer program:

PIG DOG BAY

PIG DOG BAY

PIG DOG BAY

Whizzed up the screen. This pleased Pig Dog greatly. Many years later the son returned and was so happy to see his old friend, he gave Pig Dog his Google Nexus 7. Pig Dog squealed with glee and now wanted to show the world his little apps.