# Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

### Protego

# PIC24FJ64GA004 -- Serial Peripheral Interface

- 1
- 2
…
- 13
- 14
- 15
- 16
- 17
…
- 41
- 42

 2014 Microchip Technology Inc. DS70005185A-page 15
Serial Peripheral Interface (SPI) Module
3.3.1.1 Master Mode Setup Procedure
The following procedure is used to set up the SPIx module for Master mode of operation:
1. If using interrupts, configure the interrupt controller:
a) Clear the SPIx Interrupt Flag Status bit (SPIxIF) in the respective Interrupt Flag Status
(IFSx) register in the interrupt controller.
b) Set the SPIx Interrupt Enable bit (SPIxIE) in the respective Interrupt Enable Control
(IECx) register in the interrupt controller.
c) Write to the SPIx Interrupt Priority bits (SPIxIP) in the respective Interrupt Priority
Control (IPCx) register to set the interrupt priority.
2. Set the SPIx Master Mode Enable bit (MSTEN) in the SPIxCON1 register (SPIxCON1<5> = 1).
3. Clear the SPIx Receive Overflow Flag bit (SPIROV) in the SPIxSTAT register
(SPIxSTAT<6> = 0).
4. Enable the SPIx operation by setting the SPIx Enable bit (SPIEN) in the SPIxSTAT register
(SPIxSTAT<15> = 1).
5. Write the data to be transmitted to the SPIxBUF register. The transmission (and reception)
starts as soon as data is written to the SPIxBUF register.
Example 3-1 provides the code sequence to show the SPIx register configuration for Master mode
(the SPI1 module is used in the example).
Example 3-1: SPI1 Register Configuration – Master Mode
/* The following code sequence shows SPI register configuration for Master mode */
IFS0bits.SPI1IF = 0; // Clear the Interrupt flag
IEC0bits.SPI1IE = 0; // Disable the interrupt
// SPI1CON1 Register Settings
SPI1CON1bits.DISSCK = 0; // Internal serial clock is enabled
SPI1CON1bits.DISSDO = 0; // SDOx pin is controlled by the module
SPI1CON1bits.MODE16 = 1; // Communication is word-wide (16 bits)
SPI1CON1bits.MSTEN = 1; // Master mode enabled
SPI1CON1bits.SMP = 0; // Input data is sampled at the middle of data output time
SPI1CON1bits.CKE = 0; // Serial output data changes on transition from
// Idle clock state to active clock state
SPI1CON1bits.CKP = 0; // Idle state for clock is a low level;
// active state is a high level
SPI1STATbits.SPIEN = 1; // Enable SPI module
// Interrupt Controller Settings
IFS0bits.SPI1IF = 0; // Clear the Interrupt flag
IEC0bits.SPI1IE = 1; // Enable the interrupt

- 1
- 2
…
- 13
- 14
- 15
- 16
- 17
…
- 41
- 42