PDA

View Full Version : HID USB on 18F87J50



pedja089
- 13th August 2011, 21:31
Does someone have example for this PIC?
I can't get it to work...

pedja089
- 15th August 2011, 16:50
I searched the whole forum and I only found examples for the PIC18f2550 and 4550.
Does PBP2.60 support USB on 18F87J50?
For the second day of trying all possible examples and with all possible fuse configuration but nothing show in device menager, not even device not recognised...
I bought this development system (http://www.mikroe.com/eng/products/view/303/lv18f-v6-development-system/) from mikroe, thinking that the is a hardware problem, but still nothing...
What are my other options:confused:

ScaleRobotics
- 15th August 2011, 17:21
Should work. I had the 18F67J50 (same family) running CDC. I can try to get an example for it going for HID. By the way, are you using DT_HID260 ? Will try to get something up tonight, or tomorrow morning.

pedja089
- 15th August 2011, 18:02
Yes, I tried that and DT_HID. But nothing happen if cable is plugged or unplugged.
For now, CDC will be good starting point.
I would be very grateful if you could send me CDC example with fuse configuration.
Thank you very much.

ScaleRobotics
- 16th August 2011, 16:15
Well, now I am starting to wonder if I ever had it working on CDC.:( I had a cdc labeled program for it, but what I had does not work. I had a fairly quick time with the 47J53 in CDC as well as HID, but for the 67J50, I can't seem to get either to work, and I have spent a fair amount of time at it.

These were the configs I used for other programs for the 67J50, which pretty much matches Microchip's HID bootloader software.




'DEFINE LOADER_USED 1
'DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader
#config
CONFIG PLLDIV = 5 ;for 20 mhz chip
CONFIG XINST = OFF
CONFIG STVREN = ON ;stack overflow reset
CONFIG WDTEN = OFF
CONFIG CP0 = OFF
CONFIG IESO = OFF
CONFIG FCMEN = OFF
CONFIG CCP2MX = DEFAULT
CONFIG WDTPS = 32768
CONFIG CPUDIV = OSC1 ;DIVIDE BY 1 MODE
CONFIG FOSC = HSPLL
CONFIG MSSPMSK = MSK5
#endconfig

DEFINE OSC 48
clear
OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
I will try a few more things, but I wanted to give you a heads up.

pedja089
- 16th August 2011, 17:28
I try cdc from pbp/usb18 and add config, but still nothing...
I use 8MHz crystal, so PPLDIV is 2 is that correct?
What are the chances that the USB module on 3 PIC are broken?

ScaleRobotics
- 16th August 2011, 17:32
Not very high. But (speaking for myself), the chances of the problem being behind the keyboard is pretty high! Just not sure what I could be missing here, doing it two different ways hid, and cdc, and with a USB bootloader, and without. So I am running out of things I can think of to try....

Yes, divide by two would be correct for a 8 mhz.

pedja089
- 17th August 2011, 01:29
I check hardware and recheck, and everything seems ok.
Here is code for cdc from pbp/usb18:


asm
CONFIG PLLDIV = 2 ;for 8 mhz chip
CONFIG XINST = OFF
CONFIG STVREN = ON ;stack overflow reset
CONFIG WDTEN = OFF
CONFIG CP0 = OFF
CONFIG IESO = OFF
CONFIG FCMEN = OFF
CONFIG CCP2MX = DEFAULT
CONFIG WDTPS = 32768
CONFIG CPUDIV = OSC1 ;DIVIDE BY 1 MODE
CONFIG FOSC = HSPLL
CONFIG MSSPMSK = MSK5
endasm
Include "cdc_desc.bas" ' Include the HID descriptors

Define OSC 48

buffer Var Byte[16]
cnt Var Byte


OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
Pause 10

USBInit ' Get USB going

' Wait for USB input
idleloop:
USBService ' Must service USB regularly
cnt = 16 ' Specify input buffer size
USBIn 3, buffer, cnt, idleloop

' Message received
buffer[0] = "H"
buffer[1] = "e"
buffer[2] = "l"
buffer[3] = "l"
buffer[4] = "o"
buffer[5] = " "
buffer[6] = "W"
buffer[7] = "o"
buffer[8] = "r"
buffer[9] = "l"
buffer[10] = "d"
buffer[11] = 13
buffer[12] = 10
buffer[13] = 0

outloop:
USBService ' Must service USB regularly
USBOut 3, buffer, 14, outloop

Goto idleloop ' Wait for next bufferI spend another day on it, and nothig, rely, nothin on usb...
I really don't know what to do.

ScaleRobotics
- 17th August 2011, 18:16
Well, I am not having any luck over here either. Here is my try at using DT_HID260. I have been successful in getting it running on another J chip, the PIC18F47J53, and looking at the two data sheets, the USB doesnt seem to differ much between these two chips. Except on one the USB data memory is below the buffer descriptors, and the other the USB data memory is above the buffer descriptors. The DEV files seem to point to the USB buffer descriptors (67J50 here): USBMEMORYADDRESS Con $400 ' USB RAM starts here

Here is my code (that does not work)


'************************************************* **************************
'* Name : BasicUSB.pbp *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2009 *
'* Date : 7/23/2009 *
'* Version : 1.x ' Modified by scalerobotics *
'* Notes : I tried to edit it to work on a PIC18F67J50 and I failed *
'* : Worked great on other chips, but I can't seem to figure out *
'* : the problem for PIC18F67J50. Board is PIC_LCD3310, which does*
'* : work with the USB bootloader,so probably not a hardware issue*
'************************************************* **************************
'DEFINE LOADER_USED 1
'DEFINE RESET_ORG 1000h ' For Microchip USB Bootloader

;--- if you un-comment these, you must comment the ones in the .inc file ---
ASM ; 18F2550/4550, 20mhz crystal
; __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
; __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
; __CONFIG _CONFIG3H, _PBADEN_OFF_3H
; __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
ENDASM

;ASM ; 18F13K50/14K50 Only 12mhz crystal can be used for USB
; CONFIG CPUDIV=NOCLKDIV ; CPU runing at full speed
; CONFIG USBDIV=OFF ; Low speed USB clock diviser disabled, not used here
; CONFIG FOSC=HS ; Use of High Speed crystal oscillator
; CONFIG PLLEN=ON ; Enable PLL multiplier, 12Mhz oscilator x 4
; CONFIG PCLKEN=ON ; Primary clock source is enabled
; CONFIG FCMEN=OFF ; Failsafe clock off
; CONFIG IESO=OFF ; Oscillator switchover mode disabled
; CONFIG WDTEN=ON ; Watchdog timer on
; CONFIG WDTPS=512 ; Watchdog divider is 512
; CONFIG MCLRE=OFF ; Disable MCLR pin, enable RC3
; CONFIG STVREN=ON ; Stack full/underflow will cause reset
; CONFIG LVP=OFF ; Low voltage programming disabled
; CONFIG BBSIZ=OFF ; 512kW block boot size
; CONFIG XINST=OFF ; Extended instruction mode disabled
;ENDASM
#config ;pic18F67J50 on Olimex PIC_LCD3310 usb board
CONFIG PLLDIV = 5 ;for 20 mhz crystal
CONFIG XINST = OFF
CONFIG STVREN = off ;stack overflow reset
CONFIG WDTEN = OFF ;added
CONFIG CP0 = OFF ;added
CONFIG IESO = OFF ;added
CONFIG FCMEN = OFF ;added
CONFIG CCP2MX = DEFAULT ;added
CONFIG WDTPS = 32768
CONFIG CPUDIV = OSC1 ;DIVIDE BY 1 MODE
CONFIG FOSC = HSPLL
CONFIG MSSPMSK = MSK5 ;add
#endconfig

DEFINE OSC 48
clear
OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family

;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
endm
INT_CREATE ; Creates the interrupt processor
endasm

;--- Setup USB -------------------------------------------------------------
INCLUDE "DT_HID260.pbp"

DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Darrel Taylor"
DEFINE USB_PRODUCTNAME "DT_HID"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 32 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 16 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10

; --- Each USB LED is optional, comment them if not used ----
;DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
;DEFINE USB_PLUGGEDLED PORTB,0 ; LED indicates if USB is connected
;DEFINE USB_TXLED PORTC,2 ; " " data being sent to PC
;DEFINE USB_RXLED PORTC,1 ; " " data being received from PC

OutCount VAR WORD : OutCount = 0
Value VAR WORD
X VAR WORD

;--- Setup ADC -------------------------------------------------------------
DEFINE ADC_BITS 10 ; Number of bits in ADCIN result
' Configure ADC
' =============
' See thread http://www.picbasic.co.uk/forum/showthread.php?t=11128&highlight=18f67j50
' for more information about setting analog, and the WDTCON.4 on this chip
WDTCON.4 = 1 ' Switch to Alternate SFR
ANCON0_ALT = %10011110
' -xx------ Not Implemented
' 1--1111-- AN7, & AN<4:1> = Digital
' -------0- AN0 = Analog

ANCON1_ALT = %11111111
' 11111111- AN<15:10> = Digital

WDTCON.4 = 0 ' Back to Default SFR

ADCON0 = %00000001
' 0-------- VCFG1, Vref- 0 = AVss (1=AN2)
' -0------- VCFG2, Vref+ 0 = AVdd (1=AN3)
' --0000--- CHS<3:0>, Channel select -- 0
' ------0-- Go/Done, don't care for now
' -------1- ADON, Enable ADC

ADCON1 = %10000111
' 1-------- ADFM, Right justified result
' -0------- ADCAL, Normal A/D converter operation
' --000---- ACQT<2:0>, A/D Aquisition time = 0 Tad
' -----111- ADCS<2:0>, A/D conversion clock = FRC
;--- The Main Loop ---------------------------------------------------------
TRISD = 0
PORTD.0 = 1 'turn on g sensor
PORTD.1 = 0 'select scale for g sensor
PORTD.2 = 0 'select scale for g sensor


TRISA = %00000111 'set porta.0, 1, and 2 as inputs
TRISB = 0
CM1CON1 = 7 'CM1CON in PBP3 as CM1CON1
CM2CON1 = 7 'CM2CON in PBP3 as CM2CON1
TRISC = 0
TRISE = 0
pause 100
;--- The Main Loop ---------------------------------------------------------
Main:
FOR X = 0 to 1000 ; Check for incomming USB data while pausing
@ ON_USBRX_GOSUB _HandleRX
PAUSE 1
NEXT X

ADCIN 10, Value
OutCount = OutCount + 1
ARRAYWRITE USBTXBuffer,["AN0=",DEC Value," -",DEC OutCount," "]
IF Plugged THEN GOSUB DoUSBOut ; only send when USB is connected
GOTO Main

;---- This just sends the received packet back to the PC -------------------
HandleRX:
ARRAYWRITE USBTXBuffer,[STR USBRXBuffer\USBBufferSizeRX]
return

pedja089
- 17th August 2011, 22:11
I try similar thing, but same result.
So is it possible there are some bug in PBP for this PIC family?

Darrel Taylor
- 18th August 2011, 01:01
I'm looking into it too.
Trying to build a board.

But first I have to ask ...
Do you have VDD (3.3V) tied to VUSB?
There's no internal regulator on those chips.

cncmachineguy
- 18th August 2011, 01:22
I can't speak for Pedja's board, But I am pretty sure Walter is using the PIC_LCD3310. If so that DOES show Vusb tied to 3.3V on the schamatic.

ScaleRobotics
- 18th August 2011, 01:56
Thanks!

Yes, I am using Olimex's PIC_LCD3310. Making a board for this family is a little bit of a pain. Darrel, do you want me to send you the Olimex board? I can ship it out tomorrow.

Walter

Darrel Taylor
- 18th August 2011, 03:59
Thanks Walter, that's a nice offer.

But I ordered one from sparkfun. They're only 50 miles away so I should have it by friday, shipped ground.
That's sure easier than building one.

I'm going to try a 26J50 too.
The 87J50 may still be a question mark.

ScaleRobotics
- 18th August 2011, 05:58
Now that's what I call support! Thanks Darrel.

I can vouch for the PIC18F46J50 working with DT_HID260 and PBP3. I have Micochip's mini demo board http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en540669 going. But the 67J50 is elusive for me. Not ruling out my own operator error here, but this operator is running out of ideas ..

pedja089
- 18th August 2011, 06:58
Darrel, thank for support.
I have 3.3V om Vusb... That was first thing to check...
I can send you PIC. Just give me adress.

Darrel Taylor
- 18th August 2011, 18:54
Thanks Pedja,

We have some of those chips, but no boards to put it on.
At least none that would be easy to use.

I think the 67J50 should be good enough since it's in the same family as the 87J50.
We shall see this weekend.

pedja089
- 18th August 2011, 19:08
Dear sir,
Thank you for support.

Darrel Taylor
- 21st August 2011, 17:11
There is something seriously messed up with these chips. And it's all Microchip.

The SFR's from address F40h to F5Fh cannot be accessed with either the MOVFF opcode or indirectly through the FSR's.
They can only be accessed by setting BSR to bank15 and using "banked" opcodes like movf, movwf, bcf etc.

I realize that those SFR's are outside of the ACCESS bank, but that should not affect MOVFF or indirect addressing thru FSR's.

That range of SFR's contains many of the USB modules registers.
Other USB module registers such as UCON USTAT etc that reside in the access bank can be written/read with all 3 methods FSR, MOVFF and banked. So it's not related to the USB module itself.

The USB libraries rely heavily on MOVFF and FSR's.

I have found nothing in the errata or datasheet that mentions this behavior.

To illustrate the issue, here is a program for the Olimex PIC_LCD3310.
It attempts to read several SFR's using all 3 methods and displays the result on the GLCD. With anything in the affected range, only the banked method (GetR on the display) returns a value. Any other SFR's work fine.

Use Up and Down on the joystick to scroll thru the SFR's.


'************************************************* **************************
'* Name : 18F67J50USB.pbp *
'* Author : Darrel Taylor *
'* Notice : Copyright (c) 2009 *
'* Date : 8/21/2011 *
'* Notes : The FSR's from F40 to F5F are not accessable using either *
'* : MOVFF or indirectly with FSR's. *
'************************************************* **************************
#config ;pic18F67J50 on Olimex PIC_LCD3310 usb board
CONFIG PLLDIV = 5 ;for 20 mhz crystal
CONFIG XINST = OFF
CONFIG STVREN = off ;stack overflow reset
CONFIG WDTEN = OFF ;added
CONFIG CP0 = OFF ;added
CONFIG IESO = OFF ;added
CONFIG FCMEN = OFF ;added
CONFIG CCP2MX = DEFAULT ;added
CONFIG WDTPS = 32768
CONFIG CPUDIV = OSC1 ;DIVIDE BY 1 MODE
CONFIG FOSC = HSPLL
CONFIG MSSPMSK = MSK5 ;add
#endconfig
DEFINE OSC 48
clear
OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
PAUSE 200
;--- For the 3310 display---------------------------------------------------
include "AllDigital.pbp"
;DEFINE SHOWDIGITAL 1
include "modedefs.bas"
include "LCD_3310v32.inc"
GOSUB Lcd_Clear
;--- Setup Interrupts ------------------------------------------------------
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Allows re-entry to PBP from ASM interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler USB_Handler
INT_Handler TMR1_INT, _TMR1_ISR, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
endasm
;--- Setup USB -------------------------------------------------------------
INCLUDE "DT_HID260.pbp"
DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Darrel Taylor"
DEFINE USB_PRODUCTNAME "DT_HID"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 32 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 16 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10
; --- Each USB LED is optional, comment them if not used ----
;DEFINE USB_LEDPOLARITY 1 ; LED ON State [0 or 1] (default = 1)
DEFINE USB_PLUGGEDLED PORTE,3 ; LED indicates if USB is connected
;DEFINE USB_TXLED PORTC,2 ; " " data being sent to PC
;DEFINE USB_RXLED PORTC,1 ; " " data being received from PC
OutCount VAR WORD : OutCount = 0
Value VAR WORD
X VAR WORD
;--- The Main Loop ---------------------------------------------------------
TRISD = 0
PORTD.0 = 1 'turn on g sensor
PORTD.1 = 0 'select scale for g sensor
PORTD.2 = 0 'select scale for g sensor
pause 100
T1CON = $31 ; Prescaler = 8, TMR1ON
LCD_Value VAR BYTE
UCFG_VAL CON EXT
B0 VAR BYTE ; Button Var
B1 VAR BYTE ; Button Var
;------------------------------------------------------------------------------
ASM
GetReg macro Regin, VarOut
banksel Regin
movf Regin, W
banksel VarOut
movwf VarOut
banksel 0
endm
ENDASM
PAUSE 100
Left VAR PORTB.1
Right VAR PORTA.4
Up VAR PORTB.4
Down VAR PORTB.5
Center VAR PORTB.0
;------------------------------------------------------------------------------
ShowUCON:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UCON - F65h"
@ PrintStr 0,2, "FF = "
LCD_Value = UCON
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UCON, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UCON
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UCON_Wait:
PAUSE 10
BUTTON Down,0,255,255,B0,0,UCON_Wait
;------------------------------------------------------------------------------
ShowUSTAT:
GOSUB Lcd_Clear
@ PrintStr 0,0, " USTAT - F64h"
@ PrintStr 0,2, "FF = "
LCD_Value = USTAT
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg USTAT, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, USTAT
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
USTAT_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUCON
BUTTON Down,0,255,255,B0,0,USTAT_Wait
;------------------------------------------------------------------------------
ShowUEIR:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UEIR - F63h"
@ PrintStr 0,2, "FF = "
LCD_Value = UEIR
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UEIR, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UEIR
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UEIR_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUSTAT
BUTTON Down,0,255,255,B0,0,UEIR_Wait
;------------------------------------------------------------------------------
ShowUIR:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UIR - F62h"
@ PrintStr 0,2, "FF = "
LCD_Value = UIR
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UIR, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UIR
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UIR_Wait:
PAUSE 10
BUTTON UP,0,255,255,B1,1,ShowUEIR
BUTTON Down,0,255,255,B0,0,UIR_Wait
;------------------------------------------------------------------------------
ShowUCFG:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UCFG - F5Fh"
@ PrintStr 0,2, "FF = "
LCD_Value = UCFG
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UCFG, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UCFG
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UCFG_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUIR
BUTTON Down,0,255,255,B0,0,UCFG_Wait
;------------------------------------------------------------------------------
ShowUADDR:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UADDR - F5Eh"
@ PrintStr 0,2, "FF = "
LCD_Value = UADDR
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UADDR, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UADDR
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UADDR_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUCFG
BUTTON Down,0,255,255,B0,0,UADDR_Wait
;------------------------------------------------------------------------------
ShowUEIE:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UEIE - F5Dh"
@ PrintStr 0,2, "FF = "
LCD_Value = UEIE
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UEIE, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UEIE
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UEIE_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUADDR
BUTTON Down,0,255,255,B0,0,UEIE_Wait
;------------------------------------------------------------------------------
ShowUIE:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UIE - F5Ch"
@ PrintStr 0,2, "FF = "
LCD_Value = UIE
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UIE, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UIE
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UIE_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUEIE
BUTTON Down,0,255,255,B0,0,UIE_Wait
;------------------------------------------------------------------------------
ShowPIE2:
GOSUB Lcd_Clear
@ PrintStr 0,0, " PIE2 - FA0h"
@ PrintStr 0,2, "FF = "
LCD_Value = PIE2
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg PIE2, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, PIE2
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
PIE2_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUIE
BUTTON Down,0,255,255,B0,0,PIE2_Wait
;------------------------------------------------------------------------------
ShowUEP0:
GOSUB Lcd_Clear
@ PrintStr 0,0, " UEP0 - F4Ch"
@ PrintStr 0,2, "FF = "
LCD_Value = UEP0
GOSUB LCD_BIN8
@ PrintStr 0,3, "GetR= "
@ GetReg UEP0, _LCD_Value
GOSUB LCD_BIN8
@ LFSR 0, UEP0
@ movff INDF0, _LCD_Value
@ PrintStr 0,4, "FSR = "
GOSUB LCD_BIN8
UEP0_Wait:
PAUSE 10
BUTTON Up,0,255,255,B1,1,ShowUIE
BUTTON Down,0,255,255,B0,0,UEP0_Wait
;--- The Main Loop ---------------------------------------------------------
Main:
FOR X = 0 to 1000 ; Check for incomming USB data while pausing
@ ON_USBRX_GOSUB _HandleRX
PAUSE 1
NEXT X

ADCIN 10, Value
OutCount = OutCount + 1
ARRAYWRITE USBTXBuffer,["AN0=",DEC Value," -",DEC OutCount," "]
IF Plugged THEN GOSUB DoUSBOut ; only send when USB is connected
GOTO Main
;---- This just sends the received packet back to the PC -------------------
HandleRX:
ARRAYWRITE USBTXBuffer,[STR USBRXBuffer\USBBufferSizeRX]
return
;----[Timer1 interrupt blinks an LED]--------------------------------------
TMR_DIV VAR BYTE
TMR1_ISR:
TMR_DIV = TMR_DIV + 1
if TMR_DIV = 12 THEN
TOGGLE PORTE.2
TMR_DIV = 0
ENDIF
@ INT_RETURN
LCD_BIN8:
Lcd_Data = LCD_Value.7 + $30
Gosub Lcd_SendChar
Lcd_Data = LCD_Value.6 + $30
Gosub Lcd_SendChar
Lcd_Data = LCD_Value.5 + $30
Gosub Lcd_SendChar
Lcd_Data = LCD_Value.4 + $30
Gosub Lcd_SendChar
Lcd_Data = LCD_Value.3 + $30
Gosub Lcd_SendChar
Lcd_Data = LCD_Value.2 + $30
Gosub Lcd_SendChar
Lcd_Data = LCD_Value.1 + $30
Gosub Lcd_SendChar
Lcd_Data = LCD_Value.0 + $30
Gosub Lcd_SendChar
RETURN


Walter,

My PIC_LCD3310 arrived with a solder bridge between pins 13-14 (D+, RF5).
Sometimes those are intentional, does your have a bridge there too.

I've attached the .hex file for the above program.

ScaleRobotics
- 21st August 2011, 17:25
Weirdness! Will have to check your program out tonight! Thanks Darrel!


No, mine do not have a solder bridge on any of the PIC pins.

Here is a USB HID bootloader, just to make sure your USB portion (still)works.

(Hold joystick in down position at power up to go to bootload mode)

mister_e
- 21st August 2011, 17:39
There is something seriously messed up with these chips. And it's all Microchip.
http://1.bp.blogspot.com/_DgMV2hrDED4/TSujomBFhCI/AAAAAAAAAH8/5NRSyfPmK8g/s1600/smack_in_face_slap_computer.jpg

cncmachineguy
- 21st August 2011, 18:55
Just went and looked at 1 of mine(I have 2 but must have put the other in a safe place). I see no bridges on the pins anywhere. So Darrel is it safe to assume you will create a workaround for microchips shortcoming? Haha just poking at you. Seems now that you have done the hard part and identified the issue, we need to make an asm routine to talk to those sfr's?

ScaleRobotics
- 21st August 2011, 22:00
I found this on page 81: But I guess you found that already.


Note: Addresses, F40h through F5Fh, are not
part of the Access Bank, therefore specifying
a BSR should be used to access these
registers.
See, its a feature, not a bug!

mister_e
- 21st August 2011, 22:02
http://www.allamericanblogger.com/wp-content/uploads/double-facepalm1.jpg

Darrel Taylor
- 21st August 2011, 22:30
I found this on page 81: But I guess you found that already.
See, its a feature, not a bug!

I tried to head off that question in my earlier post.
I understand that it's outside of the access bank, but that only affects the "banked" opcodes (movf, movwf, bcf, bsf, iorwf etc). Banked opcodes are the only ones that work in that range on the 67J50.

MOVFF and indirect addressing are not affected by the BSR register.
They use the full address of the register.

From the MOVFF Instruction definition ...

Location of source ‘fs’ can be anywhere
in the 4096-byte data space (000h to
FFFh) and location of destination ‘fd’
can also be anywhere from 000h to
FFFh.

ScaleRobotics
- 22nd August 2011, 02:54
I think it is sort of interesting that in both the PIC18F47J53, and the PIC18F46J50 (both known to work with PBP USB) it states:


Note: The SFRs located between EB0h and
F5Fh are not part of the Access Bank.
Either BANKED instructions (using BSR) or
the MOVFF instruction should be used to
access these locations. When programming
in MPLAB® C18, the compiler will
automatically use the appropriate
addressing mode.
However, for the PIC18F67J50, they leave the MOVFF part out of this statement. I wonder if Microchip knows its errata and just didn't add it to the errata list. Or it's just a coincidence.

Darrel Taylor
- 22nd August 2011, 03:13
Hmmmm, very interesting indeed.

pedja089
- 23rd August 2011, 00:58
I was out of town, now I'm reading posts, and i tested hardware with HID boot loader, and it works.
When can I expect solution?
Is this will be corrected in PBP2.60(which I currently use), or I must upgrade to PBP3?
I really appreciate your efforts.
Thanks to all;)

mister_e
- 23rd August 2011, 01:28
There's no good reason to not upgrade to PBP3... forum is free... now say to Melabs & Crownhill you appreciate the forum because it saved your butt a couple of times... get the upgrade ;)

pedja089
- 23rd August 2011, 03:50
Yes, you're right, I'll get update;)

Squibcakes
- 23rd August 2011, 03:55
I just saw the PBP 3 update too. Everybody - time to open your wallets. Is it really that more stable than PB2?

mister_e
- 23rd August 2011, 03:56
Good boy ;)

mister_e
- 23rd August 2011, 04:00
Is it really that more stable than PB2?
I can't confirm as of yet, but PBP2 always have been bomb proof to me... Sure enough, the little money invested in the upgrade worth it! 50$/Year? Who cares? less than 1$/Week.

mackrackit
- 23rd August 2011, 04:44
I have not seen a version of PBP that was not stable. So far PBP 3.0 has not given me any trouble.

UPGRADE UPGRADE UPGRADE

Maybe the faster folks upgrade the faster they will come out with more bells and whistles.

ScaleRobotics
- 23rd August 2011, 14:45
I didn't get very far on the Microchip forum. http://www.microchip.com/forums/tm.aspx?high=&m=596998&mpage=1#597082 They wanted me to try the simulator, and see if the simulator thought that should work or not. I couldn't get far enough in Mplab to find out. Though I am not sure how useful that would be. Does a simulator always sim what it should?

mister_e
- 23rd August 2011, 17:32
MPSIM worked with PBP 2.x, will try with PBP3. It has to.

And NO a simulator do not always give you the good results, some are worst than others. As a guideline they are usually decent tool or pure toy, not much.

Darrel Taylor
- 23rd August 2011, 17:48
What did you try in MPSIM?

I'm finding that it's reversed in MPSIM.
MOVFF and FSR's work, but banked instructions don't.

mister_e
- 23rd August 2011, 18:09
I haven't tried this specific PIC yet. I try to stay away of Sims ;)

Darrel Taylor
- 23rd August 2011, 19:25
OK, I'm getting closer.
I think I can make USB work on it.

What a screwy chip.

tumbleweed
- 23rd August 2011, 20:06
This is all very interesting. Care to share what you've been able to find out so far?

How is this chip different than the others?

pedja089
- 23rd August 2011, 20:07
Maybe is screwy, but it have everything I need for this project, and it's cheep. Thank you;)

ScaleRobotics
- 23rd August 2011, 20:30
How is this chip different than the others?

I am sure Darrel will share more.

But one way it is a bit odd, is it shares addresses for SFR's. See: 5.3.5.1 Shared Address SFRs . You have to set the ADSHR bit in the WDTCON register to access the alternate locations.

tumbleweed
- 23rd August 2011, 20:42
But one way it is a bit odd, is it shares addresses for SFR's. See: 5.3.5.1 Shared Address SFRs
Yeh, I've seen that "feature" in a number of the J series parts, not just the J50.

It doesn't seem to have anything to do with USB register access, though.

ScaleRobotics
- 23rd August 2011, 21:25
Darrel talks about it in post 19 of this thread:


There is something seriously messed up with these chips. And it's all Microchip.

The SFR's from address F40h to F5Fh cannot be accessed with either the MOVFF opcode or indirectly through the FSR's.
They can only be accessed by setting BSR to bank15 and using "banked" opcodes like movf, movwf, bcf etc.

I realize that those SFR's are outside of the ACCESS bank, but that should not affect MOVFF or indirect addressing thru FSR's.

That range of SFR's contains many of the USB modules registers.
Other USB module registers such as UCON USTAT etc that reside in the access bank can be written/read with all 3 methods FSR, MOVFF and banked. So it's not related to the USB module itself.

The USB libraries rely heavily on MOVFF and FSR's.

I have found nothing in the errata or datasheet that mentions this behavior.

And in due time, we will see his work around!

Darrel Taylor
- 23rd August 2011, 22:59
WOW, I've been chasing my tail, and apparently for not.

The MPASM that comes with MPLAB 8.73a was generating incorrect opcodes for the banked instructions.
This was making me think things were happening in the chip that should not have been happening.

The actual silicon in the xxJ50's is not the problem.

There is a new version MPLAB 8.76 which has fixed the errors.
Compile your USB programs using the new assembler, and walla, working USB.

There are other chips that will be affected by the problem, and it's not only USB that will be affected, so it is recommended that everyone with PBP 2.60 or later upgrade MPLAB to a version higher than 8.73a.

pedja089
- 23rd August 2011, 23:45
I'll give it try tomorrow.
Thanks Darrell

mister_e
- 23rd August 2011, 23:50
And obviously, it doesn't seems Microchip have documented that bug... or again, I'm blind

pedja089
- 24th August 2011, 01:39
I just recompile CDC from last attempt and it is working. Now just to try HID with VB6.
You save my butt, again:D

Darrel Taylor
- 24th August 2011, 01:49
I think it's time to retire one of my signature quotes ...

5905

They don't always do what you tell them. :eek:

But I'm definitely keeping this one ... :)

5906

ScaleRobotics
- 24th August 2011, 02:54
I have installed MPLAB8,76. Now I get CDC to work on 2.60C, but I don't get the same file to work with PBP3.

But I am wondering where PBP3 is looking for MPLAB or MPASM? 2.60 allowed you to select the location for PBP, and it also allowed you to show it where the assembler was located. In PBP3 I get this option:

5907

How am I supposed to enter them both? Or are they really supposed to be in the same place??

Darrel Taylor
- 24th August 2011, 03:01
In the Start menu, go to All Programs > PBP3 from melabs > MPASM-MPLAB setup.
It allows you to set the path to MPASM.

ScaleRobotics
- 24th August 2011, 03:38
Thanks Darrel. I had some weird behavior in my computer. PBP3 kept defaulting to MPASMX, no mater how I set it, I'd check back, and it was set to MPASMX. So after removing the Microchip directory, and re-installing MPLAB 8.76, I was able to get PBP to settle on C:\Program Files\Microchip\MPASM Suite . Now CDC and HID work for the 18F67J50 with PBP3.0! Thanks for routing that out for us!

mister_e
- 24th August 2011, 04:13
I have to say I'm glad for Melabs it's not another Microchip twist who had to implement another .HWLIB thing.

Finger crossed for the next USB pic though... BTW, it's about time Microchip release USB3 AND/OR Thunderbolt.

pedja089
- 24th August 2011, 22:23
Darrel,
I try your DT_HID260, and it work on first attempt. It's very simple to use.
But I have question.
If I want to use 64 byte, #define USB_EP0_BUFF_SIZE should be 64, is that correct?
Thanks

Darrel Taylor
- 24th August 2011, 23:26
No, endpoint 0 is for setup and control transfers. You should not change that.
And you should not change anything inside the DT_HID260.pbp file.

Set the report sizes with the defines...


;--- Setup USB -------------------------------------------------------------
INCLUDE "DT_HID260.pbp"
DEFINE USB_VENDORID 6017
DEFINE USB_PRODUCTID 2000
DEFINE USB_VERSION 1
DEFINE USB_VENDORNAME "Darrel Taylor"
DEFINE USB_PRODUCTNAME "DT_HID"
DEFINE USB_SERIAL "001"
DEFINE USB_INSIZE 64 ; IN report is PIC to PC (8,16,32,64)
DEFINE USB_OUTSIZE 16 ; OUT report is PC to PIC
DEFINE USB_POLLIN 10 ; Polling times in mS, MIN=1 MAX=10
DEFINE USB_POLLOUT 10

pedja089
- 24th August 2011, 23:58
Ok. Everything working fine.
Thanks again.

pedja089
- 25th August 2011, 09:24
Here is my template. Maybe it will be useful for someone.
Application for PC is done in VB6. Screen shot:
5908
PBP & VB6 files:
5909
If knobs doesn't appear in vbForm, you need to add it in components.