chipKIT® Development Platform

Inspired by Arduino™

[request] spi slave mode for pic32mx250 / pic32mx270

Created Sun, 23 Aug 2015 03:37:14 +0000 by scoppys


scoppys

Sun, 23 Aug 2015 03:37:14 +0000

hello !

i'm looking for spi slave mode example pic32mx250 / pic32mx270

some one have do it?


majenko

Sun, 23 Aug 2015 10:17:39 +0000

Unfortunately I don't think we have slave mode support in either SPI.h or DSPI.h at the moment.

That means you're going to have to program it manually.

There's two areas you have to understand for this - Peripheral Pin Select, and the SPI hardware.

You can probably make your life easier by using DSPI to first configure the SPI port in master mode then using the SPI registers to manually switch it into slave mode. That way all the PPS is taken care of for you, and you can concentrate on getting the SPI working the way you want.

You should start now by reading through the SPI manual: [url]http://ww1.microchip.com/downloads/en/DeviceDoc/61106G.pdf[/url]

Section 23.3.3.2 tells you all about slave mode. One of the most tricky things is the SS pin synchronisation (should you wish to use it, if not you can do it manually with interrupt pins):

The SSx pin allows a Synchronous Slave mode. If the SSEN bit (SPIxCON<7>) is set, transmission and reception is enabled in Slave mode only if the SSx pin is driven to a low state. The port output or other peripheral outputs must not be driven in order to allow the SSx pin to function as an input. If the SSEN bit is set and the SSx pin is driven high, the SDOx pin is no longer driven and will tri-state even if the module is in the middle of a transmission. An aborted transmission will be retried the next time the SSx pin is driven low using the data held in the SPIxTXB register. If the SSEN bit is not set, the SSx pin does not affect the module operation in Slave mode.

You should really use interrupts to handle the reception and transmission of each byte from/to the SPI interface. To learn more about interrupts on the chipKIT platform you can read this: [url]http://chipkit.net/interrupts-made-easy-with-chipkit/[/url]