Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Jim Granville
03/31/16 23:39
  04/01/16 00:07

Read: 556 times

#190641 - Hmmm
Responding to: Charles Townsend's previous message
It's been a while since I tried Atmel firmware + AT Studio programmers, but I recall some version creep & lottery connect issues.

You are probably better to use TSim51 instead ?

For SPI ISP, the easiest 'blind start' is to use a Bootloader ROM device,
(any of AT89LP51Rx2 @ 22.1184MHz) and Assemble/download the code below, using ISP via BootLoader menu.

Then, it runs as SPI Bridge firmware, so you change the menu from ISP via BootLoader to ISP via SPI and you can ISP the AT89LP6440 etc.

; TSim51 ISPviaSPI_fwLP51B2.ASM derived from ISPviaSPI_C2051.asm  ISP programmer via SPI interface
; TSim51.b504     ~14.74MHz upper Sim speed 89LP51TB2, not Fast.
; TSim51.b600.DLL ~17.55MHz Sims on Terminal & Coms.
; TSim51.b650.DLL 89~100% of 22.1184MHz
; This code acts as a Serial <-> SPI bridge, to allow TSim51 Program of ALL Atmel AT89xx devices,
; with SPI ISP feature, using the ISP via SPI menu
; Suggested Target Firmware host device is AT89P51RB2-20PC, as the cheapest new variant with ROM BOOTLOADER.
; The ROM loader means you can use any Serial link to program this firmware HEX file into a AT89P51RB2-20PC
; and once the BOOT FUSE (BLJB) is flipped, this PGM (Serial<->SPI) bridge runs instead of the BOOT.
; (Holding PSEN low at RESET can still force ROM boot for re-flash firmware updates )
; All other fuses can be left in default (erased) state = [XtalOsc, /2, /12 Compat mode, 
;  ie Run ISP via Bootloader menu to first install this Firmware, and then you can run ISP via SPI menu

; Osc: 22.1184 MHz
; Serial: 115200,n,8,1   - fixed with /16/12  (or 57600 with 11.0592MHz xtal)
; Pins: P1.0 - Error led
;       P1.1 - Ready led
;       P1.3 - SS     ;
;       P1.4 - SCK    ;
;       P1.5 - MOSI   ;
;       P1.6 - MISO   ;
;       P1.7 - RESET  ;
; Resgister usage: R0 - FIFO input pointer
;                  R1 - FIFO output pointer
;                  R2 - Command length
;                  R4 - Bit counter
;                  R5 - SCK pulse width counter
;                  R6 - Command temporary storage
; Serial Command formats:  (used by TSim51 Studio,  View.ISPvaiSPI menu)
; Header: ':', CommandChar, Length
; Data: [Byte 0] .. [Byte (Length-1)]
; Commands: ':R'#2 [Data0] - RST (bit7), SCK (bit4) and CPOL (bit0) control
;                  [Data1] - SCK pulse width
;           ':S' [Length] [Data ...] - SPI command with SS release after end
;           ':s' [Length] [Data ...] - SPI command without SS release after end
; Data length: 1..77 bytes, so if the data is longer then the 's' command must be used,
;              prior to the last block.
;              The last block, and one block commands with 'S' to start.

$PAGING              ; Enable title header and paging (default, with width = 72)
$DATE ()             ; use today's date, and enable on Title
$PAGELENGTH (65535)  ; Similar to $NOPAGING, allows useful Title line: AsmVer $TITLE  Date
$PAGEWIDTH (118)     ; Tune to suit editor and included information. 118 trims here->|
                     ; 118 suits TSim51 @ 1024x768 screen
;$NOPAGING            ; totally removes title header, date, and paging, extends Page width 255

$TITLE ( ISP programmer via SPI ISPviaSPI_fwLP51B2 )
$NOMOD51          ; Use Generic 8051 resources

                bseg at 0000h
CPOL:           dbit    1
NCPOL:          dbit    1
OnTxReady:      dbit    1

                dseg at 0021h

Pulse:          ds      1
CmdChar:        ds      1

                dseg at 0030h
Header:         ds      3
Buffer:         ds      77

Baud            equ     -1                      ;115200 baud  22.1184M/12/16 = 115200
Stack           equ     07h

LEDRDY          equ     P1.1
LEDERR          equ     P1.0

PSS             equ     P1.3
PSCK            equ     P1.4
PMOSI           equ     P1.5
PMISO           equ     P1.6
PRST            equ     P1.7
Xtal1  EQU 22.1184e6
Xtal2  EQU 22.118456789123e6
XtalDiff EQU Xtal2-Xtal1

; ~~~~~~~~~~~~~~~~~~~~~~~~ RESET and INTERUPTS ~~~~~~~~~~~~~~~~~~~~~~
                cseg at 0000h                   ;Reset vector
                ajmp     Start

                cseg at 0023h

                ajmp     SerialInt

                cseg at 0040h

; ~~~~~~~~~~~~~~~~~~~~~~~~ Main Code ~~~~~~~~~~~~~~~~~~~~~~
Start:          mov     P1,#0FFh
                mov     P3,#0FFh
                mov     SP,#Stack
                mov     P0M0,A                  ;change to QuasiBiDirectional on Pn
                mov     P1M0,A 
                mov     P2M0,A 
                mov     P3M0,A

                setb    LEDERR                  ;no error
                clr     LEDRDY                  ;ready

                mov     TMOD,#00100001b         ;T0:mode 1, T1:mode2
                orl     PCON,#10000000b         ;SMOD = 1
                mov     SCON,#01000000b         ;Serial port: mode 1

                mov     TH1,#Baud               ;Set baud (115200 baud)
                mov     TL1,#Baud

                setb    TR1
                setb    REN
                setb    ES

                mov     R0,#Header
                mov     R1,#Header
                setb    OnTxReady

                setb    EA

Main:           cjne    R0,#Header,Main1
                sjmp    Main

Main1:          acall   GetChar
                acall   PutChar
                cjne    a,#':',Main

                acall   GetChar
                acall   PutChar
                mov     R6,a

                acall   GetChar
                acall   PutChar

                acall   Command

                clr     LEDRDY
                setb    LEDERR

                mov     R0,#Header
                mov     R1,#Header

                sjmp    Main

GetChar:        mov     a,R1
                clr     c
                subb    a,R0
                jnc     GetChar
                mov     a,@R1
                inc     R1

PutChar:        jnb     OnTxReady,$
                clr     OnTxReady
                mov     SBUF,a

Command:        cjne    R6,#'S',Cmd1
                sjmp    CmdSpi
Cmd1:           cjne    R6,#'R',Cmd2
                sjmp    CmdReset
Cmd2:           cjne    R6,#'s',Cmd3
                sjmp    CmdSpi
Cmd3:           ret

CmdReset:       acall    GetChar
                acall    PutChar

                mov     c,ACC.0
                mov     CPOL,c
                cpl     c
                mov     NCPOL,c

                xrl     a,#080h
                orl     a,#6Fh                  ;MOSI, MISO, SS high
                mov     P1,a

                acall    GetChar
                acall    PutChar
                mov     Pulse,a

CmdSpi:         clr     PSS
CmdSpiLoop:     mov     a,R1
                xrl     a,R2
                jz      CmdSpiExit
                acall    GetChar
                acall    SpiData
                acall    PutChar
                sjmp    CmdSpiLoop

CmdSpiExit:     mov     a,Header+1
                cjne    a,#'S',CmdSpiNoClose
                setb    PSS
CmdSpiNoClose:  clr     c

SpiData:        mov     R4,#8
                mov     R5,Pulse
                cjne    R5,#0,SpiSlow

SpiLoop:        mov     c,CPOL
                mov     PSCK,c
                mov     c,acc.7
                mov     PMOSI,c

                mov     c,NCPOL
                mov     PSCK,c

                mov     c,PMISO
                rlc     a

                djnz    R4,SpiLoop
                setb    PMOSI
                clr     PSCK


SpiSlow:        mov     c,CPOL
                mov     PSCK,c
                mov     c,acc.7
                mov     PMOSI,c

                mov     R5,Pulse
                djnz    R5,$

                mov     c,NCPOL
                mov     PSCK,c

                mov     R5,Pulse
                djnz    R5,$

                mov     c,PMISO
                rlc     a

                djnz    R4,SpiSlow
                setb    PMOSI
                clr     PSCK

; ~~~~~~~~~~~~~ Interrupt Code, Serial ~~~~~~~~~~~~~~~~~~~~~~~~~~
SerialInt:      push    acc
                push    psw
                jnb     RI,SerialIntTI
                clr     RI
                mov     @R0,SBUF
                cjne    R0,#Header,SerialInt1
                cjne    @R0,#':',SerialInt0
                setb    LEDRDY
                sjmp    SerialIntStore

SerialInt0:     clr     LEDERR
                clr     LEDRDY
                sjmp    SerialIntTI

SerialInt1:     cjne    R0,#Header+1,SerialInt5
                cjne    @R0,#'R',SerialInt2
                sjmp    SerialIntStore

SerialInt2:     cjne    @R0,#'S',SerialInt3
                sjmp    SerialIntStore

SerialInt3:     cjne    @R0,#'s',SerialInt4
                sjmp    SerialIntStore

SerialInt4:     mov     R0,#Header
                mov     R1,#Header
                sjmp    SerialIntTI

SerialInt5:     cjne    R0,#Header+2,SerialInt6
                mov     a,@R0
                add     a,#Buffer
                mov     R2,a
                sjmp    SerialIntStore

SerialInt6:     mov     a,R0
                jb      ACC.7,SerialInt4
                xrl     a,R2
                jz      SerialIntTI

SerialIntStore: inc     R0

SerialIntTI:    jnb     TI,SerialIntExit
                clr     TI
                setb    OnTxReady

SerialIntExit:  pop     psw
                pop     acc

                DB   "Firmware ISPviaSPI_fwLP51B2 v1.01 AT89LP51RB2"


;TASMC51 V1.1    ISP programmer via SPI ISPviaSPI_fwLP51B2                       PAGE 4
;        S E G M E N T   U S A G E
;        =========================
; Code    :   402 bytes of 24576

; Data    :    82 bytes of 128
; IData   :     0 bytes of 128
; EData   :     0 bytes of 2048
; FData   :     0 bytes of 0
; UData   :     0 bytes of 512
; XData   :     0 bytes of 65536
; Bit     :     3 bits  of 128


List of 4 messages in thread
AT89LP ISP Studio      CHARLES TOWNSEND      03/30/16 15:15      
   Hmmm      Jim Granville      03/31/16 23:39      
      thanks, it works      CHARLES TOWNSEND      04/01/16 13:29      
   this has been ages and ....      Erik Malund      04/01/16 06:57      

Back to Subject List