HID USB on 18F87J50


Results 1 to 40 of 57

Threaded View

  1. #19
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default Re: HID USB on 18F87J50

    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.

    Code:
    '***************************************************************************
    '*  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.
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 21st August 2011 at 17:18.
    DT

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts