FLEX Board USB Connection
FLEX Board USB Connection
com/print/51822
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" // Required
#include "system\usb\usb.h" // Required
#include "io_cfg.h" // Required
/** 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 ***************************************/
/** 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
}
_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; // index of USB buffer
void main(void)
{
int i;
InitializeSystem();
for (i=0; i
Trademarks
Links:
[1] http://dev.emcelettronica.com/usb
[2] http://dev.emcelettronica.com/Flex
[3] http://www.evidence.eu.com/content/view/250/266/