chipKIT® Development Platform

Inspired by Arduino™

Cannot drive PORTG on Chipkit Max32

Created Fri, 21 Aug 2015 15:00:11 +0000 by louisvilg


Fri, 21 Aug 2015 15:00:11 +0000

Hi everybody !

I've got some trouble, let me explain. I would like to drive RG6, RG7, RG8 and RG9 pins. So to do this, I deactivated SPI2, UART2, UART3, I2C4, PMA, CNCON, and a little more peripheral.

So there is my code initialization but I don't know if I do a configuration mishandling by doing this...

void ConfigAcqSetup(void) {
    flagSignal.allFlags = 0;

    DDPCONbits.JTAGEN = 0;
    AD1PCFG = 0xFFFF;   // Disable ADC
    CM1CON = 0;         // Disable comparator 1
    CM2CON = 0;         // Disable comparator 2
    //U1CON = 0;          // Disable USB
    I2C4CON = 0;        // Disable I2C 4 to only use JTAG port
    U2MODE = 0;         // Disable UART2 to use JTAG port
    U3MODE = 0;         // Disable UART3 to use JTAG port
    PMCON = 0;          // Disable parallel master port to use JTAG port
    PMAEN = 0;          // Disable parallel master port
    CNCON = 0;          // Disable Change Notification register

    // Disable SPI2A pins to set pins
    SPI2ACON = 0;               // Reset and clear SPI2
    SPI2ACONbits.ON = 0;        // Disable SPI port
    SPI2ACONbits.SSEN = 0;      // Disable SPI SS2 pin
    SPI2ACONbits.DISSDO = 1;    // Disable SPI SDO pin

    // Set GPIO for debug
    TRISGbits.TRISG6 = 0; // TCK
    TRISGbits.TRISG7 = 0; // TDI
    TRISGbits.TRISG8 = 1; // TDO
    TRISGbits.TRISG9 = 0; // TMS
    // Port initialization
    PORTGbits.RG6 = 0;
    PORTGbits.RG7 = 0;
    PORTGbits.RG9 = 0;

    // Setting reset pin for PIC18
    PORTSetPinsDigitalOut(IOPORT_B, RB0);

I would like to use JTAG port for chip reconfiguration. But I want to set data like the master is PIC32 on chipKIT... I can't change pins because I have already done the PCB...

So if someone could help me, it will be awesome ! Cheers,



Fri, 21 Aug 2015 15:15:11 +0000

It can sometimes be a little tricky to mix chipKIT IO and native IO instructions. There's a knack to it though:

  • Most peripherals are already off, there's no need to disable them
  • The only one that interfered by default is analog, and only for input

How I do it:

  • Use the chipKIT "pinMode()" function to configure the pins
  • Use native register access for the actual IO

By using "pinMode()" you are ensuring the pin is in the right state for digital IO. You're keeping it all happy with the rest of the chipKIT system. Once you have it in the right mode (it ensures anything else is turned off for you then) you are free to use direct register access for high speed.

So instead of "TRIS" and all that use "pinMode()". You can then use "LATx" for setting the port's state, and also subsequently use "TRISx" if you need to switch from input to output or output to input at high speed (since everything else has already been dealt with by pinMode()).


Fri, 21 Aug 2015 15:18:01 +0000

Thank you Majenko, I'll try your recommendations and tell you what happens !

[Edit] My answer was too quick ... I never used pinMode() function and I don't know where I could find it ! I only use basic libraries of C32 compiler. So could you help me please?



Fri, 21 Aug 2015 15:43:53 +0000

Oh, so you're not using MPIDE then? You're on MPLAB I guess?

That's a whole different ball game...

Theoretically you should just have to use AD1PCFG, TRIS and LAT/PORT. Everything else will already be off.

Don't forget all the initialization you need to do for the PIC32 though - it's not a simple chip to get running properly, which is why I (and many others) use the chipKIT software instead of MPLAB / XC32, etc, because it does all that hard work for you.


Mon, 24 Aug 2015 08:13:50 +0000

Yes, I'm using MPLAB X. I initialize every registers with shared pin I would like to use. But it still doesn't work. I am sure that there is a specific solution to make it works but I don't know what...

I will still continue to do this and if I found a solution, I'll post it here!

If anybody has some ideas, feel free to let me know!