Hi all,
I trying to send a two byte word down the pipe but I cannot get the received data to equal what's been sent. ASCII char are fine as each is one byte long. I can send a one byte number like 255 and all good. I'm not quite sure if I load a word variable with two bytes from the buffer, like word.byte0=buff[0], word.byte1=buff[2] is where the problem is? The number being transmitted is not ASCII but is a number 0 to FFFF, scratching my head now. Any ideas?
Thanks
John
Code:
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
endasm
DEFINE OSC 48
INCLUDE "cdc_desc.bas" 'Descriptor file for CDC serial demo
;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
Include "modedefs.bas"
;------LCD -----//
' Set LCD Data port
DEFINE LCD_DREG PORTD
' 'Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' ' Set LCD Register Select port
DEFINE LCD_RSREG PORTD
' 'Set LCD Register Select bit
DEFINE LCD_RSBIT 2
' 'Set LCD Enable port
DEFINE LCD_EREG PORTD
' 'Set LCD Enable bit
DEFINE LCD_EBIT 3
' 'Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' 'Set number of lines on LCD
DEFINE LCD_LINES 2
' 'Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' ' Set data delay time in us
DEFINE LCD_DATAUS 50
buffer Var byte[5]
buffer2 var BYTE[2]
cnt Var Byte
position var word
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_INT, _DoUSBSERVICE, ASM, yes
INT_Handler INT_INT, _Handle_INT, PBP, yes
endm
INT_CREATE ; Creates the Low Priority interrupt processor
INT_ENABLE USB_INT ;we will do this after we initialize USB
INT_ENABLE INT_INT
ENDASM
;----[Initialise USB and Interrupts]----------------------------------------
PAUSE 100 ; Allow VUSB to stabilize
USBINIT ; initialize the USB driver
USBSERVICE ; service it once
UIE = $7F ; enable USB interrupts
UEIE = $9F ; enable USB Error interrupts
@ INT_ENABLE USB_INT
;----[Main program loop]----------------------------------------------------
lcdout $FE, 1, "Begin"
pause 1000
Main:
cnt = 2 ' Specify input buffer size
USBIn 3, buffer2, cnt, main
'lcdout $FE, 1, str buffer2\4 'this displays ASCII ok provided cnt=4
position.byte0=buffer2[0]
position.byte1=buffer2[1]
lcdout $FE, 1, DEC position
outloop:
USBOut 3, buffer2, 2, outloop
GOTO Main
;----[Interrupt handler -- Service USB]-------------------------------------
DoUSBSERVICE:
USBSERVICE ; Run the SERVICE routines
@ INT_RETURN
;----[Interrupt handler -- INT]
Handle_INT:
; something here
@ INT_RETURN
Bookmarks