This shows you the differences between two versions of the page.
Next revision Both sides next revision | |||
pic32mx270f256b [2019/04/25 11:46] sausage created |
pic32mx270f256b [2019/04/25 12:50] sausage |
||
---|---|---|---|
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 25: | Line 29: | ||
* 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. | ||
Line 30: | Line 35: | ||
Also between Pin 20 (CAP) and Pin 9 (VSS) add a 0.01uf capacitor. | Also between Pin 20 (CAP) and Pin 9 (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|page 28 of the PIC32MX270F256B Datasheet]], Figure 2-1. | ||
Line 42: | Line 49: | ||
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 and in the main.c file, add the following before the while loop: | ||
+ | <code> | ||
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 = 0b00000010; //set pin 3 (RA1) to on. (supply 3.3 volts) | ||
Line 64: | Line 74: | ||
{ | { | ||
} | } | ||
+ | </code> | ||
- | 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\PIC32MX270F256B-cpp\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> | ||
+ | TRISA = 0b00000000; //all PortA pins are output | ||
+ | PORTA = 0b00000010; //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++; | ||
+ | } | ||
+ | </code> | ||
===== What happens if? ===== | ===== What happens if? ===== | ||
Line 91: | Line 117: | ||
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. | |
- | ---------------- | + | | No 0.1uf bypass capacitors | Unstable effects |No noticeable effect on basic test| |
- | Component For Programming For Execution | + | | No External Oscillator | Not required | Internal can be used | |
- | Not using a pull up on MCLR to Positive No effects Safety to keep a floating pin from random resets on the PIC. | + | |No AVDD on Pin 28|PIC can't be found|?| |
- | 0.1uf bypass capacitors on each side +/- Unstable effects No noticeable effect on basic test | + | |No AVSS on Pin 27|PIC can't be found|Executes normally| |
- | External Oscillator Not required Internal can be used | + | |No Cap between VCAP on 20 to 21 to GND |?|Executes normally| |
- | No AVDD on Pin 28 PIC can't be found | + | |No VDD on Pin 13| ? |Executes normally| |
- | No AVSS on Pin 27 Executes normally | + | |No VSS on Pin 8| ? |Executes normally| |
- | No Cap between VCAP on 20 to 21 to GND Executes normally | + | |No PGEC1 connected | Cannot connect to target device | ? | |
- | No VDD on Pin 13 Executes normally | + | |No PGED1 connected | Cannot connect to target device | ? | |
- | No VSS on Pin 8 Executes normally | + | |
- | No PGEC1 connected Cannot connect to target device | + | |
- | No PGED1 connected Cannot connect to target device | + | |