Hi Guys
I have a dsPic33FJ128GP802 on protoboard with LCD display to see output, and trying to map SPI pins to RP6-RP9 (RB6-RB9).
This is to get an SD card library working, but I’m pretty sure I’m stuck on SPI not working, as I don’t see activity with LEDs
temporarily connected to the pins instead of the SD card.
This “should” be pretty easy with PPS.h, and I should be able to do this:
PPSUnLock;
PPSInput(PPS_SDI1, PPS_RP6); //Sets RP6 (pin 15) to be Input, and maps to SPI IN
PPSOutput(PPS_SS1, PPS_RP9);//Sets RP9 (pin 18) to be Output, and maps to SPI CS
PPSOutput(PPS_SCK1, PPS_RP8);//Sets RP8 (pin 17) to be Output, and maps to SPI CLK
PPSOutput(PPS_SDO1, PPS_RP7);//Sets RP7 (pin 16) to be Output, and maps to SPI OUT
PPSLock;
}
but my PPS.h file has register definitions that I think apply to another device, and doesn’t even compile as-is.
It has an include line for another mpu, the file for which doesn’t exist: #include "p33EP512MU810.h”.
So I have tried to do the same thing a number of ways, this being one of them:
// PPS needs to first unlock the pins before re-assignment
__builtin_write_OSCCONL(0x46); // unlock sequence - step 1
__builtin_write_OSCCONH(0x57); // unlock sequence - step 2
_IOLOCK = 0;
// Pins can now change - though, these don't change in the SFR debugger window... why?
RPINR20bits.SDI1R = 6; // configure SDI for input
RPOR4bits.RP8R = 8; // configure sck1 as output
RPOR3bits.RP7R = 7; // configure sdo1 as output
RPOR4bits.RP9R = 9; // configure ss1 as output
__builtin_write_OSCCONL(0x46); // unlock sequence - step 1
__builtin_write_OSCCONH(0x57); // unlock sequence - step 2
_IOLOCK = 1; // re-lock the ports
Funny enough, just the OSCCON lines change the behaviour of some display test code in my program
that should have nothing to do with.
If it’s worth anything, the write protect switch and card socket switches both work through the library functions to test them.
... another reason to think SPI isn’t mapped to the SD card pins.
Another question is why the unlocking procedure is done here, and in the data sheet,
yet I have another project I remapped the UART in for the 64 version of the same chip, before I even knew about this pin unlocking procedure!
Furthermore, in a Pic24F MP3 player project, it’s also done on a pic24F, but I haven’t checked the data sheet for that to see if the procedure exists.
Any thoughts appreciated. Maybe I’m missing something obvious.
Cheers, Brek.