Vault 7: Projects

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

dsPIC33/PIC24 Family Reference Manual
DS70005185A-page 34 2014 Microchip Technology Inc.
5.1 SPI Transmission and Reception with DMA
The SPIx module is configured in Master mode. Two DMA channels are used, such as Channel 0
for data transmission and Channel 1 for data reception.
DMA Channel 0 is configured for SPI transmission with the following parameters:
Transfer data from RAM to the SPIx module continuously
Register Indirect with Post-Increment Addressing mode
Use two ping-pong buffers
16 transfers per buffer
DMA Channel 1 is configured for SPI reception with the following parameters:
Transfer data from the SPIx module to RAM continuously
Register Indirect with Post-Increment Addressing mode
Use two ping-pong buffers
16 transfers per buffer
Example 5-1 shows the SPI1 transmission and reception with DMA for dsPIC
®
devices.
Example 5-1: SPI1 Transmission and Reception with DMA
Setup for SPI1 Master Mode:
// Interrupt Controller Settings
IFS0bits.SPI1IF = 0;
// SPI1CON1 Register Settings
SPI1CON1bits.MODE16 = 1; // Communication is word-wide (16 bits)
SPI1CON1bits.MSTEN = 1; // Master mode enabled
// SPI1CON2 Register Settings
SPI1CON2bits.FRMEN = 0; // Framed mode disabled
// SPI1STAT Register Settings
SPI1STATbits.SPISIDL = 0; // Continue module operation in Idle mode
SPI1STATbits.SPIBEC = 0; // Buffer Length = 1 Word
SPI1STATbits.SPIROV = 0; // No Receive Overflow has occurred
SPI1STATbits.SPIEN = 1; // Enable SPI module
// Force First Word After Enabling SPI
DMA0REQbits.FORCE=1;
while (DMA0REQbits.FORCE == 1);
IEC0bits.SPI1IE = 1;
Set up DMA Channel 0 to Transmit in Continuous Ping-Pong Mode:
unsigned int TxBufferA[16] __attribute__((space(xmemory)));
unsigned int TxBufferB[16] __attribute__((space(xmemory)));
IFS0bits.DMA0IF = 0;
IEC0bits.DMA0IE = 1;
DMACS0 = 0;
DMA0CON = 0x2002;
DMA0STAL = (unsigned int)&TxBufferA;
DMA0STAH = (unsigned int)&TxBufferB;
DMA0PAD = (volatile unsigned int) &SPI1BUF;
DMA0CNT = 15;
DMA0REQ = 0x000A;
DMA0CONbits.CHEN = 1;
Set up DMA Channel 1 to Receive in Continuous Ping-Pong Mode:
unsigned int RxBufferA[16] __attribute__((space(xmemory)));
unsigned int RxBufferB[16] __attribute__((space(xmemory)));
IFS0bits.DMA1IF = 0;
IEC0bits.DMA1IE = 1;
DMA1CON = 0x0002;
DMA1STAL = (unsigned int)&RxBufferA;
DMA1STAH = (unsigned int)&RxBufferB;
DMA1PAD = (volatile unsigned int) &SPI1BUF;
DMA1CNT = 15;
DMA1REQ = 0x000A;
DMA1CONbits.CHEN = 1;

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh