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:
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:
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:
Now you have two options:
In the figure below you can see the conceptual diagram of the connections.
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.
This application note has been moved to the ERIKA Wiki