我正在尝试将数据闪存与 89lp 4052 控制器连接。水晶使用 11.0592 兆赫。该控制器内置 spi 总线。我尝试了 CPHA 和 CPOL 的所有组合。尝试了模式 0 和模式 3。无法读取状态寄存器。有时它会读取寄存器,但有时它只是从闪存中取出代码。
我的代码如下。
CLR SCLK
CLR CS
LCALL DELAY2
;;================================================== ===============================
WRITE_FLASH: MOV 20H,#0D7H ;COMMAND LCALL SEND_CLOCK_ONE LCALL READ_FLASH CLR SCON.1 MOV A,21H MOV SBUF,A JNB SCON.1,$ CLR SCON.1 ;;============= ==================================================== ======== SETB CS CLR SCLK LCALL DELAY2 CLR CS ; 再次选择 MOV 20H,#84H LCALL SEND_CLOCK MOV 20H,#00H LCALL SEND_CLOCK
MOV 20H,#00H LCALL SEND_CLOCK
MOV 20H,#00H LCALL SEND_CLOCK
MOV 20H,#33H LCALL SEND_CLOCK LCALL DELAY2 SETB CS LCALL DELAY2 CLR SCLK CLR CS ;再次选择 MOV 20H,#0D4H LCALL SEND_CLOCK
MOV 20H,#00H LCALL SEND_CLOCK
MOV 20H,#00H LCALL SEND_CLOCK
MOV 20H,#00H LCALL
SEND_C ,#00H LCALL SEND_CLOCK_ONE
LCALL READ_FLASH
CLR SCON.1
MOV A,21H
MOV SBUF,A
JNB SCON.1,$
CLR SCON.1
SETB CS
SETB SCLK
LCALL DELAY2
LJMP REP
;;================================================== ======================= SEND_CLOCK_ONE: MOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C, 05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SEND
MOV C,00H MOV DOUT,C LCALL PULSE_SEND_LAST RET ;;===================================== ======================================= READ_FLASH: LCALL PULSE_SEND MOV C,DIN MOV 0FH,C LCALL PULSE_SEND MOV C,DIN MOV 0EH,C LCALL PULSE_SEND MOV C,DIN MOV 0DH,C LCALL PULSE_SEND MOV C,DIN MOV 0CH,C LCALL PULSE_SEND MOV C,DIN MOV 0BH,C LCALL PULSE_SEND MOV C,DIN MOV 0AH,C LCALL PULSE_SEND MOV C,DIN MOV 09H,C LCALL PULSE_SEND MOV C,DIN MOV 08H,C LCALL PULSE_SEND RET ;;================================== ====================================== SEND_CLOCK: MOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C,05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDDIN MOV 08H,C LCALL PULSE_SEND RET ;;======================================== ================================ SEND_CLOCK: MOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C,05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDDIN MOV 08H,C LCALL PULSE_SEND RET ;;======================================== ================================ SEND_CLOCK: MOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C,05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDC LCALL PULSE_SEND RET ;;============================================= =========================== SEND_CLOCK: MOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C,05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDC LCALL PULSE_SEND RET ;;============================================= =========================== SEND_CLOCK: MOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C,05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDMOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C,05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDMOV C,07H ;MSB MOV DOUT,C LCALL PULSE_SEND MOV C,06H MOV DOUT,C LCALL PULSE_SEND MOV C,05H MOV DOUT,C LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDC LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SENDC LCALL PULSE_SEND MOV C,04H MOV DOUT,C LCALL PULSE_SEND MOV C,03H MOV DOUT,C LCALL PULSE_SEND MOV C,02H MOV DOUT,C LCALL PULSE_SEND MOV C,01H MOV DOUT,C LCALL PULSE_SEND
MOV C,00H MOV DOUT,C LCALL PULSE_SEND RET
;;================================================== =========================== DELAY2: mov 56H,#0FFH DJNZ 56H,$ mov 56H,#0FFH DJNZ 56H,$ RET ;; ==================================================== ================= PULSE_SEND: SETB SCLK LCALL DELAY2 CLR SCLK LCALL DELAY2 RET ;;==================== ================================ PULSE_SEND_LAST: SETB SCLK LCALL DELAY2 RET ;;========== ============================================ PULSE_READ_FIRST:CLR SCLK LCALL DELAY2 SETB SCLK LCALL DELAY2 RET ;;============================================= ================
结尾