chipKIT® Development Platform

Inspired by Arduino™

Toggle Pin to blink LED

Created Sat, 12 Jul 2014 18:09:43 +0000 by pklimchuk


pklimchuk

Sat, 12 Jul 2014 18:09:43 +0000

I have a Mikromedia for PIC32 board (PIC32MX460F512L) Programmed with a Mikromedia demo hex file, it works fine.

I just trying to get some sort of response from it with MPIDE.

According to the schematic the backlight is PIC32 PIN# 28, RA9

I bought a picKit3 so that I can program (wanted to remove the USB bootloader as any source of a problem)

So, I open MPIDE and go to the blink example. I modify as follows..

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin PIN_LED1 has an LED connected on most Arduino and compatible boards:
  pinMode(28, OUTPUT);     
}

void loop() {
  digitalWrite(28, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(28, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

I set the MPIDE config to not delete my hex file. I press shift and click verify, and it compiles and at the bottom I see the directory my hex file is in.

I go to MPLAB and: Configure->Select device->PIC32MX460F512L programmer -> select programmer -> picKit3 click file->import and select it configure -> Configuration bits -> Use the below

#pragma config FNOSC = PRIPLL // Oscillator selection #pragma config POSCMOD = EC // Primary oscillator mode #pragma config FPLLIDIV = DIV_2 // PLL input divider #pragma config FPLLMUL = MUL_20 // PLL multiplier #pragma config FPLLODIV = DIV_1 // PLL output divider #pragma config FPBDIV = DIV_8 // Peripheral bus clock divider #pragma config FSOSCEN = OFF // Secondary oscillator enable #pragma config IESO = OFF // Internal/external clock switchover #pragma config FCKSM = CSDCMD // Clock switching (CSx)/Clock monitor (CMx) #pragma config OSCIOFNC = OFF // Clock output on OSCO pin enable #pragma config UPLLEN = ON // USB PLL enable #pragma config UPLLIDIV = DIV_2 // USB PLL input divider #pragma config FVBUSONIO = OFF // VBUS pin control #pragma config FUSBIDIO = OFF // USBID pin control #pragma config FWDTEN = OFF // Watchdog timer enable #pragma config WDTPS = PS1024 // Watchdog timer post-scaler #pragma config FSRSSEL = PRIORITY_7 // SRS interrupt priority #pragma config CP = OFF // Code protection #pragma config BWP = OFF // Boot flash write protect #pragma config PWP = OFF // Program flash write protect //#pragma config ICESEL = ICS_PGx2 // ICE pin selection

I press program and all seems to work ok, but there is no blinking backlight.

Could anyone shed some light on this for me? Majenko, You helped me a while back. I've been working slowly backwards... haven't been able to get it to do anything at all.

**forgot to mention. I looked at the reference manual for a cerbot with the mx460 chip and it had pin 68 listed. Same result (no blink)with 68 as the pin#

Thanks


Jacob Christ

Sun, 13 Jul 2014 18:09:59 +0000

Pin 28 on the PIC may not (and is probably most likely not) the abstracted chipKIT pin number.

Here is how I figured out the correct abstracted chipKIT pin number you should be using.

  1. Go to the following folder:

...\mpide-0023-windows-20140316\hardware\pic32

  1. Open board.txt in a text editor
  2. search for mikromedia (ignore case).
  3. Look for the following line: mikroe_mikromedia.build.variant= and see what its set to. I see: Default_100
  4. Next go into the following folder:

...\mpide-0023-windows-20140316\hardware\pic32\variants\Default_100

Where the last folder name is what mikroe_mikromedia.build.variant was set to.

  1. Open Board_Data.c and search for digital_pin_to_port_PGM

Your looking for RA9, I can see that in this array that RA9 is the 9th element in the array (starting at zero). This means that RA9 is really the abstracted chipKIT pin number 9 and not the uC pin number 28.

Humph. This is one of the reasons always say that the only innovations Arduino brought to the embedded world was to tell people it was easy and open there design. In reality I think they mucked things up a bit. If they would have mapped the uC pin number to the headers this would never be a point of confusion. It confused the hell out of me when I first started and I suspect countless others.

Jacob


pklimchuk

Sun, 13 Jul 2014 21:00:21 +0000

[attachment=0]Screen Shot 2014-07-13 at 4.55.35 PM.png[/attachment]

Changed the code to reflect pin9, and still nothing. So from what you're saying the pin # assignments start at 0 and go up through the ports?

0 -15 = PORTA.0 - PORTA.15 16-31 = PORTB.0 - PORTB.15 32-47 = PORTC.0 - PORTC.15 etc...

I tried replacing 9 with _PORTA.9 and nothing.

Double checked the schematics, still looks like toggling A9 should do the trick
Can you tell me how I would set the fuses in the mpide code?