??? 12/23/05 17:43 Read: times |
#105837 - SPI ISP |
I have been trying to make a program to program a ISP chip (AT89S52) over SPI interface. I made a few routines for testing on the ELEKTOR board with PAULMON. the responce from the target chip is always FF. even though i can program the target chip using my usual parallel port ISP programmer. could someone please help me out. the program listing is in bascom51 demo version. PC interface is simply a terminal emulator
the SPI write (SHOUT) and read (SHIN) routines were taken from the ATmel's application note for programming AT89s8252, i have modified the routines to acomodate the four byte programming instruction set of the AT89S52. still i am not able to find whats wrong. The new notebooks that the students got this semester in my department doesnot have any parallel port. and here we do not get a USB to parallel port convertor that easily ( I couldnt find one locally). So i searched and searched for a SPI programmer for ATMEL's AT89S52 using the serial port. but to no avail, all the serial port programmers catered to AT89S8252/53. Now one choice would be to get phillips or dallas chips with internal bootloader. but the thing is that our inventory is filled with ATMEL's AT89S52. and we are stuck with it. so i thought of making a serial port ISP programmer using a AT89C2051. for that i made some programs but to no avail. 'SPI ISP PRG Ver 1.0 'SPI ISP PROGRAMMER FOR AT89S51/52 'demo program only if getready,read and $crystal = 11059200 $noinit 'for elekor board $romstart=&H2000 $baud = 9600 'SOFT SPI PIN CONFIGURATION Mosi Alias P1.4 Miso Alias P1.3 Sck Alias P1.5 Rst Alias P1.7 'DECLARE SUBROUTINE Declare Sub Writebyte Declare Sub Readbyte Declare Sub Erasechip Declare Sub Shout Declare Sub Shin Declare Sub Rdy 'VARIALBLE ASSINGMENT Dim K As Byte Waitms 500 'FOR THE ELEKTOR BOARD WITH PAULMON 'INITIALISATION OF SPI PINS Init: setb MISO setb MOSI clr SCK clr RST Main: print "AT89S52 ISP SPI programmer Ver 1.0" Print "COMMANDS: G(etREADY), W(RITE),R(EAD),E(RASE)" K: K = Waitkey() If K = "G" Then Rdy Else Goto L 'put board into programming mode Goto K L: If K = "W" Then Writebyte Else Goto M 'writing one byte at the required address Goto K M: If K = "R" Then Readbyte Else Goto N 'read one byte from the iven address Goto K N: If K = "E" Then Erasechip Else Goto O 'erase chip Goto K O: If K = "Q" Then Goto Quit Else Goto P 'quit and go back to monitor Goto K P: Print "INVALID COMMAND" Goto K Quit: LJMP 00 'SERIAL PROGRAMMING ENABLE Sub Rdy() Print "Enabling Programming" Set Rst MOV A,#&HAC 'PGMEN COMMAND BYTE1 Shout MOV A,#&H53 'PGMEN COMMAND BYTE2 Shout MOV A,#&H55 'PGMEN COMMAND BYTE3 Shout Shout Shin 'OUTPUT SHOULD BE &H69 Printhex Acc Print "Programming enabled" Reset Rst End Sub 'READING A BYTE FROM MEMORY Sub Readbyte() Print "Reading a byte from 0000" Set Rst MOV A,#&H20 'READBYTE COMMAND BYTE1 Shout MOV A,#&H00 'ADDRESS MSB Shout MOV A,#&H00 'ADDRESS LSB Shout Shin 'OUTPUT SHOULD BE DATA AT MEMORY LOCATION 00FF Reset Rst Printhex Acc Print " Read Complete" End Sub 'READING SIGNATURE BYTE Sub Readsign() Print " reading signatue byte" Set Rst MOV A,#&H28 'READ SIGN BYTE COMMAND BYTE1 Shout MOV A,#&H00 'READ SIGN BYTE COMMAND BYTE2 Shout MOV A,#&HFF 'READ SIGN BYTE COMMAND BYTE3 Shout Shin 'OUTPUT SHOULD BE THE SIGNATURE BYTE AT 00 Reset Rst Printhex Acc Print " Read Sign Complete" End Sub 'ERASING THE CHIP Sub Erasechip() Print " Erasing Chip" Set Rst MOV A,#&HAC 'ERASE COMMAND BYTE1 Shout MOV A,#&H80 'ERASE COMMAND BYTE2 Shout MOV A,#&HFF 'ERASE COMMAND BYTE3 Shout MOV A,#&HFF 'ERASE COMMAND BYTE4 Shout Reset Rst Print " Chip Erased" End Sub 'PROGRAMMING THE CHIP IN BYTE MODE Sub Writebyte() Print " Programming a byte at 0000H" Set Rst MOV A,#&H40 'PROGRAM CHIP COMMAND BYTE1 Shout MOV A,#&H00 'ADDRESS MSB Shout MOV A,#&H00 'ADDRESS LSB Shout MOV A,#&H25 'DATA TO BE PROGRAMMED Shout Reset Rst Print " programmed 25H at 0000H" End Sub Sub Shout() 'Shift out a byte, most significant bit first. 'SCK expected low on entry. Return with SCK low. 'Called with data to send in A. push b mov b, #8 ' bit counter X42: rlc a ' move bit into CY mov MOSI, c ' output bit nop ' enforce data setup nop ' setb SCK ' raise clock nop ' enforce SCK high nop ' nop ' nop ' clr SCK ' drop clock djnz b, .x42 ' next bit pop b End Sub Sub Shin() 'Shift in a byte, most significant bit first. 'SCK expected low on entry. Return with SCK low. 'Returns received data byte in A. push b mov b, #8 ' bit counter X43: setb SCK ' raise clock mov c, MISO ' input bit rlc a ' move bit into byte nop ' enforce SCK high nop ' clr SCK ' drop clock nop ' enforce SCK low nop ' djnz b, .x43 ' next bit pop b End Sub 'LOW LEVEL ASM ROUTINES TO SEND A BYTE OVER SPI Sub Sendspi() CLR SCK MOV B,#8 ;Set bit count. Loop1: RRC A ;Send one data bit. MOV MOSI,C ;Put data bit on pin. SETB SCK NOP NOP CLR SCK NOP DJNZ B,.Loop1 ;Repeat until all bits sent. CLR MOSI ;Release data line for acknowledge. End Sub 'LOW LEVEL ASM ROUTINE TO READ A BYTE OVER SPI Sub Readspi() MOV B,#8 ;Set bit count. Rbloop: SETB SCK NOP NOP MOV C,MISO ;Get data bit from pin. RLC A ;Rotate bit into result byte. CLR SCK NOP DJNZ B,.RBLoop ;Repeat until all bits received. End Sub End |
Topic | Author | Date |
SPI ISP | 01/01/70 00:00 | |
reset | 01/01/70 00:00 | |
reset should be on all the time? | 01/01/70 00:00 | |
Assert reset while programming | 01/01/70 00:00 | |
thanks jan | 01/01/70 00:00 | |
welcome | 01/01/70 00:00 | |
yeah sure![]() | 01/01/70 00:00 |