ds30 Loader free edition forums
Pic18F14K22 with USB MCP2200 - Printable Version

+- ds30 Loader free edition forums (https://picbootloader.com/forum)
+-- Forum: Support (https://picbootloader.com/forum/forumdisplay.php?fid=3)
+--- Forum: 8-bit firmwares (https://picbootloader.com/forum/forumdisplay.php?fid=7)
+--- Thread: Pic18F14K22 with USB MCP2200 (/showthread.php?tid=619)



Pic18F14K22 with USB MCP2200 - pietervanwyk - 2013-06-24

I will appreciate help with this.
Spent days and can not get the bootloader to work at all. With a C program, comms Tx and Rx works and the MCP2200 Usb to serial converter works 100%.
I have tried just every option with clock speeds, configurations, etc. I also tried it with the latest bootload version.
The Osc is running 64000000 with the PLL but the code gives an error and I therefore switch off the PLL to run 16000000 hz.
Here is my user setup, changed to enable the MCP2200 and a led, tried with and without the OSCCON setup:

USER_CODE.INC:

Code:
; UserInit()
; Description: this is executed immediately on start-up before the boot loader code
;------------------------------------------------------------------------------
UserInit macro
            

        ;    enable MCP2200
    movlw     b'11110110' ; setup clock     to 16M clock speed
    movwf     OSCCON
    bcf 0x0F93,6        ; tris B6 out
    bcf 0x0F81,6        ; pin B6 // ce low
    bsf 0x0F81,6        ; pin B6 // ce high
    bcf 0x0F93,4        ; tris B4 out
    bsf 0x0F81,4        ; pin B4 blue led        
;
            ; Make uart pins digital
            ifdef    ADCON1
;                error Do you need to configura uart pins to be digital? If not, remove this line
            endif
            ;movlw     b'01100000'        ;xxx disable
            ;movwf     ADCON1            ;xxx analog on tx/rx             
            
            ; UART/CAN pps config
            ifdef    HAS_PPS
                ifdef USE_UART2
                    error You need to configure PPS    ;xxx remove this line when PPS is configured
                    
                    ; This template maps U2Rx to RP4
                    bcf        RPINR16, RX2DT2R0        ;xxx
                    bcf        RPINR16, RX2DT2R1        ;xxx
                    bsf        RPINR16, RX2DT2R2        ;xxx
                    bcf        RPINR16, RX2DT2R3        ;xxx
                    bcf        RPINR16, RX2DT2R4        ;xxx
                    
                    ; This template maps RP3 to U2Tx
                    bsf        RPOR3,    RP3R0            ;xxx
                    bcf        RPOR3,    RP3R1            ;xxx
                    bsf        RPOR3,    RP3R2            ;xxx
                    bcf        RPOR3,    RP3R3            ;xxx
                    bcf        RPOR3,    RP3R4            ;xxx
                endif
            endif
        endm
        
        
;------------------------------------------------------------------------------
; UserExit()
; Description: this is executed right before the user application is loadaed
;------------------------------------------------------------------------------
UserExit macro

        endm

SETTINGS.INC:

Code:
;------------------------------------------------------------------------------
; Device
;------------------------------------------------------------------------------
        processor    18F14K22                    ;xxx


;------------------------------------------------------------------------------
; Includes
;------------------------------------------------------------------------------
        #include "devices.inc"


;------------------------------------------------------------------------------
; User preferences
;------------------------------------------------------------------------------
        radix DEC
        
        #define        OSCF            16000000    ;xxx oscillator frequency (including pll)
        #define        BLINIT            2000        ;xxx hello receive timeout [ms]
        #define        HELLOTRIES        2            ;xxx number of non hello characters received before branching to the user application
        #define        BLTIME            2000        ;xxx data receive timeout [ms]


;------------------------------------------------------------------------------
; UART settings
;------------------------------------------------------------------------------            
        #define        USE_UART1        1            ;xxx uncomment to use uart1
        ;#define    USE_UART2        1            ;xxx uncomment to use uart2
        #define        BAUDRATE         38400        ;xxx baudrate
        ;#define    USE_ABAUD        1            ;xxx uncomment to use auto baud rate detection, READ ERRATA FIRST        
        ;#define    USE_BRG16        1            ;xxx uncomment to use 16-bit brg

        ;#define    USE_TXENABLE    1            ;xxx uncomment to use a tx enable pin        
        ifdef USE_TXENABLE
            #define    TXE_DELAY         10            ;xxx time in us to wait before transmitting after pulling the tx enable pin high
            #define    TRISR_TXE        TRISD        ;xxx tris register containing tx enable
            #define    LATR_TXE        LATD        ;xxx port register containing tx enable
            #define    TRISB_TXE        TRISD0        ;xxx tris bit for tx enable
            #define LATB_TXE        RD0            ;xxx port bit for tx enable
        endif


;------------------------------------------------------------------------------
; Advanced settings
;------------------------------------------------------------------------------        
        ;#define    KICK_WD            1            ;xxx uncomment to kick the wd in the rx loop, only enable if the watchdog is enabled
        #define        PROT_GOTO        1            ;xxx protect goto at 0x00
        #define        PROT_BL         1            ;xxx protect bootloader
        #define        WRITE_VER        1            ;do flash write verification
        #define        EWRITE_VER        1            ;do eeprom write verification
        
        ifdef IS_PIC18F
            #define        BLPLP        9            ;bootloader placement, pages from end
            #define        BLSIZEP        9            ;bootloader size [pages], used by bootloader protection    
        endif
        
        ifdef IS_PIC18FJ        
            #define        BLPLP        2            ;bootloader placement, pages from end
            #define        BLSIZEP        1            ;bootloader size [pages], used by bootloader protection    
        endif

Attached is the code listing...


RE: Pic18F14K22 with USB MCP2200 - Mikael Gustavsson - 2013-06-24

You need to configure the RX pin to be digital, put the code in the UserInit macro:
Code:
bcf ANSELH, ANS11



RE: Pic18F14K22 with USB MCP2200 - Mikael Gustavsson - 2013-06-24

Where are the configuration bits?


RE: Pic18F14K22 with USB MCP2200 - pietervanwyk - 2013-06-24

Dear Mikael, please pat yourself on the shoulder...
Twice please!
bcf ANSELH, ANS11
was the problem....

Still will not work with PLL= on (64000000hz) but it may be the chip config.

Thank you!


RE: Pic18F14K22 with USB MCP2200 - Mikael Gustavsson - 2013-06-24

Great. Do you enable the PLL?
Code:
bsf    OSCTUNE, PLLEN



RE: Pic18F14K22 with USB MCP2200 - pietervanwyk - 2013-06-24

The PLL enabled (64000000hz) does not work.


RE: Pic18F14K22 with USB MCP2200 - zidged - 2013-11-30

I am trying to run PIC18F firmware on PIC18F14K22 too.
I have changed settings.inc file like this;
Code:
;------------------------------------------------------------------------------
;
; Title:            ds30 Loader for PIC18F
;
; File description:    user settings and configuration bits
;
; Copyright:         Copyright 2009-2012 Mikael Gustafsson
;                                                                            
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;    This file is part of ds30 Loader.
;
;    ds30 Loader is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation.
;
;    ds30 Loader is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.
;
;    You should have received a copy of the GNU General Public License
;    along with ds30 Loader. If not, see <http://www.gnu.org/licenses/>.
;------------------------------------------------------------------------------



;------------------------------------------------------------------------------
; Device
;------------------------------------------------------------------------------
        ;LIST         P=18F14k22
        processor    18F14K22                    ;xxx



;------------------------------------------------------------------------------
; Includes
;------------------------------------------------------------------------------
        #include "devices.inc"


;------------------------------------------------------------------------------
; User preferences
;------------------------------------------------------------------------------
        radix DEC
        
        #define        OSCF              16000000    ;xxx oscillator frequency (including pll)
        #define        BLINIT            1000        ;xxx hello receive timeout [ms]
        #define        HELLOTRIES        2            ;xxx number of non hello characters received before branching to the user application
        #define        BLTIME            1000        ;xxx data receive timeout [ms]


;------------------------------------------------------------------------------
; UART settings
;------------------------------------------------------------------------------            
        #define        USE_UART1        1            ;xxx uncomment to use uart1
        #define        BAUDRATE         9600        ;xxx baudrate
        ;#define    USE_ABAUD        1            ;xxx uncomment to use auto baud rate detection, READ ERRATA FIRST        
        ;#define    USE_BRG16        1            ;xxx uncomment to use 16-bit brg

        #define    USE_TXENABLE    1            ;xxx uncomment to use a tx enable pin        
        ifdef USE_TXENABLE
            #define    TXE_DELAY         100            ;xxx time in us to wait before transmitting after pulling the tx enable pin high
            #define    TRISR_TXE        TRISB        ;xxx tris register containing tx enable
            #define    LATR_TXE        LATB        ;xxx port register containing tx enable
            #define    TRISB_TXE        TRISB6        ;xxx tris bit for tx enable
            #define LATB_TXE        RB6            ;xxx port bit for tx enable
        endif


;------------------------------------------------------------------------------
; Advanced settings
;------------------------------------------------------------------------------        
        #define        KICK_WD            1            ;xxx uncomment to kick the wd in the rx loop, only enable if the watchdog is enabled
        #define        PROT_GOTO        1            ;xxx protect goto at 0x00
        #define        PROT_BL         1            ;xxx protect bootloader
        #define        WRITE_VER        1            ;do flash write verification
        #define        EWRITE_VER        1            ;do eeprom write verification
        
        ifdef IS_PIC18F
            #define        BLPLP        9            ;bootloader placement, pages from end
            #define        BLSIZEP        9            ;bootloader size [pages], used by bootloader protection    
        endif
        
        ifdef IS_PIC18FJ        
            #define        BLPLP        2            ;bootloader placement, pages from end
            #define        BLSIZEP        1            ;bootloader size [pages], used by bootloader protection    
        endif
        

;------------------------------------------------------------------------------
; Configuration bits, these macros can be found at the end of the inc-files located in
; C:\Program Files\Microchip\MPASM Suite\
;
; These can also be set in MPLAB IDE instead, they are found in Configure->Configuration bits...
;------------------------------------------------------------------------------


        ; xxx
        ;config    RETEN             = OFF           ;Ultra low-power regulator is Disabled (Controlled by REGSLP bit)
        ;config    INTOSCSEL         = LOW            ;LF-INTOSC in Low-power mode during Sleep
        ;config    SOSCSEL         = LOW               ;Low Power SOSC circuit selected
        config    XINST             = OFF               ;Disabled
        config    FOSC             = IRC            ;XT oscillator
        config    PLLEN             = Off               ;Enabled
        config    PCLKEN            = Off
        config    FCMEN             = OFF           ;Disabled
        config    IESO             = OFF           ;Disabled
        config    PWRTEN             = OFF           ;Disabled
        config    HFOFST            = Off

        config BOREN             = OFF            ;Brown Out Detect
        ;config    BORV             = 3             ;1.8V
        ;config    BORPWR            = MEDIUM        ;BORMV set to medium power level
        config    WDTEN             = OFF              ;WDT disabled in hardware; SWDTEN bit disabled
        config    WDTPS             = 32768         ;1:32768
        ;config    CANMX             = PORTE         ;ECAN TX and RX pins are located on RE5 and RE4, respectively
        ;config    T0CKMX             = PORTG             ;Timer0 gets its clock input from the RG4/T0CKI pin on 64-pin packages
        ;config    T3CKMX             = PORTB         ;Timer3 gets its clock input from the RB5/T3CKI pin on 64-pin packages
        ;config    MSSPMSK         = MSK7          ;7 Bit address masking mode
        config    MCLRE             = ON            ;MCLR Enabled, RG5 Disabled
        config    STVREN             = ON            ;Stack Overflow Reset            
        
        ;config    BBSIZ             = BB2K            ;Boot Block Size
        config    CP0             = OFF            ;Code Protect 00800-03FFF
        config    CP1             = OFF            ;Code Protect 04000-07FFF
        ;config    CP2                 = OFF            ;Code Protect 08000-0BFFF
        ;config    CP3             = OFF            ;Code Protect 0C000-0FFFF
        ;config    CPB             = OFF            ;Code Protect Boot
        config    CPD             = OFF            ;Data EE Read Protect
        config    WRT0             = OFF            ;Table Write Protect 00800-03FFF
        config    WRT1             = OFF            ;Table Write Protect 04000-07FFF
        ;config    WRT2             = OFF            ;Table Write Protect 08000-0BFFF
        ;config    WRT3             = OFF            ;Table Write Protect 0C000-0FFFF
        config    WRTC             = OFF            ;Config. Write Protect
        config    WRTB             = OFF            ;Table Write Protect Boot
        config    WRTD             = OFF            ;Data EE Write Protect
        config    EBTR0             = OFF            ;Table Read Protect 00800-03FFF        
        config    EBTR1             = OFF            ;Table Read Protect 04000-07FFF
        ;config    EBTR2             = OFF            ;Table Read Protect 08000-0BFFF
        ;config    EBTR3            = OFF            ;Table Read Protect 0C000-0FFFF
        config    EBTRB             = OFF           ;Table Read Protect Boot
        

;------------------------------------------------------------------------------
; ds30 Loader commercial version
;------------------------------------------------------------------------------
;-Supports read of flash and EEPROM
;-Supports software UART
;-Supports CAN
;-Available with encryption
;-Read more at www.ds30loader.com


;------------------------------------------------------------------------------
; End of file
;------------------------------------------------------------------------------
PLL function does not affect it. It is still 16MHz.

And uart.inc has some problem.
Code:
;------------------------------------------------------------------------------
;
; Title:            ds30 Loader for PIC18
;
; File description:    UART functions
;
; Copyright:         Copyright © 2011, Mikael Gustafsson
;
; History:            3.0.0 first version of this file
;                                                                            
;------------------------------------------------------------------------------

;-----------------------------------------------------------------------------
;    This file is part of ds30 Loader.
;
;    ds30 Loader is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation.
;
;    ds30 Loader is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.
;
;    You should have received a copy of the GNU General Public License
;    along with ds30 Loader. If not, see <http:;www.gnu.org/licenses/>.
;------------------------------------------------------------------------------
        

;------------------------------------------------------------------------------
; UARTs
;------------------------------------------------------------------------------
        ifdef USE_UART1
            ifdef USE_UART2
                error "Both uarts are specified"
            endif
            
            #define PIRRCIF_        PIR1                ;uart interupt status register
            #define RCIF_            RCIF
            
            ifndef TXSTA1
                   #define TXSTA_        TXSTA                ;uart status
                   #define    RCSTA_        RCSTA                ;uart status
                   #define    SPBRG_        SPBRG                ;uart baudrate
                   #define    TXREG_        TXREG                ;uart transmit
                   #define    RCREG_        RCREG                ;uart receive
            else
                   #define    TXSTA_        TXSTA1                ;uart status
                   #define    RCSTA_        RCSTA1                ;uart status
                   #define    SPBRG_        SPBRG1                ;uart baudrate
                   #define    TXREG_        TXREG1                ;uart transmit
                   #define    RCREG_        RCREG1                ;uart receive
            endif
            
            ifdef BAUDCON
                   #define    BAUDCON_    BAUDCON                ;uart receive
            else
                   #define    BAUDCON_    BAUDCON1            ;uart receive
            endif
            
            ifdef SPBRGH
                   #define    SPBRGH_        SPBRGH                ;uart receive
            else
                   #define    SPBRGH_        SPBRGH1                ;uart receive
            endif
        endif

        ifdef USE_UART2
            ifdef USE_UART1
                error "Both uarts are specified"
            endif        
            ifndef HAS_UART2
                error "UART2 specified for a device that only has uart1"
            endif
            
            
            #define PIRRCIF_    PIR3                    ;uart interupt status register
            #define RCIF_        RC2IF

               #define    TXSTA_        TXSTA2                    ;uart status
               #define    RCSTA_        RCSTA2                    ;uart status
               #define    SPBRG_        SPBRG2                    ;uart baudrate
            #define    SPBRGH_        SPBRGH2                    ;uart baudrate
               #define    TXREG_        TXREG2                    ;uart transmit
               #define    RCREG_        RCREG2                    ;uart receive
            #define    BAUDCON_    BAUDCON2                ;uart receive
        endif
        
        ;
        ifdef USE_TXENABLE
            #define    TXE_DELAY_CNT    ( (TXE_DELAY * OSCF) / (4000000 * 3) )
        endif

                
;------------------------------------------------------------------------------
; Range check
;------------------------------------------------------------------------------
        ifndef USE_BRG16
            if UBRG > 255
                error spbrg_value_ is out of range
            endif
        else
            if UBRG > 65535
                error spbrg_value_ is out of range
            endif
        endif
        
        if UBRG == 0
            error spbrg_value_ might be out of range
        endif
        

;------------------------------------------------------------------------------
; CommInit()
;------------------------------------------------------------------------------    
CommInit
        banksel    TXSTA_
        ifdef USE_BRG16
            bsf        BAUDCON_, BRG16
            movlw    (UBRG>>8)
            movwf    SPBRGH_
        endif

        movlw     b'00100100'        ;enable transmit and
        movwf     TXSTA_            ; high speed mode
        movlw     (UBRG&0xff)
        movwf     SPBRG_
        movlw     b'10010000'        ;enable serial port
        movwf     RCSTA_            ; and receive
            
        ifdef USE_ABAUD
            ; Activate auto baud rate detection
            bsf        BAUDCON_, ABDEN            
            ; Wait for auto baudrate detection to finish with timeout control
            movlw     BLSTART
            movwf    cnt1            ;
abd_rpt2    movlw    DELBASE            ;
            movwf    cnt2            ;        
abd_rpt3    clrf     cnt3        
abd_rptc    clrwdt
            btfss     BAUDCON_, ABDEN
            bra     abd_ok        
abd_notrcv    decfsz     cnt3
            bra     abd_rptc
            decfsz     cnt2
            bra     abd_rpt3
            decfsz     cnt1
            bra     abd_rpt2
            ; abd timed out if we get here
            bra        exit            
            ; abd finished
abd_ok        movf    RCREG_, w        ;clear rcif
            SendL    OK    
    
        endif
        
        ; Make tx enable pin output and set to 0
        ifdef USE_TXENABLE
            bcf    TRISR_TXE, TRISB_TXE
            bcf    LATR_TXE, LATB_TXE
        endif
        

        movlb 0x0
        return    
        

;------------------------------------------------------------------------------
; CommExit()
;------------------------------------------------------------------------------    
CommExit
        banksel    RCSTA_
        clrf    RCSTA_            ;reset receive status and control register
        clrf    TXSTA_            ;reset transmit status and control register
        ifdef USE_BRG16
            clrf BAUDCON_
            clrf SPBRGH_
        endif
        
        movlb 0x0        
        return    

;------------------------------------------------------------------------------
; Receive()
;------------------------------------------------------------------------------    
Receive    movlw     BLDELAY
RcvIni    movwf    cnt1            ;
rpt2    movlw    DELBASE            ;
        movwf    cnt2            ;        
rpt3    clrf     cnt3        
rptc    
        ifdef KICK_WD
            clrwdt
        endif
        btfss     PIRRCIF_, RCIF_
        bra     notrcv
        banksel    RCREG_
        movf     RCREG_, w        ;return read data in W
        movlb     0x0
        addwf     crc, f            ;compute crc
        return        
notrcv    decfsz     cnt3
        bra     rptc
        decfsz     cnt2
        bra     rpt3
        decfsz     cnt1
        bra     rpt2
        ; Receive timed out if we get here
        bra        exit        
        
        
;------------------------------------------------------------------------------
; Send()
;------------------------------------------------------------------------------        
Send    ; Enable tx
        banksel    TXSTA_
        ifdef USE_TXENABLE
            bcf        RCSTA_, CREN            ;disable serial receiver
            movwf    cnt2
            bsf    LATR_TXE, LATB_TXE
            movlw    TXE_DELAY_CNT
            movwf    cnt1
txe_del_lo    decfsz    cnt1
            bra        txe_del_lo
            movf    cnt2, w
        else        
            ; Wait for transmit shift register to get empty
txwait        btfss    TXSTA_, TRMT
            bra        txwait
        endif        
        ;Send byte
        movwf     TXREG_
        ; Disable tx
        ifdef USE_TXENABLE
            ; Wait for transmit shift register to get empty
txwait        btfss    TXSTA_, TRMT
            bra        txwait
            bcf        LATR_TXE, LATB_TXE
            bsf        RCSTA_, CREN            ;enable serial receiver
        endif
        ; Send complete
        movlb 0x0
        return
    
    
;------------------------------------------------------------------------------    
; End of file
;------------------------------------------------------------------------------



RE: Pic18F14K22 with USB MCP2200 - Mikael Gustavsson - 2013-11-30

Start a separate thread.