This repository contains an example of bare-metal source code for SPI as described in TB3265 - Getting Started with SPI using MSSP on PIC18 document from Microchip.
In this demo, the SPI will be configured as slave and it will be used to exchange data. The data transfer is triggered by interrupts.
- TB3265 - Getting Started with SPI using MSSP on PIC18
- PIC18-Q10 Product Family Page
- PIC18F47Q10 Data Sheet
- PIC18F47Q10 Code Examples on GitHub
- MPLAB® X IDE 5.30 or newer (microchip.com/mplab/mplab-x-ide)
- MPLAB® XC8 2.10 or a newer compiler (microchip.com/mplab/compilers)
- Microchip PIC18F-Q Series Device Support 1.3.89 or newer (packs.download.microchip.com/)
- PIC18F47Q10 Curiosity Nano (DM182029)
The PIC18F47Q10 Curiosity Nano Development Board is used as the test platform.
The following configurations must be made for this project:
-
Clock
- Oscillator Select: HFINTOSC
- HF Internal Clock: 64 MHz
- Clock Divider: 1
-
MSSP1:
- MSSP1 Enabled
- MSSP1 Interrupts Enabled
- Serial Protocol: SPI
- Mode: Slave
- Data Mode: 0
-
Watchdog Timer: disabled
-
Low-voltage Programming: enabled
Pin | Configuration |
---|---|
RA5 (SS) | Digital Input |
RC3 (SCK) | Digital Input |
RC4 (SDI) | Digital Input |
RC5 (SDO) | Digital Output |
-
Connect the board to the PC.
-
Open the pic18f47q10-cnano-spi-slave-int-bare.X project in MPLAB® X IDE.
-
Set pic18f47q10-cnano-spi-slave-int-bare.X project as main project. Right click on the project in the Projects tab and click Set as Main Project.
-
Select the PIC18F47Q10 Curiosity Nano in the Hardware Tool section of the project settings:
- Right click on the project and click Properties;
- Select the PIC18F47Q10 Curiosity Nano (click on the SN) in the Hardware Tool tab and then click OK:
- Program the project to the board: right click on the project and click Make and Program Device.
Result:
- Channel 0 -> SCK
- Channel 1 -> Slave SDI/Master SDO
- Channel 2 -> Slave SDO/Master SDI
- Channel 3 -> SS1
- Channel 4 -> SS2 (for other slave device)
This project is an illustration for a basic use case based around MSSP1 in SPI mode.