AN2417 Freescale Semiconductor / Motorola, AN2417 Datasheet - Page 19

no-image

AN2417

Manufacturer Part Number
AN2417
Description
PCMCIA and Compact Flash Interface for the MC9328MX1 and MC9328MXL Application Processors Application Note
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Example Program to write 512 byte of data to a memory block at LBA Address 0x0000001
U8 tempU8;
U16 i;
//***Set sector count***
*(P_U8) (CS5_BASE_ADDR+0x400002) = 0x1;//sector count =1
//***Set the LBA address of memory block to be written***
*(P_U8) (CS5_BASE_ADDR+0x400003) = 0x1; //LBA [7:0] =1
*(P_U8) (CS5_BASE_ADDR+0x400004) = 0x0; //LBA [15:8:] =0
*(P_U8) (CS5_BASE_ADDR+0x400005) = 0x0; //LBA [23:16:] =0
*(P_U8) (CS5_BASE_ADDR+0x400006) = 0xE0; //LBA [27:24]=0 (lower 4 bit of register)
//Issue write command
*(P_U8) (CS5_BASE_ADDR+0x400007) = 0x30;//issue 30H command for sector write
//Poll for busy bit
tempU8 = *(P_U8) (CS5_BASE_ADDR+0x400007);
while ( tempU8&0x80) {//poll for busy bit (bit 7 of register), quit loop when busy bit =0
}
//Write data to data buffer until DRQ is clear
for (i=0;(tempU8&0x08)==0x08;i++) {
}
printf("Finish Writing\n");
3.5.3 Read from Memory Block
To read back from a memory block, the following sequence is required:
1, Write the number of block of data to be access to the sector count register
2, Write the LBA Address to the card
3, Issue 20H command
When this command is accepted, the Compact Flash Memory Card set BSY, then sets DRQ, put the sector
of data in buffer and clear BSY, then wait for the host to read the sector data from buffer. DRQ will be
clear when 512 bytes of data is read.
Example Program to read 512 byte of data to a memory block at LBA Address 0x0000001
U8 tempU8;
U16 i, U16data[256];
//Set sector count
MOTOROLA
tempU8 = *(P_U8) (CS5_BASE_ADDR+0x400007);
*(P_U16) (CS5_BASE_ADDR+0x400008)=(0xAA00+i);// write 2 byte of data to data buffer
tempU8=*(P_U8) (CS5_BASE_ADDR+0x400007);// poll for DRQ (bit 3 of register)
Freescale Semiconductor, Inc.
For More Information On This Product,
MC9328MX1/MXL Application Note
Engineering Draft / Preliminary
Go to: www.freescale.com
Programming Example
19

Related parts for AN2417