dsPic33f remap pins problem

Discussion in 'Embedded Systems and Microcontrollers' started by Art, Aug 30, 2016.

  1. Art

    Thread Starter AAC Fanatic!

    Sep 10, 2007
    Hi Guys :)
    I’m trying to map pins associated with SPI1 to pins RP6-RP9 for use with an SD Card library,
    but so far I don’t think I’ve gotten past mapping the SPI peripheral.
    The controller is dsPic33FJ128GP802.

    My PPS.h file has an include file in it for some other processor, and the include file for that device doesn’t exist,
    so I don’t get to use PPS.h to do it the easy way:
    Code (Text):
    2. PPSUnLock;
    3. PPSInput(PPS_SDI1, PPS_RP6); //Sets RP6 (pin 15) to be Input, and maps to SPI IN
    4. PPSOutput(PPS_SS1, PPS_RP9);//Sets RP9 (pin 18) to be Output, and maps to SPI CS
    5. PPSOutput(PPS_SCK1, PPS_RP8);//Sets RP8 (pin 17) to be Output, and maps to SPI CLK
    6. PPSOutput(PPS_SDO1, PPS_RP7);//Sets RP7 (pin 16) to be Output, and maps to SPI OUT
    7. PPSLock;
    8. }
    So what I think I need to do instead is something like this:
    Code (Text):
    2.     // PPS needs to first unlock the pins before re-assignment
    3.     __builtin_write_OSCCONL(0x46); // unlock sequence - step 1
    4.     __builtin_write_OSCCONH(0x57); // unlock sequence - step 2
    5.     _IOLOCK = 0;
    7.     // Pins can now change - though, these don't change in the SFR debugger window... why?
    8.     _RP8R = 8;              // configure sck1 as output
    9.     _RP7R = 7;              // configure sdo1 as output
    10.     _RP9R = 9;           // configure ss1 as output
    11.     RPINR20bits.SDI1R = 6;  // configure SDI for input
    13.     __builtin_write_OSCCONL(0x46); // unlock sequence - step 1
    14.     __builtin_write_OSCCONH(0x57); // unlock sequence - step 2
    15.     _IOLOCK = 1; // re-lock the ports
    but after that, I don’t see any activity on an LED connected to the SPIDO port when the SD card is accessed,
    and the file system initialise routine fails (returns false).
    Furthermore, just using the lines that adjust OSCCON (without the pin remapping code) has an effect on some
    of my display routines that those pins should have nothing to do with, so they either interfere with other pins on portB,
    or interfere with some variables or arrays involved in the display routines.

    Can anyone see any obvious mistake?
    Cheers, Brek.
  2. Art

    Thread Starter AAC Fanatic!

    Sep 10, 2007
    Case closed, well done Art! :D

    The answer was don’t worry about the register unlock/lock sequence unless you have set the lock bit already yourself.
    So to remap the pins, just read the data sheet and write to the registers.
    Finally, double and triple check you wired the input & output SPI to the SD card the correct way around :D