PIC32MX220 USB project demo code

Many people interesting how to create USB device using the microcontroller. Microchip Technology produces many microcontrollers with USB port. For the demo purpose I use new microcontroler PIC32MX220F032B. Circuit diagram of my demo board you can find here.


In order to connect USB device to the computer you will first need to write and compile firmware.   For this reason I took project “Device – HID – Custom Demos” from Microchip’s Application Library and adapted it to the PIC32MX220 microcontroller.


  • Firmware is targeted for the Microchip C32 compiler
  • Microchip’s Application Library must be installed before (for the USB stack)
  • At this moment polling method only is supported

How to run project?

1. Install Microchip’s Application Library (tested version 2012-02-15).

2. Copy project folder to USB folder of the MAL, for e.g:

C:\Microchip Solutions v2012-02-15\USB\USBDevice – HID – Custom Demos PIC32MX2\Firmware…..

3. Build project and program your MCU.

4. Attach MCU to the USB Host.

The reference hardware provides 2 LEDs – one indicate power, second (RB15 pin) flashes after USB is attached. For the demo purposes I left 2 files of the host (Windows) software – GenericHIDSimpleDemo.exe and HID PnP Demo.exe

Projects and source code of these files you can find in Microchip Application Library, “USBDevice – HID – Custom Demos” folder.

Project and firmware for the microcontroller you can download here:

MPLAB project files for the PIC32MX220F032B firmware

Posted in MCU - Development kits, PIC32 projects | Tagged , , , | Leave a comment

PIC32MX220 demo board Gerber files

I just received question about gerber files of my PIC32MX220 demo board. I prepared them and uploaded to the server:

Download Gerber files

Please write me if there will be some errors or etc.

P.s. I just tested USB port – it is working :)

Posted in PIC32 projects | Tagged , , | Leave a comment

PIC32MX220 demo project – delay using the 32-bit Core Timer

The MIPS M4K core of the PIC32 has the 32-bit Core Timer. This timer is fed by the system clock rather than the peripheral bus clock like all other timers. It has a fixed prescaler 1:2 and can be used for the shedulling, self timing applications and etc.

In order to use the Core Timer function DelayMs is defined:

void DelayMs(unsigned int msec)
unsigned int tWait;
while(ReadCoreTimer() < tWait);

Download complete project in C32.

Posted in PIC32 projects | Tagged , , , , | Leave a comment

PIC32MX220F032B demo code – input change notification interrupt

The PIC32MX1XX/2XX interrupt module includes the following features – up to 64 interrupt sources, single and multi-vector mode operations, seven priority levels with four subpriority levels within each priority.

The input change notification function of the I/O ports allows PIC32MX220 microcontroller to generate interrupt requests to the processor in responce to a change-of-state on selected input pins.  Every I/O port pin in this microcontroller can be selected for generating an interrupt request on a change-of-state.

In this demo project we use RB13 pin to generate interrupt. Every time the push button (PORTB.RB13) is pressed, CN interrupt will accour and the LED (PORTB.RB15) will be toggled on and off.

Download complete project in C32.

Posted in MCU - Projects, PIC32 projects | Tagged , , , , | Leave a comment

Second PIC32MX220F032B demo code – how to read input from push button

This demo project shows how to read digital input  from push button.

Every time the push button (PORTB.RB13) is pressed, the LED (PORTB.RB15) will be toggled on and off.

For the input reading we use simple polling method. When the switch is open input pin RB13 is pulled up through external 10k resistor – microcontroller will read this input as “high” (logic “1″). When the switch is pressed, RB13 is pulled down and microcontroller will read this pin as logic “0″.

Schematic of the PIC32MX220 development board you can find in my post.

Download complete project in C32.

Posted in PIC32 projects | Tagged , , , | Leave a comment

First PIC32MX220F032B demo code – flashing an LED

This is simple test project for the PIC32MX220 MCU. While this code looks very simple, it is the best project to start study microcontroller.

I tested this code on my “self-made” board.

LED is connected to port pin RB15; it flashes about 2 timer per second.

You can download complete project here.

Pay attention to the configuring of pin. C32 compiler has I/O PORT library with macros. But there is small mismatch between the older PIC32 and new PIC32MX1/MX2. For e.g. in PIC32MX795 only PORTB share analog and digital function; operation of the analog port pins controls AD1PCFG register. While in PIC32MX220 analog function share some pins from PORTA and PORTB ports; operation of the analog pins control ANSELA and ANSELB registers. For this reason, macro mPORTBSetPinsDigitalOut() is not appropriate.

Posted in MCU - Projects, PIC32 projects | Tagged , , , , | Leave a comment

Self-made development board for the 32-bit PIC32MX220F032B Microcontroller

Few months ago Microchip introduced smallest, lowest-cost PIC32 microcontrollers – new PIC32”MX1” and PIC32”MX2” families. PIC32 MX1 and MX2 MCUs include up to 32 KB of Flash and 8 KB of SRAM, two I2S interfaces for audio processing, 10-bit 1 Msps ADC, an 8-bit Parallel Master Port and serial-communications peripherals. MX2 MCUs also have USB 2.0-compliant full-speed module.

For the prototyping purposes I made small development board with PIC32MX220F032B MCU. This board includes all of the external circuitry needed to get the PIC32 up and running. Power can be provided over USB or from an external source. It has 2 push buttons (Reset and 1 user-defined button) and 2 LEDs (Power and 1 user defined LED).

Continue reading

Posted in MCU - Development kits | Tagged , , , | 3 Comments

Microchip Introduces Smallest, Lowest-Cost PIC32 Microcontrollers

Microchip Technology Inc., a leading provider of microcontroller, analog and Flash-IP solutions, Oct. 24, 2011 announced a new series of low pin count 32-bit PIC32 microcontrollers (MCUs) that provide 61 DMIPS of performance in packages as small as 5 mm x 5 mm for space-constrained and cost-sensitive designs. The PIC32 “MX1” and “MX2” MCUs are the smallest and lowest-cost PIC32 microcontrollers, and are the first PIC32s to feature dedicated audio and capacitive-sensing peripherals. These new MCUs include a host of additional useful features that make them suitable for applications in the consumer, industrial, medical and automotive markets.

Rated for operation up to 105°C, the PIC32 MX1 and MX2 MCUs include up to 32 KB of Flash, and 8 KB of SRAM; two I2S interfaces for audio processing; Microchip’s Charge Time Measurement Unit (CTMU) peripheral for adding mTouch™ capacitive touch buttons or advanced sensors; and an 8-bit Parallel Master Port (PMP) interface for graphics or external memory. The new devices also feature an on-chip 10-bit, 1 Msps, 13-channel Analog-to-Digital Converter (ADC), as well as USB 2.0, and serial-communications peripherals. The MCUs bring eight new packages to the PIC32 MCU product line, from 28- to 44-pins, with sizes down to 5 mm x 5 mm and a 0.5 mm pitch. Further easing the design effort is Microchip’s Peripheral Pin Select feature, which allows developers to “remap” most digital-function pins in the chip, making layout and design modifications significantly simpler. The PIC32 MX1 and MX2 devices are compatible with Microchip’s 16-bit PIC24F product line for easy migration, and are supported by the MPLAB® X IDE—the single development environment for all of Microchip’s 8-, 16- and 32-bit MCUs.

“More designs in the consumer, industrial, medical and other markets are requiring high-quality audio, touch-sensing and graphics capabilities, as well as USB communication,” said Sumit Mitra, vice president of Microchip’s High-Performance Microcontroller Division. “With their numerous on-chip peripherals and features in small packages, the PIC32 MX1 and MX2 enable designers to add all of this functionality, while keeping design size and costs low.”

For further information, contact any Microchip sales representative or authorized worldwide distributor, or visit Microchip’s Web site at http://www.microchip.com/get/7NBT.

Posted in MCU - Market news | Tagged , , | Leave a comment

Wireless data transmission between two PIC microcontrollers using low-cost RF modules

A lot of times we need to keep track of data from a device or a sensor located in a remote location from the point where it is processed. In other situations we desire wireless solutions for ease. Using long cables, infrared (IR) or other means are often tedious and not loss-less. Imagine collecting pH level data from a chemically lethal or toxic treatment plant where human presence is highly health hazardous. Running long cables from the pH sensor to the control or monitor station will surely introduce noisy signals and signal-to-noise ratio will thus drastically decrease. The result is erroneous data acquisition and thereby false decisions may be generated. If infrared signals or other optical means including lasers are used, they will need good obstacle-free line of sight or expensive and delicate optical fibers. Thus the solution stays in the radio frequency (RF) domain. This article talks about interfacing low cost RF modules (KST-TX01 and KST-RX806) for transmitting data between two remotely located PIC microcontrollers.

The theory is pretty simple and straight. It uses KST-TX01 and KST-RX806 RF modules which is a 433 MHz serial data transmitter/receiver pair. One PIC16F877A is programmed to transmit its ADC data (RA0/AN0 channel) serially using its built-in USART hardware at 1200 baud with no parity and 8-bit data stream. The PIC’s USART transmitter (TX) pin feeds the data into the data pin of the KST-TX01 which transmits it using 433 MHz ASK RF signal. On the receiving end the KST-RX806 module receives the data and its output is connected to the another PIC’s USART input pin. The second PIC is programmed to read its USART receiver (RX) pin. On both ends, two LCD displays are also connected which show the transmitted and received bytes. Since RS232 communications typically allow 8-bit data, the 8-bit A/D conversion is used here for simplicity, instead of the more common 10-bit ADC.

Read more at http://embedded-lab.com/blog/?p=3557

Posted in MCU - Wireless communication | Tagged , , | Leave a comment

Low cost temperature data logger using PIC and Processing

This project describes an easy and inexpensive way of adding a digital thermometer and data logging feature to a PC. It involves a PIC microcontroller that gets the surrounding temperature information from the Microchip MCP9701 sensor, and sends it to a PC through an USB-UART interface. The USB port of the PC is also used to power the device. The open-source Processing programming platform is used to develop a PC application that displays the temperature in a graphics window on the computer screen. The PC application also records the temperature samples plus date and time stamps on an ASCII file.

This project is based on Microchip’s PIC12F1822 microcontroller from the enhanced mid-range PIC family. It has got 8-pins in total and the power supply voltage range of 1.8V to 5.5V. The microcontroller has four 10-bit ADC channels and one Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) module for serial communication. The temperature sensor used here is MCP9701A, which is a Low-Power Linear Active Thermistor IC from Microchip Technology. The range of temperature measurement is from -40°C to +125°C. The output voltage of the sensor is directly proportional to the measured temperature and is calibrated to a slope of 19.53mV/°C. It has a DC offset of 400mV, which corresponds to 0°C. The offset allows reading negative temperatures without the need for a negative supply. The output of the sensor is fed to one of the ADC channels of the PIC12F1822 microcontroller for A/D conversion. The internal fixed voltage reference (FVR) module is configured to generate a stable 2.048 V reference voltage for A/D conversion. The use of FVR module ensures the accuracy of the A/D conversion even when the supply voltage is not stable. The PIC12F1822 microcontroller then serially transmits the 10-bit ADC output to a PC.

The circuit diagram of this project is pretty simple. The microcontroller reads the temperature sensor’s output through RA2/AN2 pin and convert it to a 10-bit digital number. The Tx (RA0) and Rx (RA1) port of the EUSART module are connected to the corresponding pins of the USB-UART module.

Read more at www.embedded-lab.com

Posted in MCU - Measurement, MCU - Projects | Tagged , , , | Leave a comment