Docstoc

FLEX Board USB connection

Document Sample
FLEX Board USB connection Powered By Docstoc
					FLEX Board USB connection

http://dev.emcelettronica.com/print/51822

Your Electronics Open Source
(http://dev.emcelettronica.com)
Home > My blog > Content

FLEX Board USB connection
By Ionela Created 01/07/2008 - 11:51

BLOG Microcontrollers Usb This demo shows how to set up a USB [1]connection between the PC and the FLEX board [2]. 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: 1. 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. 2. The second part concerns the dsPIC side with the use of the SPI connection with the PIC18. 3. 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.

/** I N C L U D E S **********************************************************/ #include #include #include "system\typedefs.h" #include "system\usb\usb.h" #include "io_cfg.h"

// Required // Required // Required

#include "system\usb\usb_compile_time_validation.h" // Optional #include "user\pickit.h" #include "user\pk_isr.h" /** V A R I A B L E S ********************************************************/ #pragma udata char inbuffer[64]; /** P R I V A T E P R O T O T Y P E S ***************************************/

static void InitializeSystem(void); void USBTasks(void); /** V E C T O R R E M A P P I N G *******************************************/

extern void _startup (void); // See c018i.c in your C18 compiler dir #pragma code _RESET_INTERRUPT_VECTOR = 0x002000 void _reset (void) { _asm goto _startup _endasm } #pragma code _HIGH_INTERRUPT_VECTOR = 0x002008 void _high_ISR (void) {

1 din 3

02.07.2008 13:21

FLEX Board USB connection

http://dev.emcelettronica.com/print/51822

_asm goto InterruptHandler _endasm } #pragma code InterruptVectorLow = 0x002018 void InterruptVectorLow (void) { _asm goto InterruptHandler // jump to interrupt routine _endasm } /** D E C L A R A T I O N S **************************************************/ #pragma code /****************************************************************************** * Function: void main(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: Main program entry point. * * Note: None *****************************************************************************/ unsigned char ReadSPI( void ) { SSPBUF = 75; // initiate bus cycle while ( !SSPSTATbits.BF ); // wait until cycle complete return ( SSPBUF ); // return with byte read } void Process_SPI(void){ if(PORTBbits.RB4 && INTCONbits.RBIF) { INTCONbits.RBIF=0; //if(ReadSPI()==0xaa) PORTBbits.RB5=!PORTBbits.RB5; ReadSPI(); } } void ProcessIO(void) { unsigned char usb_idx = 0; // jump to interrupt routine

// index of USB buffer

if (HIDRxReport(inbuffer, 64) > 0) // USB receive buffer has data { //PORTBbits.RB5=!PORTBbits.RB5; // do // { switch(inbuffer[usb_idx]) // parse buffer for commands { case 1: //WriteSPI(75); //switch on led PORTBbits.RB5=1; break; case 0: //WriteSPI(80); //switch off led PORTBbits.RB5=0; break; case 2: WriteSPI(80); //switch off led break; case 3: WriteSPI(75); //switch on led break; default: // End of Buffer or unrecognized command usb_idx = 64; // Stop processing. } // end switch // } while (usb_idx < 64); // end DO } // end if (HIDRxReport(inbuffer, 64) > 0) } // end void ProcessIO(void) void main(void) { int i; InitializeSystem(); for (i=0; i

2 din 3

02.07.2008 13:21

FLEX Board USB connection

http://dev.emcelettronica.com/print/51822

For more informations, click here [3]

Trademarks

Source URL: http://dev.emcelettronica.com/flex-board-usb-connection Links: [1] http://dev.emcelettronica.com/usb [2] http://dev.emcelettronica.com/Flex [3] http://www.evidence.eu.com/content/view/250/266/

3 din 3

02.07.2008 13:21


				
DOCUMENT INFO
Shared By:
Stats:
views:346
posted:7/2/2008
language:English
pages:3
Description: 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: 1. 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. 2. The second part concerns the dsPIC side with the use of the SPI connection with the PIC18. 3. 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.
About