chipKIT® Development Platform

Inspired by Arduino™

MPIDE and PIC32MX250F128B from ChipKit Pi to breadboard

Created Thu, 22 May 2014 00:37:51 +0000 by djgardn2


djgardn2

Thu, 22 May 2014 00:37:51 +0000

[attachment=1]ChipKitPi_PinMapping_for_MPIDE.png[/attachment]Hello,

I was wondering if anyone would be able to point me in the right direction on being able to access as many IO pins as possible.

I have put together a guide to all the pins that I have currently found through testing, although I have a feeling that there are still one or two pins missing.

I'm interested in accessing the factory pin 18, the pin that I am referring to is between the ground and the pin labeled 12 on my attached image (bottom right, 4 pins from the bottom).

The attached image contains the MPIDE pin numbering for the chipKit Pi board setting, hopefully this will be a good reference for pin numbers during coding for others also.

[attachment=1]ChipKitPi_PinMapping_for_MPIDE.png[/attachment]

Aside note: I tried using mapPps(x, PPS_OUT_GPIO); that I found in another post but I don't think that the function is recognized (it compiles but is not highlighted orange like regular functions).

Any tips or suggestions are appreciated.

Thanks,


majenko

Thu, 22 May 2014 06:43:17 +0000

Have you looked in the Board_Data.c file in the chipKIT_Pi variant folder in the IDE?

There it lists all the pins:

const uint8_t   digital_pin_to_port_PGM[] = {
    // Pins 0 through 18
    _IOPORT_PA, //  0   RA4     SOSCO/RPA4/T1CK/CTED9/PMA1/RA4
    _IOPORT_PB, //  1   RB4     SOSCI/RPB4/RB4
    _IOPORT_PB, //  2   RB5     TMS/RPB5/USBID/RB5
    _IOPORT_PB, //  3   RB13    AN11/RPB13/CTPLS/PMRD/RB13
    _IOPORT_PB, //  4   RB1     PGEC1/AN3/C1INC/C2INA/RPB1/CTED12/PMD1/RB1 (does not come out on Arduino header)
    _IOPORT_PB, //  5   RB0     PGED1/AN2/C1IND/C2INB/C3IND/RPB0/PMD0/RB0 (does not come out on Arduino header)
    _IOPORT_PA, //  6   RA2     OSC1/CLKI/RPA2/RA2 (does not come out on Arduino header)
    _IOPORT_PA, //  7   RA3     OSC2/CLKO/RPA3/PMA0/RA3 (does not come out on Arduino header)
    _IOPORT_PB, //  8   RB10    PGED2/RPB10/D+/CTED11/RB10
    _IOPORT_PB, //  9   RB11    PGEC2/RPB11/D-/RB11
    _IOPORT_PB, // 10   RB7     TDI/RPB7/CTED3/PMD5/INT0/RB7
    _IOPORT_PA, // 11   RA1     PGEC3/VREF-/CVREF-/AN1/RPA1/CTED2/PMD6/RA1
    _IOPORT_PB, // 12   RB8     TCK/RPB8/SCL1/CTED10/PMD4/RB8
    _IOPORT_PB, // 13   RB14    CVREF/AN10/C3INB/RPB14/VBUSON/SCK1/CTED5/RB14
    _IOPORT_PA, // 14   RA0     PGED3/VREF+/CVREF+/AN0/C3INC/RPA0/CTED1/PMD7/RA0 (Jumper to either Arduino Analog 1 or LED1)
    _IOPORT_PB, // 15   RB15    AN9/C3INA/RPB15/SCK2/CTED6/PMCS1/RB15 (Jumper to either Arduino Analog 1 or LED2)
    _IOPORT_PB, // 16   RB2     AN4/C1INB/C2IND/RPB2/SDA2/CTED13/PMD2/RB2 (Arduino A4 / SDA)
    _IOPORT_PB, // 17   RB3     AN5/C1INA/C2INC/RTCC/RPB3/SCL2/PMWR/RB3 (Arduino A5 / SCL)
    _IOPORT_PB, // 18   RB9     TDO/RPB9/SDA1/CTED4/PMD3/RB9 (does not come out on Arduino header - used for Bootloader Enable switch)
}

Cross-referencing those with the datasheet you can easilly map from pin names to physical pins.

Note the little message by pin RB9 (IDE pin 18, physical pin 18). It's used for the bootloader enable switch.


djgardn2

Thu, 22 May 2014 09:51:14 +0000

Thank you for the suggestion to look at the Board_Data.c file, but I might not be understanding it fully and plan to look at it again in the near future.

I attempted to digitalWrite(digital_pin_to_port_PGM[18], HIGH); without success, it was instead blinking factory physical pin 14 (very bottom left physical pin).

The only way I have successfully coded the factory physical pin 18 (RB9) is by the following:

TRISB =0; PORTBbits.RB9 =1;

Trying the following below does not work for physical pin 18 (RB9), but instead it lights the physical pin 11 (RB4):

digitalWrite(PORTBbits.RB9, HIGH);

I appreciate anyone's tips on other ways to access factory physical pin 18 (RB9) or even different ways or styles that you can access IO pins.


majenko

Thu, 22 May 2014 13:03:25 +0000

Just this should work:

pinMode(18, OUTPUT);
digitalWrite(18, HIGH);

The "18" looks up the port and pin details in the tables in the variant files and uses them to control the registers.


GrahamM242

Thu, 22 May 2014 13:08:28 +0000

The Board_Data.c contains digital_pin_to_port_PGM[] and digital_pin_to_bit_mask_PGM[]. The first array is a map from chipkit pin # to IOPort. The second array is a map from chipkit pin # to bitmask. The two work in conjunction as a bitmask to apply to an IOPort.

digitalWrite() only accepts a chipkit pin #, which is why digitalWrite(digital_pin_to_port_PGM[18], HIGH); won't work. In fact, the digital_pin_to_port_PGM array has the value of _IOPORT_PB stored at the index of 18. _IOPORT_PB happens to have a value of 2, which corresponds to the pin that you managed to access.

You should be able to just do

pinMode(18,OUTPUT);
digitalWrite(18,HIGH);

to access that pin, as it's already defined in the digital_pin_to_xxx arrays.


djgardn2

Thu, 22 May 2014 16:45:10 +0000

Thank you both for helping me.

I tested this below and it does not work. I am still unable to access the pin this way.

pinMode(18,OUTPUT);
digitalWrite(18,HIGH);

Possibly there is something else missing, I have tested on two different bootloader versions with out any success.

Thanks, any insight helps.


EmbeddedMan

Thu, 22 May 2014 16:56:58 +0000

Hmm. I guess I never tested that because pin 18 doesn't come out on the Arduino headers. It should work, as you have it. If not I must have made a mistake in the variants files.

How are you testing pin 18? (i.e. how are you reading it's output voltage?) if you have it plugged into the Pi, make sure you remember that chipKIT Pi pin 18 is tied to the Raspberry Pi's connector on pin 7. Also remember that if you want it to come out the TDO pin, make sure to set JP6 to the TDO position.

*Brian


djgardn2

Thu, 22 May 2014 17:06:50 +0000

Thanks for looking into this for me.

I have the PIC32 on a breadboard. Currently it is just attached to an LED on the breadboard attached to that pin.


EmbeddedMan

Thu, 22 May 2014 17:21:47 +0000

Ahh! I see. You're making your own version. Cool.

When I get home today, I'll give this a test and see if it works on a real chipKIT Pi. If it doesn't, then I'll find the problem and reply back to this thread.

*Brian


djgardn2

Sun, 25 May 2014 01:23:05 +0000

If you want to see one of my small projects I have been working on, check out this link of it with a live video demo found below.

It is a simple LED light display, with the display easily changeable for any occasion.

[url]http://www.chipkit.net/forum/viewtopic.php?f=15&t=2937[/url]

[url]https://www.youtube.com/watch?v=qUkfxSXcfig&feature=youtu.be[/url]


djgardn2

Thu, 12 Jun 2014 05:33:36 +0000

Hello,

I just wanted to check in to see if anyone ever got a chance to test digital pin 18 out or if this functionality is missing? No rush, thanks to anyone that looks into this.

I wanted to mention a few things I noticed when looking through the Board_Defs.h for the chipKIT PI.

LINE 63: NUM_DIGITAL_PINS is 18 (should this be 19) LINE 64: NUM_ANALOG_PINS is 10 (should this be 9) LINE 146: PIN_INT0 is 11 (should this be 10 (RB7), 11 is mapped to RA1, comment on this line says it is RB7 that is non-PPS)

I don't know if my understanding of this is incorrect or not so feel free to disregard my comment if this is correctly arranged.

Two side questions if anyone can answer:

  1. Does PPS (mapPps() function) work on the chipKIT PI using MPIDE? I have had no luck in programing this functionality for PPS_OUT_U2TX and PPS_IN_U2RX.

My ultimate goal is to have two PIC32MX250F128B chips to communicate on a breadboard once programed with the chipKIT PI.

  1. Does interrupts (attachInterrupt() function) work on the chipKIT PI using MPIDE? I haven't had any luck getting this to work in MPIDE with expected results, some might work but are mapped to different pins then expected.

Thanks.


EmbeddedMan

Thu, 12 Jun 2014 09:00:56 +0000

I have tested digital pin 18, and it DOES work, but you have to set NUM_DIGITAL_PINS to 19 as you suggest in order for it to work.

You are correct about the NUM_DIGITAL_PINS. It should be 19. The NUM_ANALOG_PINS is correct at 10, however, as we need to be able to represent analog inputs 0 through 9, which is 10 total.

For PIN_INT0, you are correct, it should be at 10.

The PPS mapping functions should work just fine on chipKIT Pi. I haven't had any problems with them, but I'll admit I haven't tried remapping UART2. I will try this and let you know.

attachInterrupt() does work. Please see the tests.txt file in the hardware\pic32\variants\ChipKIT_Pi\ folder. It also has a lot of other useful information that I wrote up about getting the board to work. (note that the current tests.txt says that INT0 is on 11 when it is in fact on pin 10)

I have made changes to the chipKIT Pi variants files for the above that will be included in the next MPIDE build. Thank you so very much for finding these bugs!

*Brian


EmbeddedMan

Thu, 12 Jun 2014 10:15:13 +0000

Note that the previous post I wrote has been edited several times as I figured stuff out.

About the mapPps() for UART2. I had no trouble getting it to work. For example, this sketch allowed me to remap U2RX to pin 11 and U2TX to pin 13.

*Brian

int inByte = 0;
void setup()
{
  Serial1.begin(9600);
  mapPps(11, PPS_IN_U2RX);
  mapPps(13, PPS_OUT_U2TX);
}

void loop()
{
  if (Serial1.available() > 0) {
    inByte = Serial1.read();
    Serial1.println(inByte, DEC);
  }
  delay(250);
  Serial1.println("Serial1");
}

djgardn2

Thu, 12 Jun 2014 21:56:10 +0000

Thanks for adding those new changes to be included in the next build, I will certainly appreciate accessing as many possible pins in the future for small projects.

It seems I didn’t have the latest MPIDE downloaded with the new tests.txt file so I didn’t see the PPS examples, extremely useful. It turned out that I didn’t think to make the pin an input before using the attachInterrupt function. I will look at the serial code segment and will plan to give it a try again in the near future.

Also, about the NUM_ANALOG_PINS, I was just looking at the PIC datasheet on page 20 of 330 from the 60001168F.pdf file counting only 9 Analog pins (a note attached to the 10th pin says that it is for MX1xx devices only). Then what also made me think it should be 9 is referring to the DP32 Board_Defs.h file it is defined as 9 there also. Just a side note in case it is useful or not, I could be easily misunderstanding it.

Thanks again for all the help and looking into everything for me, appreciate it.