Correct, that is exactly what paragraph 11.5.2 of datasheet says: in dsPICs there is no default pin assignment.
note that for the clock, as it can be both an input and an output, you have to assign it both on _SCK2R (input) and _RPxR (output)
this is one of the parts i use the most, if i have time later i will post the configuration code.
I did have weird issues when i first used it with DMA (unexpected waveforms, like seeing a long capacitor discharge at times, as if it changed the output line to high impedance at times..) so in the end i used the enhanced mode, 8 buffers. as it was to read/write a memory, i didn't require particular high speed. firing the interrupt every 8 bytes was acceptable, then i never changed the code because it worked well..
same with DACs, required samplerates were never high so i could use interrupts
EDIT:
SPI1 is'nt PPS-able, in that case this code works for me
/* SPI */
_TRISA4 = 0; //SDO1
_ANSA4 = 0;
_TRISA9 = 1; //SDI1
_ANSA9 = 0;
_TRISC3 = 0; //SCK1
_ANSC3 = 0;
_CS1 = 1;
_TRISB4 = 0; //CS
void SPI1_Init() {
SPI1STAT = 0;
SPI1CON1bits.DISSCK = 0; //Internal SPI Clock Enabled
SPI1CON1bits.DISSDO = 0; //SDO Enabled
SPI1CON1bits.SSEN = 0; //_SS is not used
SPI1CON1bits.MSTEN = 1; //Master Mode
SPI1CON1bits.MODE16 = 0; //8 bit transfer
SPI1CON1bits.SMP = 0; //Data Sampled at middle of time
SPI1CON1bits.CKE = 1; //Mode 0
SPI1CON1bits.CKP = 0;
SPI1CON1bits.SPRE = 4; //1:4
SPI1CON1bits.PPRE = 1; //1:16 -> 500 kHz SPI clock
SPI1CON2 = 1; //Disable Framed mode, Enable enhanced mode
SPI1STATbits.SPIEN = 1;
_SPI1IF = 0;
}
same should work with SPI2 if you assign the pins (SDI and SCK PPS input, SDO and SCK PPS output)
other notes:
-it's not uncommon to have issues or erratas on the SPI regarding the status bits, that's why i tend to use interrupts or clear then check the interrupt flag anyway.
-check the errata, but the remaining SPI issues should not affect you
-clock prescalers can't be both set at 1:1 at the same time, in that case the peripheral won't work.
-after a transaction you must read back the SPIxBUF register, otherwise it will stay in the FIFO buffer and after one or more transactions (depending on enchanced mode status) it will overflow and the peripheral will stop working. relevant status bit should be set.
-this is my goto function for spi
uint16_t SPI1_Send(uint16_t data) {
/* you may or may not want to change the size of data and return depending on the data width and MCU */
_SPI1IF = 0;
SPI1BUF = data;
while(!_SPI1IF);
return SPI1BUF;
}
or, when the status bits do work
uint16_t SPI1_Send(uint16_t data) {
while(!SPI1STATbits.SRMPT); //Wait for a possible previous transaction to end
SPI1BUF = data;
while(!SPI1STATbits.SRMPT);
return SPI1BUF;
}