# PIC24FJ128GA202 some I/O PortB pins not behaving correctly

I am working on a small project using a PIC24FJ128GA202, and noticed that my UART wasn't working with every RP pins. I ran the following code :

#include "xc.h"
int main(void) {
ANSB = 0 ;
TRISB = 0 ;
LATB = 0xFFFF ;

while(1) {} ;
return 0;
}


Turns out not all the pins are pulled to Vdd as expected. Pins RB4,8,9 and 10 stays at Gnd, while pin 11 is at 2V (tested without anything connected to the pins). Those were the same pins that my uart didn't work with as either input or output.

Tried to use them as open drain, and these pins cannot pull the line to Gnd either. Replacing the microcontroler achieved the same results.

My guess is that some peripherical is controlling them by default but i did not manage to find it in the documentation. Any recommandation ?

• Which package is the microcontroller in? – Dwayne Reid Jan 16 '16 at 15:27
• It's in the 28-Pin DIP – Dtty Jan 16 '16 at 15:34

Firstly, I don't see your configuration bits set. You can have MPLAB generate the required code: http://microchip.wikidot.com/mplabx:view-and-set-configuration-bits

I suspect that RB4 isn't working because the secondary oscillator isn't turned off through the configuration bits. Similarly, RB8, RB9 and RB10 are also TCK, TDO and TDI respectively for JTAG. Disabling JTAG through the configuration bits should fix those pins as well.

• Thank you ! Setting #pragma config JTAGEN = OFF Did the trick and portB8,9,10,11 are now behaving correctly, and usable by UARTs. – Dtty Jan 17 '16 at 12:54

RB4 is strictly an input pin, see table 1-3 on page 18 of the data sheet

Note: the advance micro controllers of microchip (i.e. pic24fj, and pic30/33 series have remappable ports) So not all pins are strictly assigned on startup. for example on the dspic33EP, I had to assign UART Rx to a particular RP100 pin by assigning the following code

RPINR18 = 0x0064;      // UART Rx PPS -> RP100


or assign UART Tx to RP101 by the following code

RPOR9BITS.RP101R = 1;


So here are few things I suggest doing, or following.

1. Make sure you're including your micro controller's header file. However, if this code compiles then it may mean it's included automatically.
2. Setup configuration bits to avoid unwanted behavior. I'd disable watchdog, and reset pin for the time being. They may cause your micro controller to constantly reset, thus not letting you run your program. Using XC.h, it takes some simple macros.

_FWDT(WDT_OFF); // Watchdog timer off

_FBORPOR(MCLR_DIS); // Disable reset pin

3. Setup an internal oscillator for the time being (although eventually move to external for better accuracy, if it's a necessary requirement)

4. You need to make sure, gpio of interest RBx isn't being set for a mode other than I/O (i.e. RB4 may be setup for an external secondary oscillator: SOSCI). note: Some pins are remappable, RPx means they can be input or output, and RPIx means they are strictly input (which seems to be the case for RB4).

• Thanks. I did not notice that portB4 was input only, it is working as intended as an input with the same default parameters. – Dtty Jan 17 '16 at 13:05