A big improvement of dsPIC33e series micro-controller from its predecessors is the re-mappable peripheral IO. This allows great flexibility for circuit board design, but also requires slightly more efforts to use it.
- “RPn” is for both output and input, whereas “RPIn” is input only. When wiring up your PCB design, you need to double check that “PRIn” is not hookup up as a peripheral output.
- Declaration for output type IO is different from input. For example, if you use RPI16 as input for UART1 receiver, you should claim in your program like:
// U1ART RX connects to RPI16 _U1RXR = 16;
If you use RP118 as output for UART1 transmitter, you will need to claim in a reversed way like:
// RP118 connects to peripheral 0b00001 _RP118R = 1; // 0b00001 stands for UART1
I believe it is related to the way the look-up table is implemented.
- Configuring the peripheral IO register is not the whole story to correctly use an IO, especially when this pin shares with an analog function (usually ADC). All the IO that are shared with “ANx” are set to be an analog pin as default. Any attempts trying to use them as digital IO must have their corresponding ANSELx register cleared. (set to 0).
For example, if you want to use Pin No.3 (which is also AN29, RE5, RP85) for any peripheral function’s output (UART, DCI, SPI, I2C, etc.,), you must declare:
// ANSxy, x stands for Port A/B/C/D/E/..., y stands for number _ANSE5 = 0; // Enables digital port pin
Update on 11/25/2013
Pins that multiplex with analog function are not only limited to ADCs, but also Comparators/Op-Amps. I/Os such as RG6, RG7 share with C1IN3- and C1IN1- are also default as analog pin after reset. In order to use them as digital I/O, their corresponding ANSxy (in this case _ANSG6, _ANSG7) register must be cleared. I didn’t realized this until I ran into trouble when remapping the DCI CSDI on one of the comparator input pin, and ended up receiving nothing but zero. As soon as I clear the corresponding ANSELx register, data started pumping into the DCI receiver.