Search code examples
microcontrollerpicmicrochip

PIC32MX cannot change select TRIS bits


hopefully I have the right forum here.

Firstly:

Processor: PIC32MX795F512L (on the chipKIT mx32 dev board)

IDE: MPLAB X IDE v2.26

Pogrammer/Debugger: PicKIT 3

I am trying to set some of the PORT pins to outputs so I can bit bang a communication protocol to another device. However, when I run the PIC using the pickit 3 as a debugger, I find that some of the TRIS bits won't toggle to 0.

This is an issue I am having with just TRISF and TRISG so far, and I have seen some mention of it in other posts, but no solution.

The pins I have tried to toggle are:

  • TRISF4 (SDA3A/SDI3A/U3ARX/PMA9/CN17/RF4)
  • TRISG3 (D-/RG3)
  • TRISG2 (D+/RG2)

here is an example of how I am doing it.

ODCDCLR = 0xFFFF;
ODCFCLR = 0xFFFF;
TRISDCLR = 3<<14;
TRISFCLR = 3<<5;

What could be some causes for a sticky TRIS bit?


Solution

  • If you look at page 36 of the datasheet, you will see that G2 and G3 are input-only when used as digital I/O instead of USB. Excerpt below:

    pins

    Similarly, if you have UART3 enabled, RF4 will be an RX input.

    You need to make sure you enable/disable the peripherals sharing those pins and read the datasheet very carefully. It's a complete PITA sometimes, but I've never found the datasheet to be wrong - just sometimes things are well hidden!