Welcome! Log In Create A New Profile

Advanced

C on the BP2

Posted by migry 
C on the BP2
November 11, 2014 09:15PM
I was interested in this board due to the arduino connector layout together with the power of a PIC32. Of course you need to make sure that any shields are 3.3V compatible. Remember that any output can only drive 3.3V as a logic high which might or might not work with 5V devices. Any pin which DOES NOT share an analogue function is 5V input capable.

My preference is to program in C. I am using MPLAB IDE v8.70 rather than the newer MPLAB-X. I am also using a PicKit3 to program the PIC32. You will need to populate the 5 holes in the centre of the board with suitable connector pins. Remember that the PicKit3 connector has 6 connection points, so be very careful not to plug it in incorrectly.

The various pins have multiple possible functions. Many are configured in software but others are configured by the config fuses.

Add the following code to switch off the 4 JTAG pins on RB10/RB11/RB12/RB13 and allow these pins to be used as general purpose I/O.

The other gotcha is that several I/O pins are configured as analogue I/O after reset, so if you need them to be digital write to AD1PCFG (there is the same gotcha on PIC16 and PIC18s!).

#include <plib.h>

...

DDPCONbits.JTAGEN = 0; // disable the JTAG port

AD1PCFG = 0xffff; // all PORTs as digital

The setting of the config fuses is important(!). Forgetting some settings can result in yet more pins apparently not working. If you are not using the low frequency clock pins set the fuse FSOSCEN = OFF (otherwise RC13 and RC14 won't work in the expected way). Likewise for the fuse FNOSC = FRCPLL (otherwise RC12 and RC15 won't work as expected). This is not clearly documented.

The config fuses can be set in several ways, including the PicKit3 software, however in C it is probably wise to use the #pragma approach. Here are my settings. The processor clock is programmed to 80MHz and the peripheral clock to 40MHz.

// 80MHz core clock, 40MHz Peripheral clock
#pragma config FNOSC = FRCPLL
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1
#pragma config FPBDIV = DIV_2
#pragme config FWDTEN = OFF
#pragma config POSCMOD = OFF
#pragma config BWP = OFF
#pragma config CP = OFF
#pragma config FSOSCEN = OFF
#pragma config OSCIOFNC = OFF
#pragma config DEBUG   = OFF  
#pragma config ICESEL  = ICS_PGx2

A key setting is the clock source (FNOSC = FRCPLL). There is no external XTAL on the BP2 so the internal 8MHz RC clock source has to be used. It took me several days to figure out that I had set this config incorrectly set (cut and paste!) and so the processor wasn't getting any clock whatsoever.

I'll post an example program and associated files in a seperate posting.
Re: C on the BP2
November 11, 2014 09:23PM
I ought to mention that if you plan to program the PIC32 in C then buy a copy of "PROGRAMMING 32-BIT MICROCONTROLLERS IN C: Exploring the Pic32" by Lucio Di Jasio.



Edited 1 time(s). Last edit at 11/11/2014 10:04PM by migry.
Re: C on the BP2
January 09, 2016 12:30AM
Just a quick message.

It has been a busy year for me with new job and house move, so my work using the BP23 programmed in C has come to a complete halt. I hope to pick things up this year now I have a work room sorted out.

So hopefully I will post more information later this year (2016).
Sorry, only registered users may post in this forum.

Click here to login