Visual Micro

Post Reply
JeanD
Posts: 7
Joined: Wed Dec 14, 2016 3:11 am

Visual Micro

Post by JeanD » Wed Dec 14, 2016 3:30 am

Hello,

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.

Jean

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Visual Micro

Post by majenko » Wed Dec 14, 2016 11:42 am

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:

Code: Select all

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:

Code: Select all

uint32_t mask;
p32_ioport *port = getPortInformation(23, &mask);
From then it's a matter of:

Code: Select all

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:

Code: Select all

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
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

JeanD
Posts: 7
Joined: Wed Dec 14, 2016 3:11 am

Re: Visual Micro

Post by JeanD » Wed Dec 14, 2016 12:34 pm

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.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Visual Micro

Post by majenko » Wed Dec 14, 2016 1:01 pm

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.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

JeanD
Posts: 7
Joined: Wed Dec 14, 2016 3:11 am

Re: Visual Micro

Post by JeanD » Wed Dec 14, 2016 1:54 pm

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.

Post Reply