This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
pic32mx270f256b [2019/04/25 11:46] sausage created |
pic32mx270f256b [2021/12/14 12:07] (current) sausage Updated missing details. New code. |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Minimum setup for a PIC32MX270F256B on a Breadboard + PICkit3 ====== | ====== Minimum setup for a PIC32MX270F256B on a Breadboard + PICkit3 ====== | ||
- | After discovering that my PIC32MX170F256B did not sport a USB module, I then purchased a PIC32MX270F256B which did have one. | + | My first experiments with PIC Microcontrollers was on the PIC32MX170F256B. But after discovering that there was no USB module on that controller, I then purchased a PIC32MX270F256B which did have one. |
This article serves as a reminder for the minimum setup for this microcontroller. | This article serves as a reminder for the minimum setup for this microcontroller. | ||
Line 10: | Line 10: | ||
{{ :pic32mx270f256b-pins.png?nolink |}} | {{ :pic32mx270f256b-pins.png?nolink |}} | ||
+ | |||
+ | Here is the overall layout on the breadboard: | ||
+ | |||
+ | {{ :pic32mx270f256b-breadboard-pickit3-overview.jpg?direct&400 |}} | ||
Note the following pins on the Microcontroller: | Note the following pins on the Microcontroller: | ||
Line 24: | Line 28: | ||
* Pin 2 (RA0) to the positive side of an LED. Negative side of the LED to a 10 Ohm resistor. Then to GND. | * Pin 2 (RA0) to the positive side of an LED. Negative side of the LED to a 10 Ohm resistor. Then to GND. | ||
* Pin 3 (RA1) to the positive side of an LED. Negative side of the LED to a 10 Ohm resistor. Then to GND. | * Pin 3 (RA1) to the positive side of an LED. Negative side of the LED to a 10 Ohm resistor. Then to GND. | ||
- | |||
On both the Power and Ground rails on the breadboard, add a 0.1uf capacitor each. | On both the Power and Ground rails on the breadboard, add a 0.1uf capacitor each. | ||
- | Also between Pin 20 (CAP) and Pin 9 (VSS) add a 0.01uf capacitor. | + | Also between Pin 20 (CAP) and Pin 19 (VSS) add a 0.01uf capacitor. |
- | Add a 10k pull up? resistor from Pin 1 (MCLR) to Power. MCLR is Master Clear or Reset. | + | Add a 10k pull up resistor from Pin 1 (MCLR) to Power. MCLR is Master Clear or Reset. |
- | That should be the minimum required to test the Microcontroller. | + | That should be the minimum required to test the microcontroller. |
- | You can also get a diagram of the recommended setup on page 28 of the PIC32MX270F256B Datasheet, Figure 2-1. | + | {{ :pic32mx270f256b-breadboard-components.jpg?nolink |}} |
+ | |||
+ | You can also get a diagram of the recommended setup on [[https://docs-apac.rs-online.com/webdocs/1385/0900766b8138548d.pdf#G3.1116201|page 28 of the PIC32MX270F256B Datasheet]], Figure 2-1. | ||
Line 42: | Line 47: | ||
Attach a USB cable between the PICkit3 and the computer's USB port. | Attach a USB cable between the PICkit3 and the computer's USB port. | ||
- | Load MPLABX IPE and go to Advanced Settings. | + | - Load MPLABX IPE and go to Advanced Settings. |
- | Choose Family: 32-bit MCUs | + | - Choose Family: 32-bit MCUs |
- | Choose Device: PIC32MX270F256B | + | - Choose Device: PIC32MX270F256B |
- | Under Power: Ensure 3.3V is chosen. | + | - Under Power: Ensure 3.3V is chosen. |
- | ICSP Options: Check the "Power Target Circuit from Tool" | + | - ICSP Options: Check the "Power Target Circuit from Tool" |
- | Back in Operate, click on "Read" to see if PICkit3 can find the microcontroller. | + | - Back in Operate, click on ''Read'' to see if PICkit3 can find the microcontroller. |
The Output should result in: | The Output should result in: | ||
+ | <code> | ||
Programmer to target power is enabled - VDD = 3.300000 volts. | Programmer to target power is enabled - VDD = 3.300000 volts. | ||
Target device PIC32MX270F256B found. | Target device PIC32MX270F256B found. | ||
+ | </code> | ||
- | A simple first test is to light an LED from RA1 which is pin 3 on the microcontroller. | + | A simple first test is to light an LED from ''RA1'' which is pin 3 on the microcontroller. |
- | In the MPLABX IDE, create a new C project and in the main.c file, add the following before the while loop: | + | In the MPLABX IDE, create a new C project by doing the following: |
- | TRISA = 0b00000000; //all PortA pins are output | + | <code ini> |
- | PORTA = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | + | New Project > Microchip Embedded > Standalone Project |
+ | |||
+ | Next > | ||
- | while(1) | + | Family: 32-bit MCUs (PIC32) |
- | { | + | Device: PIC32MX270F256B |
+ | |||
+ | Select Tool: PICkit3 | ||
+ | |||
+ | Next > | ||
+ | |||
+ | Select Compiler: XC32 Compiler | ||
+ | |||
+ | Project Name: MyTestProject (or anything really) | ||
+ | (keep all defaults) | ||
+ | |||
+ | Finish | ||
+ | |||
+ | Under ''Source Files'': | ||
+ | New > C Main File | ||
+ | Finish | ||
+ | </code> | ||
+ | |||
+ | Click the Build Spanner icon to test the project build. Should build successfully. | ||
+ | |||
+ | Change the whole c file to contain: | ||
+ | |||
+ | <code c> | ||
+ | #ifdef __XC32 | ||
+ | #include <xc.h> | ||
+ | #endif | ||
+ | |||
+ | #include <stdio.h> | ||
+ | #include <stdlib.h> | ||
+ | |||
+ | int main(int argc, char** argv) { | ||
+ | |||
+ | TRISA = 0b00000000; //all PortA pins are output | ||
+ | PORTA = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | ||
+ | |||
+ | return (EXIT_SUCCESS); | ||
} | } | ||
+ | </code> | ||
+ | |||
+ | The ''#include <xc.h>'' line includes defined variables like ''PORTA'' and ''TRISA''. | ||
- | A nice simple test. TRISA means all the A pins (RA0, RA1, RA2 etc). Setting each bit to 0 in this way means that every pin will be set as an output pin. This means that voltage can be output from the pin to power something. | + | A nice simple test. ''TRISA'' means all the A pins (RA0, RA1, RA2 etc). Setting each bit to 0 in this way means that every pin will be set as an output pin. This means that voltage can be output from the pin to power something. |
- | PORTA is the way of turning on or off that voltage. So in the above code, only pin 3 (RA1) will be supplied with 3.3 volts. All the other pins will be 0 volts. | + | ''PORTA'' is the way of turning on or off that voltage. So in the above code, only pin 3 (RA1) will be supplied with 3.3 volts. All the other pins will be 0 volts. |
- | As we did earlier on the breadboard, you have a wire from RA1, to a 100Ohm resistor, to an LED and then to ground. | + | As we did earlier on the breadboard, you have a wire from ''RA1'', to a 100Ohm resistor, to an LED and then to ground. |
Compile the code. A hex file will be created at: | Compile the code. A hex file will be created at: | ||
- | project\dist\PIC32MX270F256B-cpp\production\myfile.hex | + | project\dist\<my project name>\production\myfile.hex |
- | Switch back to the MPLABX IPE and browse for your hex file. Program it to the chip by clicking the Program button. | + | Switch back to the MPLABX IPE and browse for your hex file. Program it to the chip by clicking the ''Program'' button. |
The LED should light up. Good stuff. Your development flow is complete. | The LED should light up. Good stuff. Your development flow is complete. | ||
- | [] | ||
- | |||
- | Add flash with internal oscillator | ||
===== Programming two blinking LEDs ===== | ===== Programming two blinking LEDs ===== | ||
+ | To blink back and forth between the two leds, change the code to: | ||
+ | <code c> | ||
+ | #ifdef __XC32 | ||
+ | #include <xc.h> | ||
+ | #endif | ||
+ | |||
+ | #include <stdio.h> | ||
+ | #include <stdlib.h> | ||
+ | #include <plib.h> | ||
+ | |||
+ | int main(int argc, char** argv) { | ||
+ | |||
+ | TRISA = 0b00000000; //all PortA pins are output | ||
+ | PORTA = 0b00000001; //set pin 3 (RA1) to on. (supply 3.3 volts) | ||
+ | | ||
+ | int count = 0; | ||
+ | |||
+ | while(1) | ||
+ | { | ||
+ | if (count >= 500000){ | ||
+ | mPORTAToggleBits(BIT_0); | ||
+ | mPORTAToggleBits(BIT_1); | ||
+ | count = 0; | ||
+ | } | ||
+ | |||
+ | count++; | ||
+ | } | ||
+ | | ||
+ | return (EXIT_SUCCESS); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | Notice ''plib.h'' is included. This supports defines like ''mPORTAToggleBits''. All this changes in later versions. This document will be updated at some point. | ||
+ | |||
+ | And that gives a basic project that will alternate between flashing LEDs. | ||
===== What happens if? ===== | ===== What happens if? ===== | ||
Line 91: | Line 170: | ||
The following shows what happens, or what could happen if part of the minimum set up is not complete. This is only what I have noticed, the effects could be greater for others. | The following shows what happens, or what could happen if part of the minimum set up is not complete. This is only what I have noticed, the effects could be greater for others. | ||
- | + | ^ Component ^ During Programming ^ For Execution ^ | |
- | Table of effects | + | | Not using a pull up on MCLR to Positive | No effects | Could cause random resets on the PIC if the pin is floating. | |
- | ---------------- | + | | Pull up on MCLR to Negative | Cannot program | - | |
- | Component For Programming For Execution | + | | No 0.1uf bypass capacitors | Unstable effects |No noticeable effect on basic test| |
- | Not using a pull up on MCLR to Positive No effects Safety to keep a floating pin from random resets on the PIC. | + | | No External Oscillator | Not required | Internal can be used | |
- | 0.1uf bypass capacitors on each side +/- Unstable effects No noticeable effect on basic test | + | |No AVDD on Pin 28|PIC can't be found|?| |
- | External Oscillator Not required Internal can be used | + | |No AVSS on Pin 27|PIC can't be found|Executes normally| |
- | No AVDD on Pin 28 PIC can't be found | + | |No Cap between VCAP on 20 to 21 to GND |?|Executes normally| |
- | No AVSS on Pin 27 Executes normally | + | |No VDD on Pin 13| ? |Executes normally| |
- | No Cap between VCAP on 20 to 21 to GND Executes normally | + | |No VSS on Pin 8| ? |Executes normally| |
- | No VDD on Pin 13 Executes normally | + | |No PGEC1 connected | Cannot connect to target device | ? | |
- | No VSS on Pin 8 Executes normally | + | |No PGED1 connected | Cannot connect to target device | ? | |
- | No PGEC1 connected Cannot connect to target device | + | |
- | No PGED1 connected Cannot connect to target device | + | |