English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (398/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
EXAMPLE 17-2: FOR 16-BIT SPI SLAVE MODE INITIALIZATION
/*
The following code example will initialize the SPI1 in slave mode with SSEN.
It assumes that the SPI1 SS input pin on RB2 is shared with the AN2 analog input.
It thus properly configures the corresponding AD1PCFG and TRIS registers bits.
*/
int
rData;
IEC0CLR=0x03800000;
SPI1CON = 0;
TRISBSET = 0x4;
AD1PCFGSET = 0x4;
rData=SPI1BUF;
IFS0CLR=0x03800000;
IPC5CLR=0x1f000000;
IPC5SET=0x0d000000;
IEC0SET=0x03800000;
// disable all interrupts
// Stops and resets the SPI1.
// Set RB2 as a digital input
// Analog input pin in digital mode
// clears the receive buffer
// clear any existing event
// clear the priority
// Set IPL=3, subpriority 1
// Enable Rx, Tx and Error interrupts
SPI1STATCLR=0x40;
SPI1CON=0x8000;
// clear the Overflow
// SPI ON, 8 bits transfer, Slave Mode
// from now on, the device is ready to receive and transmit data
DS61143E-page 396
Preliminary
© 2008 Microchip Technology Inc.