This demo shows how to set up a USB connection between the PC and the FLEX board. The aim is to control the dsPIC LED and the PIC18 LED system from the host PC. The dsPIC LED is controlled by the SPI communication with the PIC18.
The application is divided into three parts:
- In the first part a brief description of the USB set-up is provided. The aim is to give a brief overview of the USB protocol.
- The second part concerns the dsPIC side with the use of the SPI connection with the PIC18.
- The third part concerns the PC side application. You can download a simple application under Windows (XP or Vista) to communicate with FLEX in order to switch on and off both LEDs of dsPIC and PIC18.
Future application notes will develop the USB connection up to the control of the dsPIC functions through the host PC with a Linux application.
On the FLEX side:
- The software is based on the PICkit2 firmware provided by Microchip. This allows to use the HID set-up for the PIC18.
- The dsPIC is programmed using Erika. This example uses functions for the SPI not yet implemented in Erika 188.8.131.52, please download this patch and extract the the folders ee/ and examples/ in the Evidence tree.
- On the PC side, you need a specific application that identifies and enumerates the device and that is able to send and receive data through USB.
This is the list of hardware components needed to reproduce the demo:
- FLEX board, full version
- ICD2 programmer
Now you have two options:
- Use the demo board for SPI communication between PIC18 and dsPIC
- Use wires to connect directly the PIC18 with dsPIC without the demo board
Notes ONLY for the users that do NOT use the demo board
The demo board provide correct SPI connection between the PIC18 and the dsPIC. If you are not using the demo board you can set-up manually a SPI connection. For safety considerations it is STRONGLY recommended to use the same voltage for both dsPIC and PIC18, 3.3V. If you look to the picture below you can identify the jumper JP9 near PAD1 (red circle).
With PAD1 you can select the power source for the PIC18 (from switching power supply (jumper in high position) or from USB (jumper in low position)). At the right side of PAD1 a single pin is present. This is the 3.3V power supply pin. Now you have to put the jumper between the second pin of PAD1 (in the middle) and this 3.3V pin as depicted in the next picture.
In this application note the PIC18 is only a transceiver since it receives messages from the host PC through a USB connection and forwards these messages to the dsPIC through a SPI connection. The PIC18 has a full speed USB 2.0 interface that allows to easily implement USB connection with host computers. The PIC18 can be only a device. We used the code furnished by Microchip to implement the HID behaviour of the PIC18. We used only two endpoints: the EP0 that is mandatory for controlling the USB communication and the EP1 that is an interrupt endpoint. Data pass through this last endpoint. The code that you will find attached to this application note is based on the PickKit2 from Microchip.
The dsPIC receives data from the SPI interface. It can receive a switch on or off the system LED. The application has been written using Erika for dsPIC. This is very simple since it creates one periodic task that controls the SPI buffer and interprets the command received to switch on and off the system LED.
The PC application accepts in input only four commands: a for the Flex board init, t for dsPIC system LED toggle, p for PIC18 system LED toggle, h for help.