??? 05/01/07 13:18 Read: times |
#138383 - Serial flash problem |
Hi!
I am a Hong Kong student. This is my first time to write 8051 code and post topic here(My english is not very good,please don't blame me...) I am doing a project on 8051(89c55)which need to interface a serial flash(AT45DB041B). I had read all material (AT45DB041B datasheet,and something about SPI). I follow the procedure which is written in the datasheet. But I am still not able to solve the problem.I cant write anything in the flash... Here is my code org 0000h si equ p1.1 sck equ p1.2 cs equ p1.3 so equ p1.4 wp equ p1.5 clr si clr so clr sck start: setb wp clr cs ;enable the flash mov r0,#46H ;the data i want to write in the flash ;================================ mov r5,#78D ;time delay to allow the flash warm up l2: mov r7,#00H l1: nop djnz r7, l1 djnz r5, l2 ;=======write process============ acall c_write acall command ;clock the 8 bits into the flash acall rev_addr acall command mov a,#00h ;choose page 0 acall command mov a,#00h ;start from 00 in page 0 acall command mov a,r0 acall command setb cs ;terminate the operation nop ;=======read process=============== clr cs acall c_read acall command acall rev_addr acall command mov a,#00h ;choose page 0 acall command mov a,#00h ;start from 00 in page 0 acall command acall dont_care ;32 dont care bits,whcih is needed for read command acall recieve ;to recieve the 8 bit and store in a setb cs mov r1,a ;store the final result in r1 jmp start c_read: ;read the main memory directly mov a,#0D2H ;opcode ret c_write: ;write main memory page through buffer mov a,#82h ret rev_addr: ;4 reserved bit and 4 bit addr,i make it all 0 mov a,#00h ret command: ;input the command to the flash mov r6,#8 again: rlc a mov si,c ;send the bit setb sck ;give a sck to memory to recieve signal clr sck djnz r6,again ret recieve: ;recieve the data mov r6,#8 again1: setb sck clr sck ;give a sck to memory to recieve signal mov c, so rlc a djnz r6,again1 ret dont_care: mov a,#00h mov r6,#32 again2: rlc a mov si,c setb sck clr sck djnz r6,again2 ret end I think the problem may be due to the clock input to the flash.But i still dont know which part is going wrong. I had try many methods but it is still not work.I know the problem i asked is little bit long and confusing.Since i respond this part of the project,i really want to finish it... If anyone have any comments, please feel free to say. I deeply appreciate that! |
Topic | Author | Date |
Serial flash problem | 01/01/70 00:00 | |
have you checked the timing | 01/01/70 00:00 | |
The datasheet says...![]() | 01/01/70 00:00 |