How to use the CF card? Is there a library?

Hi,

I saw that some people were able to use a SPI display and a SD card (SPI too), so that data from the SD card is sent directly to the display, without the need for the microcontroller to work with this data. The microcontroller only works with data access and pulse clock to synchronize the SD card and the display.

Considering a display with parallel bus, with controller SSD1963 (16 bits of data bus). I believe it would be possible to use a CF card (compact flash) which also has 16 bits of data bus. To transfer data directly from the CF card to the display. This could save a lot of unnecessary operation for displaying images, thus reducing the loading time of the image.

I would like to experiment with Arduino Mega or DUE.

Could anyone suggest a library for read access to a CF card?
Or do you know if it would be possible to adapt the SD card library to operate with the CF card?

Thank you.


rtek1000:
I saw that some people were able to use a SPI display and a SD card (SPI too), so that data from the SD card is sent directly to the display, without the need for the microcontroller to work with this data. The microcontroller only works with data access and pulse clock to synchronize the SD card and the display.

Please link to that! Never saw that, would be cool :slight_smile:

CF is based on the PCMCIA (People Can't Memorize Computer Industry Acronyms) standard. That's basically an extension of the PC motherboard bus. Simulating that with an Arduino is likely impossible. Even a Pentuim can't do it on its own: it requires a "chipset" of helper chips to run the motherboard bus.

Even SD direct to display seems unlikely. You need MOSI commands to go to both devices (select a file and select a place on the screen to write the image) then switch the SD card's MISO to go to the display MOSI.

It’ll be an intelligent display that takes simple commands to load pages from the SD (like Nextion).

Usually templates which you then populate from your program.

There may be auto-load to get the splash screen etc.

septillion:
Please link to that! Never saw that, would be cool :slight_smile:

Hi, please see it:

MorganS:
CF is based on the PCMCIA (People Can't Memorize Computer Industry Acronyms) standard. That's basically an extension of the PC motherboard bus. Simulating that with an Arduino is likely impossible. Even a Pentuim can't do it on its own: it requires a "chipset" of helper chips to run the motherboard bus.

Even SD direct to display seems unlikely. You need MOSI commands to go to both devices (select a file and select a place on the screen to write the image) then switch the SD card's MISO to go to the display MOSI.

Hi, I am not convinced of this, it seems that the CF card can operate in 3 different modes.

lastchancename:
It’ll be an intelligent display that takes simple commands to load pages from the SD (like Nextion).

Usually templates which you then populate from your program.

There may be auto-load to get the splash screen etc.

Hi,

That's exactly what I want to avoid. This display ("Nextion") is expensive. Many applications do not need an FPGA and sliding effects etc.

The CompactFlash Storage Card functions in three basic modes: 1) PC Card ATA using I/O
Mode, 2) PC Card ATA using Memory Mode and 3) True IDE Mode, which is compatible with
most disk drives.

http://rumkin.com/reference/aquapad/media/cfspc3_0.pdf

I'm not convinced either. A CF card can operate just like an IDE drive by using a $2 CF<>IDE adapter and I ran a laptop on an 8Gb CF card out of a camera for years. I have never looked, but there is surely some discussion on using IDE drive with Arduino in the Storage Forum.

Nice reference.

A quick read of the section on the electrical interface looks like almost all of the 50 pins on the card are used. Depending on the mode, you can ignore some of the 12 address lines OR some of the 16 data lines but not both.

An Arduino Mega would be totally occupied driving that interface.

I have found this:

:o

rtek1000:
I have found this:

https://www.mikroe.com/compact-flash-board

Nice one. Only 16 pins plus power and data. The "manual" is a bit thin. No clues on how you would access the data on the card. I guess you just have to read the big specification.

It seems like it's not so complicated,

********************************
* COMPACT FLASH TEST PROGRAM
* FOR MC3
* DANIEL TUFVESSON 2013
********************************

********************************
* MONITOR LABLES
********************************
RETURN EQU $C000 RETURN TO PROMPT
OUTCHAR EQU $C003 OUTPUT CHAR ON CONSOLE
INCHAR EQU $C006 INPUT CHAR FROM CONSOLE AND ECHO
PDATA EQU $C009 PRINT TEXT STRING @ X ENDED BY $04
OUT2HS EQU $C012 PRINT 2 HEX CHARS @ X
OUT4HS EQU $C015 PRINT 4 HEX CHARS @ X
INBYTE EQU $C01B INPUT 1 BYTE TO A. CARRY SET = OK

CONSVEC EQU $7FE5 CONSOLE STATUS VECTOR
CONOVEC EQU $7FE8 CONSOLE OUTPUT VECTOR
CONIVEC EQU $7FEB CONSOLE INPUT VECTOR
 
********************************
* CF REGS
********************************
CFBASE EQU $8060
CFREG0 EQU CFBASE+0 DATA PORT
CFREG1 EQU CFBASE+1 READ: ERROR CODE, WRITE: FEATURE
CFREG2 EQU CFBASE+2 NUMBER OF SECTORS TO TRANSFER
CFREG3 EQU CFBASE+3 SECTOR ADDRESS LBA 0 [0:7]
CFREG4 EQU CFBASE+4 SECTOR ADDRESS LBA 1 [8:15]
CFREG5 EQU CFBASE+5 SECTOR ADDRESS LBA 2 [16:23]
CFREG6 EQU CFBASE+6 SECTOR ADDRESS LBA 3 [24:27 (LSB)]
CFREG7 EQU CFBASE+7 READ: STATUS, WRITE: COMMAND

********************************
* START OF PROGRAM
********************************
 ORG $0100
 JMP START
TCRLF FCB $0D,$0A,$04
TSISER FCC "  Serial: "
 FCB $04
TSIFW FCC "Firmware: "
 FCB $04
TSIMOD FCC "   Model: "
 FCB $04
TSILBA FCC "LBA size: "
 FCB $04
TPROMPT FCB $0D,$0A
 FCC "# "
 FCB $04
CFLBA3 RMB 1
CFLBA2 RMB 1
CFLBA1 RMB 1
CFLBA0 RMB 1
 ORG *


START LDX #TCRLF
 JSR PDATA
 LDAA #$80 SELECT I/O PAGE 0
 STAA $0002
 CLR CFLBA3
 CLR CFLBA2
 CLR CFLBA1
 CLR CFLBA0
 JSR CFINIT
 JSR CFINFO
PROMPT LDX #TPROMPT
 JSR PDATA
 JSR INCHAR
 ANDA #$DF TO UPPER CASE
 CMPA #'Q
 BNE *+5
 JMP RETURN
 CMPA #'I
 BNE *+5
 JMP MENU_I
 CMPA #'R
 BNE *+5
 JMP MENU_R
 LDAA #'?
 JSR OUTCHAR
 BRA PROMPT

* MENU "I" - PRINT CF INFO
MENU_I LDX #TCRLF
 JSR PDATA
 JSR CFINFO
 JMP PROMPT

* MENU "R" - READ SECTOR
MENU_R LDAA #$20
 JSR OUTCHAR
 JSR INBYTE
 BCC MENU_RE
 STAA CFLBA3
 JSR INBYTE
 BCC MENU_RE
 STAA CFLBA2
 JSR INBYTE
 BCC MENU_RE
 STAA CFLBA1
 JSR INBYTE
 BCC MENU_RE
 STAA CFLBA0
 JSR CFSLBA SET LBA
 LDAA #$01
 STAA CFREG2 READ ONE SECTOR
 JSR CFWAIT
 LDAA #$20 READ SECTOR COMMAND
 STAA CFREG7
 LDX #BLKDAT
 JSR CFREAD
 JSR CFCHERR
MENU_RE JMP PROMPT

********************************
* INITIALIZE CF
********************************
CFINIT LDAA #$04 RESET COMMAND
 STAA CFREG7
 JSR CFWAIT
 LDAA #$E0 LBA3=0, MASTER, MODE=LBA
 STAA CFREG6
 LDAA #$01 8-BIT TRANSFERS
 STAA CFREG1
 LDAA #$EF SET FEATURE COMMAND
 STAA CFREG7
 JSR CFWAIT
 JSR CFCHERR
 RTS

********************************
* WAIT FOR CF READY
********************************
CFWAIT LDAA CFREG7
 ANDA #$80 MASK OUT BUSY FLAG
 CMPA #$00
 BNE CFWAIT
 RTS

********************************
* CHECK FOR CF ERROR
********************************
CFCHERR LDAA CFREG7
 ANDA #$01 MASK OUT ERROR BIT
 CMPA #0
 BEQ CFNERR
 LDAA #'!
 JSR OUTCHAR
 LDX CFREG1
 JSR OUT2HS
CFNERR RTS

********************************
* READ DATA FROM CF
********************************
CFREAD JSR CFWAIT
 LDAA CFREG7
 ANDA #%00001000 FILTER OUT DRQ
 CMPA #%00001000
 BNE CFREADE
 LDAA CFREG0 READ DATA BYTE
 STAA ,X
 INX
 BRA CFREAD
CFREADE RTS

********************************
* CF SET LBA
********************************
CFSLBA LDAA CFLBA0 LBA 0
 STAA CFREG3
 LDAA CFLBA1 LBA 1
 STAA CFREG4
 LDAA CFLBA2 LBA 2
 STAA CFREG5 
 LDAA CFLBA3 LBA 3
 ANDA #%00001111 FILTER OUT LBA BITS
 ORAA #%11100000 MODE LBA, MASTER DEV
 STAA CFREG6
 RTS

********************************
* PRINT CF INFORMATION
********************************
CFINFO JSR CFWAIT
 LDAA #$EC DRIVE ID COMMAND
 STAA CFREG7
 LDX #BLKDAT
 JSR CFREAD
 LDX #TCRLF
 JSR PDATA

* PRINT SERIAL
 LDX #TSISER
 JSR PDATA
 LDX #BLKDAT+20
 LDAB #20
 JSR PRTRSN
 LDX #TCRLF
 JSR PDATA

* PRINT FIRMWARE REV
 LDX #TSIFW
 JSR PDATA
 LDX #BLKDAT+46
 LDAB #8
 JSR PRTRN
 LDX #TCRLF
 JSR PDATA

* PRINT MODEL NUMBER
 LDX #TSIMOD
 JSR PDATA
 LDX #BLKDAT+54
 LDAB #40
 JSR PRTRN
 LDX #TCRLF
 JSR PDATA

* PRINT LBA SIZE
 LDX #TSILBA
 JSR PDATA
 LDX #BLKDAT+123
 JSR OUT2HS
 DEX
 DEX
 JSR OUT2HS
 DEX
 DEX
 JSR OUT2HS
 DEX
 DEX
 JSR OUT2HS
 LDX #TCRLF
 JSR PDATA

 RTS

********************************
* PRINT BIG ENDIAN STRING OF N CHARS
* IN: X=ADDR, B=NCHARS
********************************
PRTRN LDAA 1,X
 JSR OUTCHAR
 LDAA 0,X
 JSR OUTCHAR
 DECB
 CMPB #0
 BEQ PRTRNE
 DECB
 CMPB #0
 BEQ PRTRNE
 INX
 INX
 BRA PRTRN
PRTRNE RTS

********************************
* PRINT BIG ENDIAN STRING OF N CHARS
* SKIPPING ALL SPACES
* IN: X=ADDR, B=NCHARS
********************************
PRTRSN LDAA 1,X
 CMPA #$20
 BEQ PRTRSN1
 JSR OUTCHAR
PRTRSN1 LDAA 0,X
 CMPA #$20
 BEQ PRTRSN2
 JSR OUTCHAR
PRTRSN2 DECB
 CMPB #0
 BEQ PRTRSNE
 DECB
 CMPB #0
 BEQ PRTRSNE
 INX
 INX
 BRA PRTRSN
PRTRSNE RTS

********************************
* STORAGE FOR SECTOR TRANSFER
********************************
 ORG $1000
BLKDAT RMB 512

I'll see if I have time to play around with this.

:grinning:

IDE Arduino Mega
1 /RESET 22 PA0
2 GND GND
3 D7 42 PL7
4 D8 37 PC0
5 D6 43 PL6
6 D9 36 PC1
7 D5 44 PL5
8 D10 35 PC2
9 D4 45 PL4
10 D11 34 PC3
11 D3 46 PL3
12 D12 33 PC4
13 D2 47 PL2
14 D13 32 PC5
15 D1 48 PL1
16 D14 31 PC6
17 D0 49 PL0
18 D15 30 PC7
19 GND GND
22 GND GND
23 /WR 23 PA1
24 GND GND
25 /RD 24 PA2
26 GND GND
30 GND GND
33 A1 26 PA4
35 A0 25 PA3
36 A2 27 PA5
37 /CS0 28 PA6
38 /CS1 29 PA7

IDEFat Library for IDE Hard Drive and Mega

Reply #11 is what I was talking about. If Arduino can handle an IDE drive, it can handle that. That adapter plus CF card is a drop-in replacement.

Nick_Pyner:
Reply #11 is what I was talking about. If Arduino can handle an IDE drive, it can handle that. That adapter plus CF card is a drop-in replacement.

Nice!