PIC32MX Development

Work in progresss

= General =

I/O Mapping
I/O Mapping from mcu-pins and control registers to constants used in the pinguino libraries.

= Programming Environment =

MPLAB X and Pinguino
In the article MPLAB X and Pinguino PIC32 DIY Fabio shows how to use the Microchip MPLAB X Integrated Development Environment for implement an application and upload it to the Pinguino PIC32 DIY board through the bootloader.

= Notes and Hints =

Small note on SPI2 with single SPI MCUs
Due to what seems to be a small quirk in the specification of the PIC32MX, on boards that only feature one SPI bus, the mcu-pins and mappings are named SPI2xxx (not SPI1xxx, as would be expected).

Peripheral Pin Select (PPS)
Original forum post: Pic32 Interrupts

After posting my problem on the Microchip forum, I got a bunch of useful suggestions as well as code with a working PPS interrupt (natively).

As for the sample code, I didn't manage to reproduce the behaviour instantly on the Pinguino and found no time to have a closer look why it still fails, though it seems to work with MPLab on a PIC32MX220 (code sample).

= Tips and Tricks =

Tips for using atomic functions when changing PIC32 registers
Author: agolac

Microchip has atomic functions for all register manipulation and they can be viewed in processor header file and processor.o These are xSET, xCLR and xINV.

xSET works in a way that it sets to 1 all bits that are 1 in mask

Example:

xCLR works in a way that it sets to 0 all bits that are 1 in mask

Example:

xINV works in a way that it inverts all bits that are 1 in mask Example:

If you do objdump of processor.o you will see adressess of all SFR's These addresess are used in the application disassembly code below this list.

Functions marked "C Code" do the same thing, and that is, set USBEN bit of register U1CON to 1, or enabled. Application disassembly code:

You will notice that using atomic functions, only three instructions are necessary, and by using XXXbits, five instructions. Atomic functions are done in hardware and cannot be interrupted so they are safer.

When using XXXbits value, SFR is first read, then its value is modified and then written back to SFR. This can cause potential problems if in the mean time interrupt occurs, and value written by interrupt will be overwritten when interrupt returns by continuing XXXbits code.

So, tip is, always use use atomic instead of XXXbits. Your code will be smaller, potential bugs and problems will be less.

Original forum post: Tips for using atomic functions when changing PIC32 registers

Using CHANGE NOTICE interrupt
Author: MarSch

CHANGE NOTICE is an interrupt that is triggered if any one from a number of prior configured inputs sees a change in polarity. The respective values can than be accessed in the ISR. Apart from keeping the code cleaner, this also fits a multiple button approach (or several input lines representing a binary state) better than a single interrupt for each input. As this might be also interesting for other Pinguino users, I'll post some sample code as soon as I find an opportunity.

Original forum post: Pic32 Interrupts