chipKIT® Development Platform

Inspired by Arduino™

Visual Micro

Created Wed, 14 Dec 2016 02:30:05 +0000 by JeanD


Wed, 14 Dec 2016 02:30:05 +0000


I'm new here. For my project (laser engraver/cutter), I must switch from Arduino Mega to Max32. My dev environnement is Visual Micro (extension for Visual Studio). This tool always worked perfectly for Uno, Mega, even ESP8266 generic. One of great features are intellisense and jump to definitions/declarations of piece of code. Unfortunately, seems there is a lot of problems when I try to develop sketch for Max32. A lot of library are not found. Normaly, just add new board in Board Manager is enough. For Max32, seems this is an other story. Someone already tried and succeeded development on Visual Micro for Max32 ? One more thing... I need to do bit banging (digitalWrite is too slow) but there is no reference to SFR registers like PORTA, PORTASET, ...

Thanks for your advices.



Wed, 14 Dec 2016 10:42:05 +0000

I can't comment on Visual Micro (well, I could but it wouldn't be nice ;) )

However, for direct port access you need to:

  • Read the MAX32 user guide to get the list of pin to port mappings (it's towards the back in a big table)
  • Read the PIC32MX795F512L datasheet which details how everything in the chip works, including the IO ports

There are functions to get the port data from a pin number built into the chipKIT API. I often use a little function like this to get the data nicely:

p32_ioport *getPortInformation(uint8_t pin, uint32_t *mask) {
    uint32_t portno = digitalPinToPort(pin);
    if (portno == NOT_A_PIN) {
        return NULL;
    if (mask != NULL) {
        *mask = digitalPinToBitMask(pin);
    return (p32_ioport *)portRegisters(portno);

Then you can:

uint32_t mask;
p32_ioport *port = getPortInformation(23, &mask);

From then it's a matter of:

port->lat.set = mask;
port->lat.clr = mask;

I find it is best to still use pinMode() initially to configure the pin since that deals with switching analog mode on and off for you. From then you can use the TRIS register to toggle between input and output:

port->tris.clr = mask; // output mode
port->lat.set = mask; // set high
port->tris.set = mask; // input mode
int i = port->port.reg & mask; // read input


Wed, 14 Dec 2016 11:34:42 +0000

Hi ,

Thanks for those excellent methods. I passed the last week-end reading the datasheet. I've learned a lot, overall about differences between ATMega and Pic32. Now I understand why only 5 pwm on MAX32.

I've found a work-around to get intellisense.

  • Locate the "p32mx795f512l.h" file somewhere in the source
  • Copy this file into your project directory and include it to your project
  • Include this file in the top of your .ino file

I will certainly go deeper in the functions you've pointed but I plan to write the app in C because the standard libraries are too heavy. Nothing better than DMA

Have a nice day.


Wed, 14 Dec 2016 12:01:27 +0000

To write in C you should just need to include "xc.h" which will then include the right CPU header for you. No need to copy system header files to your project directory since the compiler already knows where they are located.


Wed, 14 Dec 2016 12:54:48 +0000

Thank you. I always need to include p32mx795f512l.h to get intellisense. It's not a big deal because my Max32 will be used for one application only. To compile an app with my own main(), I need to alter chipKIT-application-COMMON.ld (comment the ASSERT) Thanks again.