English 中文(简体)
Interfacing 45DB161 data flash with 89LP4052 controller
原标题:

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

问题回答

Bring out your oscope, look at the SPI bus (the clk signal and the DO from your controller). Your flash datasheet has a timing diagram that shows how the data should be clocked in and out (on the edge or at the mid-point of each clock cycle), on what edge, and where the bus should idle.

Then tweek the settings on your controller till what you see out of your controller matches what you see on your flash datasheet.

Finally, read the flash datasheet carefully, it probably has something like it expects data in 8 bit chunks or 24 bit chunks before the CS (chip select) pin is raised to end and latch in the data. Make sure you do that, only when your flash expects it.

Then, it will work. :-) good luck.

I had a similar symptom when I was coding for a similar Flash chip.

My problem was that there were other Chip Select lines to other chips (RTC, UART, etc) that I did not initialize, so they defaulted to low. The low Chip Select allows those chips to drive the MISO (master in, slave out) data line so that the microcontroller couldn t read anything.





相关问题
Steps to read data from ARM microcontroller port

I am having trouble reading serial data from ARM LPC2378 microcontroller. Will I have to use UART or any GPIO port can be used?? is ayone having c code for it??

high speed tracing

I have an embedded board with a 32 Micro-controller, and an custom built OS, Unfortunately, as of now, connection to the PC is only through serial port, Internal memory is limited to 512KB. There are ...

Affordable, programmable device with gprs and simple sensors?

I ve got quite a fun challenge / work assignment. I m to monitor a couple of 5V light bulbs (warning lights) on a machine standing far out in no man s land. I m looking for an affordable device with ...

Alarm history stack or queue?

I m trying to develop an alarm history structure to be stored in non-volatile flash memory. Flash memory has a limited number of write cycles so I need a way to add records to the structure without ...

LD linker: Target address aligning but not address in ROM

I have a program that s resident in flash and will run from flash. Early in the program data segments are copied from flash to ram. I m using a linker script like (simplified): .text : { *(....

clear code for counting from 0 to 255 using 8-bit datatype

I was wondering if there is a clean way of counting from 0 to 255 using an 8 bit datatype, something like: for(uint8_t i(0);i<=255;++i) { .... } This obviously will not work but it makes it ...

热门标签