Hi all,

I am trying to get a USB Project going but have hit a brick wall.

I am using Picbasic Pro 2.50a with microcode Studio. I used EasyHID wizard to create the template files and to check all was well before continuing I set it up to continually send some bytes over USB and used Darrel Taylors HID monitor to check what was being received.

What I can't figure out is that despite trying to send some characters all I get in HIDMonitor is 8 bytes of 0x00. The device is enumerated OK and remains connected but the data just does not get through.

Its driving me absolutely insane because I have code a lot more complicated than this that works fine. The code is below, if anybody can offer some assistance that would be great!

Thanks

Andy

Code:
' ==============================================================================
' PIC Configuration Bits
' ==============================================================================
 
  
  asm
    __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
                            ;              ;                      ; USB clock source comes from the 96 MHz PLL divided by 2
                            ;              ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
                            ; No prescale (4 MHz oscillator input drives PLL directly)


    __CONFIG    _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H 
                            ;                  ;               ; Oscillator Switchover mode disabled
                            ;                  ; Fail-Safe Clock Monitor disabled
                            ; XT oscillator, PLL enabled, XT used by USB
    __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L  & _BORV_2_2L  & _VREGEN_ON_2L   
    __CONFIG    _CONFIG2H, _WDT_OFF_2H 
    __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_OFF_3H 
    __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L ;& _ICPRT_OFF_4L  & _XINST_OFF_4L & _DEBUG_OFF_4L 
    endasm

DEFINE OSC 48

USBBufferSizeMax   con 8  ' maximum buffer size
USBBufferSizeTX    con 8  ' input 
USBBufferSizeRX    con 8  ' output

' the USB buffer...
USBBuffer        Var Byte[USBBufferSizeMax] 
USBBufferCount   Var Byte 
' Used by USB initialisation:
usb_device_state        var byte EXT
CONFIGURED_STATE        CON EXT

' Used in USB Comms
IDLEIF                  VAR UIR.4
SOFIF                   VAR UIR.6
Plugged                 VAR BIT
i var byte
' ==============================================================================
' Hardware configuration
' ==============================================================================

    TRISA = 0                   ' all outputs
    TRISB = %00010000           ' only RB4 as input so others are excluded from IOC
    TRISC = 0                   ' all outputs

    PORTA = 0                   ' set all LEDs off at startup
    PORTB = 0
' ==============================================================================
' A/D converter
' ==============================================================================
'         
    ADCON0  =   %00000000       ' A/D converter module disabled
    ADCON1  =   %00001111       ' PORTA all digital signals

' ==============================================================================
' USB module
' ==============================================================================

    ucfg    =   %00010100       ' enable internal USB pull-up, Full speed USB


PORTA.1 = 1 
' ************************************************************
' * main program loop - remember, you must keep the USB      *
' * connection alive with a call to USBService every couple  *
' * of milliseconds or so...                                 *
' ************************************************************

usbinit ' initialise USB...

    repeat  ' kick-start it by performing a tight loop of servicing until the USB
            ' state is CONFIGURED
        usbservice
    until usb_device_state = CONFIGURED_STATE
PORTA.1 = 0
PORTA.0 = 1    
ProgramStart: 
   'gosub DoUSBIn
   toggle PORTA.2
   for i = 1 to 10000
        USBSERVICE
    pause 2
   next i
   gosub DoUSBOut
   goto ProgramStart  

' ************************************************************
' * receive data from the USB bus                            *
' ************************************************************
DoUSBIn:
   USBBufferCount = USBBufferSizeRX              ' RX buffer size
   USBService                                    ' keep connection alive
   USBIn 1, USBBuffer, USBBufferCount, DoUSBIn   ' read data, if available
   return
    
' ************************************************************
' * wait for USB interface to attach                         *
' ************************************************************
DoUSBOut:
   USBBufferCount = USBBufferSizeTX              ' TX buffer size
   USBBuffer[1] = "a"
   USBBuffer[3] = "F"
   USBService                                    ' keep connection alive
   USBOut 1, USBBuffer, USBBufferCount, DoUSBOut ' if bus available, transmit data
   USBSERVICE
   return