This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
pic32mx270f256b [2019/04/25 12:54] sausage |
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 28: | 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. | ||
- | |||
- | {{ :pic32mx270f256b-breadboard-components.jpg?nolink |}} | ||
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. | ||
Line 65: | Line 63: | ||
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: |
- | <code C> | + | <code ini> |
- | TRISA = 0b00000000; //all PortA pins are output | + | New Project > Microchip Embedded > Standalone Project |
- | PORTA = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | + | |
+ | 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> | </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. | ||
Line 84: | Line 120: | ||
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. | ||
Line 96: | Line 132: | ||
<code c> | <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 | TRISA = 0b00000000; //all PortA pins are output | ||
- | PORTA = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | + | PORTA = 0b00000001; //set pin 3 (RA1) to on. (supply 3.3 volts) |
| | ||
int count = 0; | int count = 0; | ||
- | | + | |
while(1) | while(1) | ||
{ | { | ||
Line 108: | Line 154: | ||
count = 0; | count = 0; | ||
} | } | ||
- | | + | |
count++; | count++; | ||
} | } | ||
+ | | ||
+ | return (EXIT_SUCCESS); | ||
+ | } | ||
</code> | </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 119: | Line 172: | ||
^ Component ^ During Programming ^ For Execution ^ | ^ Component ^ During Programming ^ For Execution ^ | ||
| Not using a pull up on MCLR to Positive | No effects | Could cause random resets on the PIC if the pin is floating. | | | 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 | - | | ||
| No 0.1uf bypass capacitors | Unstable effects |No noticeable effect on basic test| | | No 0.1uf bypass capacitors | Unstable effects |No noticeable effect on basic test| | ||
| No External Oscillator | Not required | Internal can be used | | | No External Oscillator | Not required | Internal can be used | |