|
|
View previous topic :: View next topic |
Author |
Message |
Jody
Joined: 08 Sep 2006 Posts: 182
|
Tiny Bootloader PIC18F8722 |
Posted: Mon Feb 18, 2008 8:08 am |
|
|
Hello,
I am trying to use the tiny bootloader with a 18F8722....
And to make tinks more complez I have also a RS485 connection...
Receive and Transit is connected like the normal RS232 pins.. ie through a SN75176.... This works... Have connected the RE/DE pin to RE0. And when I use the tiny bootlader with a modificated Tinybootloade.ASM I can get the HEX file into the PIC..... But when it should run after a reset I can't get any contact with it....... anyone a idea?????
include mine ASM file.
Thanks in advance,
Jody
Code: |
radix DEC
LIST P=PIC18F8722 ; change also: Configure->SelectDevice from Mplab
xtal EQU 10000000 ; you may want to change: _XT_OSC_1H _HS_OSC_1H _HSPLL_OSC_1H
baud EQU 19200 ; standard TinyBld baud rates: 115200 or 19200
; The above 3 lines can be changed and buid a bootloader for the desired frequency (and PIC type)
;********************************************************************
; Tiny Bootloader 18F series Size=132words
; claudiu.chiculita@ugal.ro
; http://www.etc.ugal.ro/cchiculita/software/picbootloader.htm
;********************************************************************
#include "C:\MentorProjects\Bootloader_RS485\icdpictypes.inc" ;takes care of: #include "p18fxxx.inc", max_flash, IdTypePIC
#include "C:\MentorProjects\Bootloader_RS485\spbrgselect.inc" ; RoundResult and baud_rate
#define first_address max_flash-264 ;132 words
; __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
; __CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_ON_2L
; __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
; __CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
;----------------------------- PROGRAM ---------------------------------
cblock 0
crc
i
cnt1
cnt2
cnt3
counter_hi
counter_lo
flag
endc
cblock 10
buffer:64
dummy4crc
sendb ; Byte to send
d1 ; For delay routine
endc
;0000000000000000000000000 RESET 00000000000000000000000000
ORG 0x0000
GOTO IntrareBootloader
;view with TabSize=4
;&&&&&&&&&&&&&&&&&&&&&&& START &&&&&&&&&&&&&&&&&&&&&&
;---------------------- Bootloader ----------------------
;PC_flash: C1h U H L x ... <64> ... crc
;PC_eeprom: C1h 40h EEADR EEDATA 0 crc
;PC_cfg C1h U OR 80h H L 1 byte crc
;PIC_response: type `K`
ORG first_address ;space to deposit first 4 instr. of user prog.
nop
nop
nop
nop
org first_address+8
IntrareBootloader
movlw b'11111110' ;RE_DE SN75176 zit op RE0
movwf TRISE
movlw b'10111111'
movwf TRISC
;init serial port
movlw b'00100100'
movwf TXSTA
movlw spbrg_value
movwf SPBRG
movlw b'10010000'
movwf RCSTA
;wait for computer
rcall Receive
sublw 0xC1 ;Expect C1h = 'K'
bnz way_to_exit
movlw IdTypePIC
rcall SendW ;send PIC type
MainLoop
movlw 'K'
rcall SendW ; "-Everything OK, ready and waiting."
mainl
clrf crc
rcall Receive ;Upper
movwf TBLPTRU
movwf flag ;(for EEPROM and CFG cases)
rcall Receive ;Hi
movwf TBLPTRH
movwf EEADR ;(for EEPROM case)
rcall Receive ;Lo
movwf TBLPTRL
movwf EEDATA ;(for EEPROM case)
rcall Receive ;count
movwf i
incf i
lfsr FSR0, (buffer-1)
rcvoct ;read 64+1 bytes
movwf TABLAT ;prepare for cfg; => store byte before crc
rcall Receive
movwf PREINC0
decfsz i
bra rcvoct
tstfsz crc ;check crc
bra ziieroare
btfss flag,6 ;is EEPROM data?
bra noeeprom
movlw b'00000100' ;Setup eeprom
rcall Write
bra waitwre
noeeprom
btfss flag,7 ;is CFG data?
bra noconfig
tblwt* ;write TABLAT(byte before crc) to TBLPTR***
movlw b'11000100' ;Setup cfg
rcall Write
bra waitwre
noconfig
;write
eraseloop
movlw b'10010100' ; Setup erase
rcall Write
TBLRD*- ; point to adr-1
writebigloop
movlw 8 ; 8groups
movwf counter_hi
lfsr FSR0,buffer
writesloop
movlw 8 ; 8bytes = 4instr
movwf counter_lo
writebyte
movf POSTINC0,w ; put 1 byte
movwf TABLAT
tblwt+*
decfsz counter_lo
bra writebyte
movlw b'10000100' ; Setup writes
rcall Write
decfsz counter_hi
bra writesloop
waitwre
;btfsc EECON1,WR ;for eeprom writes (wait to finish write)
;bra waitwre ;no need: round trip time with PC bigger than 4ms
bcf EECON1,WREN ;disable writes
bra MainLoop
ziieroare ;CRC failed
movlw 'N'
rcall SendW
bra mainl
;******** procedures ******************
; Delay is needed because the SN75176 need time for transitions.
; Only required for the RE_DE line.
Delay50us
movlw 165*xtal/40000000
movwf d1
Delay_0
decfsz d1, f
goto Delay_0
return
SendW
movwf sendb
bsf PORTE,0 ; RE_DE_485 PORTE pin 0 hoog maken om RS485 te zenden
btfss PIR1,TXIF
goto $-2
rcall Delay50us
movff sendb,TXREG
nop
bsf PORTE,0 ; RE_DE_485 PORTE pin 0 hoog maken om RS485 te zenden
btfss TXSTA,TRMT
goto $-2
bcf PORTE,0 ; RE_DE_485 PORTE pin 0 laag maken om RS485 te ontvangen
rcall Delay50us
return
Write
clrwdt
movwf EECON1
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1,WR ;WRITE
nop
;nop
return
Receive
clrwdt
movlw xtal/2000000+1 ; for 20MHz => 11 => 1second delay
movwf cnt1
rpt2
clrf cnt2
rpt3
clrf cnt3
rptc
btfss PIR1,RCIF ;test RX
bra notrcv
movf RCREG,w ;return read data in W
addwf crc,f ;compute crc
return
notrcv
decfsz cnt3
bra rptc
decfsz cnt2
bra rpt3
decfsz cnt1
bra rpt2
;timeout:
way_to_exit
bcf RCSTA, SPEN ; deactivate UART
movlw b'11111111'
movwf TRISC
bra first_address
;*************************************************************
; After reset
; Do not expect the memory to be zero,
; Do not expect registers to be initialised like in catalog.
END
|
|
|
|
D-Kens
Joined: 09 May 2005 Posts: 35 Location: Toulouse (France)
|
|
Posted: Mon Feb 18, 2008 10:21 am |
|
|
Hi...
I'm surprised by your post, as it took me less than 2 minutes to have Tiny Bootlader working on a PIC18F4620. What do you mean "I manage to get the HEX file into the PIC" ? When I read your problem, I'm afraid I understand that you use the programm Tiny Bootloader to load the bootloader firmware into your PIC, which can't work, as far as I know.
You didn't need either to post the ASM code from the bootlader : except the 3 first configuration lines, it's all working code and we all have the same.
The process is to load the bootloader firmware into your PIC (I use ICD programmer for that), then at reset your PIC will enter the bootloader mode, which means it'll wait for you to send your own programm using Tiny Bootloader. Check the settings for your serial port (Tiny Bootloader uses 115200 bauds by default, but your firmware in ASM says you use a 19200 bauds connection on the PIC side) : then click on "write flash" to begin programmation... It HAS to work !
Good luck, young padawan.
Christophe. |
|
|
Guest
|
|
Posted: Mon Feb 18, 2008 11:29 am |
|
|
Well working with "just" RS232 I has no problems....
And I wrote a simple LED flash program...
The bootloader I program with the CCS ICD..
And then I program mine hex file with tiny bootloader to the PIC...
So far.. so good...
when I now reset the PIC to progam doesn't run........ that is the LED doesn't flash.....
And: "Good luck, young padawan" what age are you... calling someone else "young"????
Regards,
Jody |
|
|
Guest
|
Re: Tiny Bootloader PIC18F8722 |
Posted: Mon Feb 18, 2008 8:18 pm |
|
|
Jody,
I think I see a couple of possible issues.
First, why would you provide a 50us delay for the enable transition? The 75176bp data sheet I looked at indicated an enable line latency of ~80ns (nano-seconds).
Secondly, in the following code snippet, it appears that you are looping while waiting for the TXIF register to be set. Is this necessary? I mean if you load the TXREG and wait for the TRMT to set, as you are doing, why then do you subsequently need to test the TXIF prior to sending the next byte?
SendW
movwf sendb
bsf PORTE,0 ; RE_DE_485 PORTE pin 0 hoog maken om RS485 te zenden
btfss PIR1,TXIF
goto $-2
rcall Delay50us
movff sendb,TXREG
nop
bsf PORTE,0 ; RE_DE_485 PORTE pin 0 hoog maken om RS485 te zenden
btfss TXSTA,TRMT
goto $-2
bcf PORTE,0 ; RE_DE_485 PORTE pin 0 laag maken om RS485 te ontvangen
rcall Delay50us
return |
|
|
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Tue Feb 19, 2008 3:19 am |
|
|
Hello Christophe,
Oke It seems that we found it....
Delay 50uS was just stupid....... I made a mistake.....
And the RE0 pin has a small pulldown resitor on the line..... The SN75176 was not always enabled.... Again I made the mistake.....
Right now it is working like I was expecting it......
Thanks for the help!!!!
Jody |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|