Electronic – dsPIC 33EP128MC506 will not read RB8, appears to be software problem


I'm using a dsPIC 33EP128MC506. I have two PCBs with this chip, both displaying the same symptoms, implying it's not one-off damage. RB8 is definitely being driven to 3.3 volts, confirmed with a multimeter and a scope. I've updated MPLAB X and the XC16 compiler to the latest versions, without effect. If I try to read RB8 immediately after setting the TRISB register, before any peripherals are enabled, I still get zero. Nothing in the errata seems to be relevant, but I could have missed something.

I've confirmed via serial output that TRISB<8> is set. TRISB is set to 0xFFFF, so one related problem where the wrong bit controls the direction seems to be inapplicable. RB9 also works fine as an input, so it doesn't appear that the upper half of PORTB is consumed by JTAG as others have reported. There are no writes to PORTB in the code, and there are no writes to LATB<8>. RB7 works fine as an input, as does RC13 (the physically adjacent pin). Peripherals that share the RB8 pin are:

  • T4CK, Timer 4 external clock input; unused and explicitly disconnected (T4CONbits.TCS = 0, confirmed by serial output)
  • TCK is JTAG test clock input pin; _FICD configuration word sets JTAGEN_OFF
  • ASCL1 is Alternate synchronous serial clock input/output for I2C1; _FICD configuration word sets ALTI2C1_OFF, and I2C is not used
  • RP40 is remappable peripheral 40; RPOR3 is 0x0000, confirmed by serial output, and the bit code for RP40 is never referenced in the program in decimal, hex, or binary
  • CVREF10 is Op amp/comparator voltage reference output; explicitly disconnected (CVRCONbits.CVR1OE = 0, confirmed by serial output)

I'm out of ideas.

Best Answer

All the ANSEL bits are set by default, which prevents the associated pins from being used as digital inputs. On this chip, ANSELB<8> exists, even though RB8 is not an A/D pin. Clearing ANSELB<8> allows it to be used as an input.