Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIC24HJ16GP304 loader issue [solved]
#1
Hi Mikael.

I have some problems with the loader.
When i connect with the GUI i only get (discarded null character). Nothing more.
I think the loader is receiving correctly, because i can see the TX enable signal going high after the GUI tries to connect, but nothing comes out from the TX pin.
Hardware has been verified with my app.
Info:
Bus: RS485, 9600
PIC UART1: TX = RP7, RX = RP22, TX_ENA = RP9
PIC Clock: Xtal 14.745Mhz
From Settings:
Code:
;------------------------------------------------------------------------------
;
; Title:            ds30 loader
;
; File description:    user settings and configuration bits for PIC24 and dsPIC
;
; 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
;------------------------------------------------------------------------------
        ;.equ __24F16KA102,         1            ;xxx uncomment and change if using PIC24F device
        ;.equ __24FJ128GA010,         1            ;xxx uncomment and change if using PIC24FJ device
        ;.equ __24HJ128GP504,         1            ;xxx uncomment and change if using PIC24HJ device
        ;.equ __30F4013,             1            ;xxx uncomment and change if using dsPIC30F device
        ;.equ __33FJ256GP710A,         1            ;xxx uncomment and change if using dsPIC33FJ device
        .equ __24HJ16GP304,            1

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


;------------------------------------------------------------------------------
; User preferences
;------------------------------------------------------------------------------
        .equiv     FCY,                 7372800        ;xxx speed of internal cycle clock[Hz], used to calculate uart brg and delay (****custom for 14mhz xtal*****)
        .equiv    BLINIT,                6000        ;xxx hello receive timeout [ms]
        .equiv    HELLOTRIES,            2            ;xxx number of non hello characters received before branching to the user application    
        .equiv    BLTIME,                3000        ;xxx data receive timeout [ms]
        

;------------------------------------------------------------------------------
; UART settings
;------------------------------------------------------------------------------        
        .equiv    USE_UART1,            1            ;xxx uncomment to use uart1
        ;.equiv    USE_UART2,            1            ;xxx uncomment to use uart2
        ;.equiv    USE_UART3,            1            ;xxx uncomment to use uart3
        ;.equiv    USE_UART4,            1            ;xxx uncomment to use uart4
        ;.equ    USE_ALTIO,            1            ;xxx uncomment to use uart 1 alternative i/o, only for dsPIC30F
        .equiv     BAUDRATE,             9600        ;xxx baudrate
        ;.equiv    USE_ABAUD,            1            ;xxx uncomment to use auto baud rate detection, READ ERRATA FIRST        
        .equiv    USE_BRGH,            1            ;xxx uncomment to use high baud rates, READ ERRATA FIRST, not available for PIC24F        
        
        .equiv    USE_TXENABLE,        1            ;xxx uncomment to use a tx enable pin        
        .ifdef USE_TXENABLE
            .equ    TXE_DELAY,         10            ;xxx time in us to wait before transmitting after pulling the tx enable pin high
            .equiv    TRISR_TXE,        TRISB        ;xxx tris register containing tx enable (***Customized for B9***)
            .equiv     LATR_TXE,        LATB        ;xxx port register containing tx enable (***Customized for B9***)
            .equiv    TRISB_TXE,        TRISB9        ;xxx tris bit for tx enable (***Customized for B9***)
            .equiv    LATB_TXE,        RB9            ;xxx port bit for tx enable (***Customized for B9***)
        .endif
        
        
;------------------------------------------------------------------------------
; Advanced settings
;------------------------------------------------------------------------------
        ;.equiv    KICK_WD,            1            ;xxx uncomment to kick the wd in the rx loop, ONLY enable if watchdog is enabled
        .equiv    WRITE_VER,            1            ;xxx do flash write verification
        .equiv    EWRITE_VER,            1            ;xxx do eeprom write verification
        .equiv    PROT_GOTO,            1            ;protect goto at 0x00
        .equiv    PROT_BL,            1            ;protect bootloader
                
        .ifdef    IS_24F
            .equiv    BLPLP,            7            ;bootloader placement, pages from end
            .equiv    BLSIZEP,        7            ;bootloader size [pages], used by bootloader protection
        .endif
                
        .ifdef    IS_24FJ
            .equiv    BLPLP,            2            ;bootloader placement, pages from end
            .equiv    BLSIZEP,        1            ;bootloader size [pages], used by bootloader protection
        .endif
        
        .ifdef IS_24HJ
            .equiv    BLPLP,            1            ;bootloader placement, pages from end
            .equiv    BLSIZEP,        1            ;bootloader size [pages], used by bootloader protection
        .endif
                
        .ifdef    IS_30F
            .equiv    BLPLP,            9            ;bootloader placement, pages from end
            .equiv    BLSIZEP,        9            ;bootloader size [pages], used by bootloader protection
        .endif
        
        .ifdef IS_33FJ
            .equiv    BLPLP,            1            ;bootloader placement, pages from end
            .equiv    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\MPLAB ASM30 Suite\Support\dsPIC33F\inc
;
; These can also be set in MPLAB IDE instead, they are found in Configure->Configuration bits...
;------------------------------------------------------------------------------
        .ifdef    IS_24F
            ;config    __FBS,    BSS_OFF/*Boot Segment Code Protect*/ & BWRP_OFF/*Boot Segment Write Protect Enable*/
            ;config    __FGS,    GCP_OFF/*General Segment Code Protect*/ & GWRP_OFF/*General Segment Write Protect Enable*/
            config    __FOSCSEL,    FNOSC_FRC/*Initial Oscillator Select*/ & IESO_OFF/*Two Speed Start-up*/
            config    __FOSC,    FCKSM_CSDCMD/*Clock switching and Fail-Safe Clock monitor*/ & SOSCSEL_SOSCLP/*Secondary Oscillator Select*/ & POSCFREQ_MS/*Primary Oscillator Frequency Range*/ & OSCIOFNC_ON/*OSCO Pin Configuration*/ & POSCMOD_XT/*Oscillator Selection*/
            ;config    __FWDT,    FWDTEN_OFF/*Watchdog Timer*/ & WINDIS_OFF/*Windowed WDT*/ & FWPSA_PR32/*Watchdog prescaler*/ & WDTPS_PS1/*Watchdog postscale*/
            ;config    __FPOR, MCLRE_ON/*Master Clear Enable*/ & BORV_LPBOR/*Brown Out Voltage*/ & I2C1SEL_PRI/*I2C1 pins Select*/ & PWRTEN_OFF/*Power Up Timer*/ & BOREN_BOR0/*Brown Out Reset*/
            ;config    __FICD, BKBUG_OFF/*Background Debugger*/ &     ICS_PGx1/*ICD pins select*/
            ;config    __FDS,    DSWDTEN_OFF/*Deep Sleep Watchdog Timer*/ & DSBOREN_OFF/*Deep Sleep BOR*/ & RTCOSC_LPRC/*RTCC Reference Oscillator Select*/ & DSWDTOSC_LPRC/*Deep Sleep Watchdog Oscillator Clock Select*/ & DSWDTPS_DSWDTPS0/*Deep Sleep Watchdog Postscale*/
        .endif
                
        .ifdef    IS_24FJ
            config    __CONFIG1, JTAGEN_OFF/*JTAG*/ & GCP_OFF/*code protect*/ & GWRP_OFF/*write protect*/ & BKBUG_OFF/*background debugger*/ & COE_OFF/*clip-on emulation mode*/ & ICS_PGx2/*icd pins select*/ & FWDTEN_OFF/*watchdog timer*/ & WINDIS_OFF/*windowed wdt*/ & FWPSA_PR32/*watchdog prescalar*/ & WDTPS_PS1/*watchdog postscalar*/
            config    __CONFIG2, IESO_OFF/*two-speed startup*/ & FNOSC_FRC/*oscillator selection*/ & FCKSM_CSDCMD/*clock switching and clock monitor*/ & OSCIOFNC_OFF/*OSC0/RC15 function*/ & POSCMOD_XT/*oscillator selection*/
            ;config     __CONFIG3, WPEND_WPSTARTMEM/*write protect range selection*/ & WPCFG_WPCFGDIS/*write protection config page*/ & WPDIS_WPEN/*write protection*/ & WPFP_WPFP8/*Write Protection Flash Page*/
        .endif
        
        .ifdef IS_24HJ
            ;config __FBS,         RBS_NO_RAM & BSS_NO_FLASH & BWRP_WRPROTECT_OFF        ;xxx boot segment
            ;config __FSS,         RSS_NO_RAM & SSS_NO_FLASH & SWRP_WRPROTECT_OFF        ;xxx secure segment
            ;config __FGS,        GSS_OFF & GCP_OFF & GWRP_OFF                        ;xxx general segment
            ;;config     __FOSCSEL,     FNOSC_FRC & IESO_OFF                                 ;xxx oscillator mode
            ;;config     __FOSC,     FCKSM_CSDCMD & OSCIOFNC_ON & POSCMD_XT                ;xxx clock switching/clock monitor, osc2 & oscillator selection
            config __FOSCSEL, FNOSC_PRI & IESO_OFF                                    ;(***Customized for Xtal 14mhz***)
            config __FOSC, FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_HS                    ;(***Customized for Xtal 14mhz***)
            config    __FWDT,        FWDTEN_OFF & WINDIS_OFF                                ;xxx watchdog
            ;config    __FPOR,        FPWRT_PWR1                                            ;xxx pwm, power-on reset
            ;config    __FICD,        BKBUG_ON & COE_ON & JTAGEN_OFF & ICS_PGD1
        .endif
        
        .ifdef    IS_30F
            config     __FOSC,     CSW_FSCM_OFF & FRC_PLL16                            ;xxx oscillator
            config     __FWDT,     WDT_OFF                                                ;xxx watchdog
            config     __FBORPOR,    PBOR_OFF & PWRT_OFF & MCLR_EN                        ;xxx power-on reset, brown-out reset, master clear
            ;config __FGS,         CODE_PROT_OFF & GWRP_OFF                            ;xxx code protection
            config     __FICD,     ICS_PGD                                                ;xxx comm channel select
        .endif
        
        .ifdef IS_33FJ
            ;config     __FBS,         RBS_NO_RAM & BSS_NO_FLASH & BWRP_WRPROTECT_OFF    ;xxx boot segment
            ;config     __FSS,         RSS_NO_RAM & SSS_NO_FLASH & SWRP_WRPROTECT_OFF    ;xxx secure segment
            ;config    __FGS,        GSS_OFF & GCP_OFF & GWRP_OFF                        ;xxx general segment
            config     __FOSCSEL,     FNOSC_PRIPLL & IESO_OFF                             ;xxx oscillator mode
            config     __FOSC,     FCKSM_CSECMD & OSCIOFNC_ON & POSCMD_XT                ;xxx clock switching/clock monitor, osc2 & oscillator selection
            config    __FWDT,        WDTPOST_PS256 & WDTPRE_PR128 & FWDTEN_OFF & WINDIS_OFF        ;xxx watchdog
            config    __FPOR,        FPWRT_PWR1                                            ;xxx pwm, power-on reset
            config    __FICD,        JTAGEN_OFF & ICS_PGD1                                ;xxx
        .endif


;------------------------------------------------------------------------------
; End of file
;------------------------------------------------------------------------------

User Code:
Code:
;------------------------------------------------------------------------------
;
; Title:            ds30 Loader for PIC24 and dsPIC
;
; File description:    user init and exit code
;
; Copyright:         Copyright © 2011, 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/>.
;------------------------------------------------------------------------------


;------------------------------------------------------------------------------
; UserInit()
; Description: this is executed immediately on start-up before the boot loader code
;------------------------------------------------------------------------------
        .macro UserInit
                ;Input output config
                mov #0b0000000000001111,W0
                mov W0, TRISA
                mov #0b1111000101000000,W0
                mov W0, TRISB
                mov #0b0000001111000000,W0
                mov W0, TRISC
                ;set up analog or digital inputs on the pins
                mov #0b110000111111100,W0
                mov W0, AD1PCFGL
            ;----------------------------------------------------------------------
            ; Make uart pins digital
            ;----------------------------------------------------------------------
            .ifdecl ADPCFGL                
                ;.error "Do you need to configure communication pins to be digital? If not, remove this line"
            .else
                .ifdecl AD1PCFGL
                    .error "Do you need to configure communication pins to be digital? If not, remove this line"
                .endif
            .endif
            
            
            ;----------------------------------------------------------------------
            ; UART/CAN pps config
            ;----------------------------------------------------------------------
            .ifdef HAS_PPS
                ;.error "PPS is not configured. More information in the firmware manual."            ;xxx remove this line when PPS is configured                        
            
                ; ** IMPORTANT **
                ;
                ; THIS CODE IS JUST A TEMPLATE AND WILL MOST LIKELY NOT WORK FOR YOU,
                ; READ THE DATASHEET AND ALTER LINES MARKED WITH XXX
                ;
                ; ** IMPORTANT **
    
                ; Receive, map pin (14 = 1110) to uart ;(***Customized for RP22***)
                bclr    RPINR18, #U1RXR0        ;xxx
                bset    RPINR18, #U1RXR1        ;xxx
                bset    RPINR18, #U1RXR2        ;xxx
                bclr    RPINR18, #U1RXR3        ;xxx
                bset    RPINR18, #U1RXR4        ;xxx
                        
                ; Transmit, map uart to pin ;(***Customized for RP7***)
                bset    RPOR7, #RP15R0            ;xxx
                bset    RPOR7, #RP15R1            ;xxx
                bset    RPOR7, #RP15R2            ;xxx
                bclr    RPOR7, #RP15R3            ;xxx
                bclr    RPOR7, #RP15R4            ;xxx    
            .endif    
        


        ; End of macro
        .endm
        
        
;------------------------------------------------------------------------------
; UserExit()
; Description: this is executed right before the user application is loadaed
;------------------------------------------------------------------------------
        .macro UserExit
        
        
        ; End of macro
        .endm
        

;------------------------------------------------------------------------------
; End of file
;------------------------------------------------------------------------------

Thanks for reading Mikael, going bald from scratching my head...


Attached Files
.zip   ds30Loader.zip (Size: 49.16 KB / Downloads: 14)
Reply
#2
Hi,
Which RS485 chip are you using? Have you tried increasing the TXE_DELAY define?
Can you test with rs232 just to rule out configuration problems?
Reply
#3
Thanks for replying.
The chip is a standard configuration 8pin tranciever.
I measure the data between the pic and the driver, so that rules out timing issues.
Thats why i dont think its meaningful to connect as 232. Nothing comes out of the pic tx port. I will dig deeper on monday. Perhaps its the rts/cts of the uart that is configured badly. In my app i do not use that, but drive the data enable in code.
Reply
#4
Hi.
I think its some PPS issue but cannot find it!!
I would be very grateful if you could take a look at the code.
Only change made from the uploaded code is this:
Code:
                ; Transmit, map uart to pin ;(***Customized for RP7***)
                bset    RPOR7, #RP15R0            ;xxx
                bset    RPOR7, #RP15R1            ;xxx
                bclr    RPOR7, #RP15R2            ;xxx
                bclr    RPOR7, #RP15R3            ;xxx
                bclr    RPOR7, #RP15R4            ;xxx
Where there was an error.

Thanks in advance..
Reply
#5
The comment says RP7 but the code says RP15, which pin is tx connected to?
If RP15, you have not configure that pin to be digital, AN9, bit PCFG9 in register AD1PCFGL.
Reply
#6
Ahh..
should be this way?
Code:
                ; Receive, map pin (14 = 1110) to uart ;(***Customized for RP22***)
                bclr    RPINR18, #U1RXR0        ;xxx
                bset    RPINR18, #U1RXR1        ;xxx
                bset    RPINR18, #U1RXR2        ;xxx
                bclr    RPINR18, #U1RXR3        ;xxx
                bset    RPINR18, #U1RXR4        ;xxx
                        
                ; Transmit, map uart to pin ;(***Customized for RP7***)
                bset    RPOR7, #RP7R0            ;xxx
                bset    RPOR7, #RP7R1            ;xxx
                bclr    RPOR7, #RP7R2            ;xxx
                bclr    RPOR7, #RP7R3            ;xxx
                bclr    RPOR7, #RP7R4            ;xxx
Reply
#7
Taking guesses may work but I usually take a look in the datasheet.
Reply
#8
Thanks for that but it did not work to take a guess. Had to follow you advice and look in the datasheet :-)
I enclose the correct PPS code here in order not to lead anyone else on the wrong track.
Code:
                ; Receive, map pin (14 = 1110) to uart ;(***Customized for RP22***)
                bclr    RPINR18, #U1RXR0        ;xxx
                bset    RPINR18, #U1RXR1        ;xxx
                bset    RPINR18, #U1RXR2        ;xxx
                bclr    RPINR18, #U1RXR3        ;xxx
                bset    RPINR18, #U1RXR4        ;xxx
                        
                ; Transmit, map uart to pin ;(***Customized for RP7***)
                bset    RPOR3, #RP7R0            ;xxx
                bset    RPOR3, #RP7R1            ;xxx
                bclr    RPOR3, #RP7R2            ;xxx
                bclr    RPOR3, #RP7R3            ;xxx
                bclr    RPOR3, #RP7R4            ;xxx
At this point i can see the loader responding with device name and loader version.
However when actually using "write" it stops after a few characters. I tried 9600, 19200 and extending the TX enable delay.
Enclosed is the output from the GUI.

When I probe(screendump enclosed) the output pins for TX(yellow) and TXEN(blue) i get some funny results. It looks like TXEN goes low long before the transmit is finished. When examining your code i cannot see how that could happen.

Do you recognize the behavior above?

Thanks for your patience.


Attached Files Thumbnail(s)
       
Reply
#9
That looks weird. Can you post a new pic of the oscilloscope with a better time base?
You could try to insert a few nop before polling of the transmit shift register status bit
in case it isn't updated immediately.
Reply
#10
Thanks,
I added exactly one nop and that did the trick.
Please see enclosed screenshot.
Now it downloads without communication errors.


Attached Files Thumbnail(s)
   
Reply
#11
Great! Thanks for the update.
Reply
#12
I have just had a similar issue with the PIC24FJ64GA004 using an isolated RS485 interface - and this sneaky 'nop' soloved the problem. Thanks for the guidance.
Reply
#13
Info to user readers of this thread; the 130708 release contains this fix and does not need to be implemented.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)