I am trying to interface the data flash with 89lp 4052 controller. Crysal used 11.0592 mhz. This controller has built in spi bus. I tried all combinations of CPHA AND CPOL. Tried mode 0 as well as mode 3. Not able to read staus register. Some times it happens that it reads the register but sometimes it just ff code out from flash.
my code is as follows.
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 ;SELECTED AGAIN
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 ;SELECTED AGAIN
MOV 20H,#0D4H
LCALL SEND_CLOCK
MOV 20H,#00H
LCALL SEND_CLOCK
MOV 20H,#00H
LCALL SEND_CLOCK
MOV 20H,#00H
LCALL SEND_CLOCK
MOV 20H,#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_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 ;;===========================================================
END