This little editing can write data to a SD card slot and read them again, all from the USB port of a PC. Let's see how this product was developed in terms of hardware and software, through the implementation of a microcontroller with a Universal Serial Bus.
Lately, there are commercially available as standalone devices or provided with digital cameras, devices read / write on sdcard to USB or, more rarely, 1394. As it is economic apparatus, we propose a self that you will return the same price as a commercial purchase, but will give you the satisfaction of an introduction to this sophisticated technology.
Our achievement
This article offers indeed the wiring diagram and the practical realization of such a reader / writer data on SD card for USB read it because it is a good opportunity to experiment theoretical concepts of the SD card (and you must begin to know because we have already published many fixtures using a DS as data memory). Our goal this time is to make a small circuit that allows to write and read blocks of a DS using a USB interface. The final result was achieved through the implementation of a PIC18F2550, surrounded by a few components coomplémentaires, but with an outstanding resident program. Not to mention the program in Delphi running on the PC. This is, again, an experiment ... but whose educational opportunities are numerous changes since a side we integrate a PIC with a huge memory and the other we interfaçons with a system of rapid and efficient as the USB.
It will be a useful and exciting to catch fast everything we have previously acquired in theory, or even to learn some very concrete way just what a DS can do.
The wiring diagram
The circuit in Figure 1 which shows the wiring diagram is decidedly simple! The only problem we encountered was the implementation of a system that can manage best communicate with the PIC: it works, we know, with signals in 0 / 5 V, while the DS requires voltages between 0 and 3.6 V. We resolved again (this problem is not new in fact) so very elegant: for lines from the PIC to the card using a Schottky diode and a resistance to draw.
Thus, when the microcontroller to the SD shows the logical one, the diode is blocked and the voltage on the pin card is due to the pull-up resistor, 3.3 V (even if the PIC provides 5 V) . When the microphone generates a logic low, the LED leads, bringing about zero volts also pin the map. Regarding the connection in the opposite direction, from SD to the PIC, the thing is slightly different: to make the simple translation of logic levels while remaining efficient and accurate, we used a buffer / line driver ( ATPL / buffer) HCT technology, it is a very economical integrated circuit but totally effective.
We used the most current version, the 74HCT125; to enable the outputs, four pins OE1 to OE4 (Output Enable) are used: the input signal is output when the line OE is at logic zero. Since we want the transition to S E happen as quickly as possible, we linked the OE pin directly to ground. Therefore, each pilot line is still active. Input lines are fully compatible with the signals from the SD card because the integrated circuits based on logic ACT / HCT accept entries in levels below the TTL (0/3V example) and present output levels 0 / 5 V when powered with 5 V, they "see" a level of 3 V as if it were a normal 5 V TTL and 5 V supply output, ideal for controlling voltage input lines directly the PIC18F2550. The supply voltage for the PIC is taken directly from the USB port (note that this standard provides for the supply of 5 V 500 mA to connected devices). The regulator LM1086-CT-3.3, from the 5 V, generates a voltage of 3.3 V, sufficient to operate the DS.
To highlight the operations that the microphone should be done, we have endowed the plate three LEDs of different colors: yellow indicates that the circuit is powered, the red one is reading or writing is in progress and the green and the player is ready to develop a command sent by the host. If both LEDs Red and green are lit together is an error condition was detected and a data transfer to or from the SD occurred (the "reset" the system must therefore take place).
You've probably noticed that no temporary memory FRAM or EEPROM is present in the circuit, because we use the U.S. speed bus (Universal Serial Bus) to send directly to the host values read from the card as well, while writing, we are ensuring that the host sends directly to the SD data we want to register. The universality of this serial bus (Universal Serial Bus) allows us to avoid burdening the system with an additional component.
In addition, to make the system effective enough, we should use a "buffer" fast as a conventional EEPROM each byte requires a pause of 10 ms stabilization. The read / write data on SD can be done in blocks of at least 512 bytes: thus for each transaction read / write the PIC awaits the arrival of the 512 bytes, with which it forms a package that sequentially sends the DS (which creates thus a direct interface between the SPI bus and the USB bus. Communication with the DS is in SPI mode, using two serial data lines (one input and one output) synchronized by a clock signal and a line of chip select useful in cases where the we connect multiple cards at the same time, to indicate which one wants to communicate.
Figure 1: Diagram of the player / recorder data on SD-Card with USB.
Figure 2: Diagram of component layout of the player / recorder data on SD-Card with USB.
Figure 2b: Drawing scale 1, the PCB of the reader / writer data on SD-Card with USB.
Figure 3: Photograph of a prototype of the reader / writer with USB data SDCard.
Iist
R1 ...... R2 4.7 k
...... 4.7 k R3
...... 4.7 k R4
...... 1.5 k
R5 ...... 1 k
R6 ...... R7 1 k
...... 1 k
C1 ...... 15 pF ceramic
C2 ...... 15 pF ceramic
C3 ...... 100 nF multilayer
C4 ...... 220 uF 25 V electrolytic C5
...... 100 nF multilayer
...... C6 220 uF 25 V electrolytic
...... C7 220 nF multilayer
D1 ...... D2 BAT85
...... BAT85 D3
...... BAT85
LD1 ..... LED 3 mm green
LD2 ..... LED 3 mm red
LD3 ..... LED 3 mm yellow
U1 ...... PIC18F2550-ET611
U2 ...... LM1086-3.3 U3
...... 74HC125
Q1 ...... 20 MHz quartz
SD1 ..... SD card reader
Miscellaneous:
a support 2 x 14 1
support 2 x 7
1 USB-B
Unless otherwise specified, all resistors are 1 / 4 W 5%.
The TSR
The complexity of this project comes not from the hardware, but the resident program and "front-end written in Delphi. For the resident program, we used PICBASIC to make the simplest explanation that we owe you! If you followed a course in PicBasic, it will seem very simplistic and will be a year you can put into practice the theory learned.
begin by analyzing the most remarkable parts of the device or the file SDUSBdsc.asm. For those who have no idea what a descriptor, it should be noted that the PIC18F2550 is recognized by the PC as a device HID (Human Interface Device) and that in order to communicate properly with the interface USB it is necessary that the computer recognizes it as such. The descriptor is a structure providing the host with any background information on the device and its operating modes.
recall that indeed, on the USB bus, it's always the computer control.
Moreover, the descriptor defines what and how many ports are used for communication (the famous "end-points"): it is therefore essential that the software can send data to the PIC and to receive him.
In the "Listing" 1 we see the most important points: we set the size (in bytes) of the "buffer" for the Endpoint0 (for low speed devices the only value is 8), the dimension of the array ("array") keeping track of alternative configurations of each interface (remember that a device can have multiple interfaces, each with different configurations or "settings", that the host can select), the maximum number of "end-points used in the project (one and only one does not take into account the Endpoint0), the number of configurations and interfaces the device, the method for managing buffers associated with each "end point", the configuration register UCFG (USB Configuration Register) and the membership class of the device (HID).
In particular, as regards the register UCFG, we decided to use the transponder chip and the internal configuration of type "Low-Speed (slow speed). In the table defining the parameters of the class, we have clarified the use of Endpoint1 IN / OUT, with a "buffer" to 8 bytes ("Listing" 2). In the interface descriptor
we specify the number of "end-points used (not counting the Endpoint0 because it is the service). In addition, we use two communication ports, one output and the other input (the "Listing" 3).
In the descriptor of "end-points" (the "Listing" 4) we determine that the issue will have a length of 8 bits (1 byte) and received 5 bytes. Indeed, we found that the software sends commands to the PIC type CODING PARAMETERS + 4 (we were inspired by the structure defined in the specifications for Secure Digital and CMD17 CMD24 or controls reading / writing that are followed by the address to 32 bits of block read / write. On the other hand, the card will respond through sequences of bytes. The range of "polling" (request from the computer) is 10 ms, which is more than enough for the goals we set ourselves. In the descriptor
Report (the "Listing" 5) we used a hierarchical structure. The field definitions of entry and exit, sized according to what we said above, are highlighted. We can see, there are structures to 8 bits for which we set limits on ordinary logic (0-255).
Moving quickly on usage.
Regarding the String descriptor, we used the values described in the "Listing" 6. These values are reported in a panel of the software when the device completes the enumeration process.
For neophytes, note that this process serves to ensure that the host ("host") and the device ("device") to get to know and can then establish a communication channel. Remember also that the name of the file containing the descriptors must be inserted into the file usbdesc.asm so that the compiler properly included in the PBP structure. HEX we then insert into the memory of the PIC.
We used among others for the correct compilation of the software project, File p18f2550.inc duly amended, providing for a division of the incoming oscillation frequency equal to 5 and a division of the system clock frequency equal to 4.
Thus, we get up in the circuit of a quartz 20 MHz and maintain (through the activation of a PLL) a 24 MHz internal clock. To program the PIC we use the MELAB Program Microengineering Labs and maintain configurations visible in the dialog in Figure 4.
That said, the time has come for the code itself. Let's take a look at the "Listing", 7 which contains statements: for communication with the card, we use the SPI mode includes a subset of standard SD protocol commands and is the easiest to implement. It does indeed only three lines to communicate: one for the clock (SCK), one for incoming data (SDI) and one for outgoing data (SDO), in addition, of course, the signal CS ( Chip Select) are used primarily to enter into SPI mode and establish the beginning and the end of a transaction.
We also clarified the pins used for ignition and extinction of two LED lights.
Finally comes the sequence of variables necessary for the process.
The pair IND0, IND1 used to determine the block address to read / write and compose the sequence of 32 bits sent by the host as a parameter list. CMD
The vector, consisting of 5 bytes, contains the sequence + 4 CODING PARAMETERS.
The choice is due to what has been established in the descriptor extension.
As shown in the "Listing" 8, the initialization code is simple. PORTA is set everything out because we only use two lines to control the LEDs, the PORTB pin is provided for the RB2 as input line for data from the card. The extinction of the two LEDs is performed and go to the startup code of the device first and then the DS. Initially the procedure
enumeration of the device is claimed stabilization and a pause of half a second occurs. At the end of the procedure, the ICP is recognized by the operating system of the computer and is ready to enter into communication with the software we use for reading / writing to the card. At the end of this process we are launching an initialization phase of the DS that will allow us to first switch to SPI and to establish the dimensional limits of blocks read / write. To summarize: we can distinguish two basic phases, RESET CARD (CMD0) and BOOT (CMD1).
In the "Listing" 9 This is how you see the code.
Note that the "reset" is preceded by a sequence of clock cycles "empty" (or "Dummy Clock" fictitious clock) as want the Secure Digital specifications.
In particular, the CMD0 is sent by holding the line at 0 CS: This procedure allows you to enter in SPI mode.
Once entered, it starts the initialization of the device and wait for the DS has completed this phase (it checks for the response it sends). Recall that
SPI mode the card is able to send only two types of response, one 8-bit (RISP1) and a 16-bit (RISP2), each with a particular structure of error reporting. Note that these sequences in a period ("time-out") was intended to avoid error in case the system crashes.
In this case, through a counter (CONTA1), we establish the limit beyond which repetition is assumed that the card refuses to answer or the initialization phase échoué.La definition of the number of bytes that make up block read / write the SD is skipped because it uses the standard length of 512 bytes (the "Listing" 10). When this first procedure is completed, we light the green LED (to indicate that the device is initialized and is ready to receive commands from the software running on the computer). We enter
especially in a loop waiting on the USB port, through which we expect to receive a sequence of 5 bytes, the first will contain the codes for the command to execute.
In the "Listing" 11 we see clearly the sequence of logic used to determine which instructions execute according to the first byte received. We intentionally kept the encoding used in the protocol description for SD SPI: the 17 starts playing (in the protocol is used CMD17) and the 24 write (CMD24). If any other command arrives, it is discarded and we return to the reading of a new sequence of 5 bytes. Note that the function USBService, which manages the USB interface module, is regularly called. The resulting code, in fact, no longer based on management interrupt signals ("interrupt"), but only on a continuous interrogation records associated with the port to identify the various operations to be performed.
Regarding the reading process, we have agreed to receive the address of the block to read in the last 4 bytes of the sequence of 5. We are launching
then the read command by transferring 512 bytes on the USB bus through instruction USBOUT. The resulting instructions are visible in the Listing 12. We light the red LED to indicate that the development of the command is in progress. The CMD17 is sent to the DS, passing as parameters the last 4 bytes received from the computer.
When the order is accepted, the card sends a special sequence of bits named "Start-Block", after which the show begins a sequence of 512 bytes, each byte is immediately sent. In the end, through the CMD13, the Status register of the card is read to verify if the operation was successful or if an error occurred.
Then, a jump ("jump") is made to the label AVVIOP where is located the code that will take care of waiting for a new command from the host. The red LED is off, the green turned back to alert the user the ability to send a new request to read / write. And we can SCRIVE label containing the code of writing a block of 512 bytes on SD (the "Listing" 13).
We light the red LED and we value and properly IND0 IND1 with the sector address to write. Through CMD24 we initialize the transaction write and send the "Start Block" ("Listing" 14).
The host ("host") sends us 104 packets of 5 bytes each: the first consists of the identifier of the command to execute followed by the address of the corresponding sector. The remaining 103 consist of values to be written on the card. The last 3-byte packet for closure and, therefore, as shown in the "listing, we are introducing the first two in the card. We therefore conclude the write operation (the "Listing" 15).
Note the logical AND operation to extract said "Data Response Token" sent for each data block written.
This sequence of bits becomes very important in the case of operations such as writing several contiguous blocks (here we will not use it). If, indeed, an error occurs, the PIC should block the transaction through a CMD12.
We do nothing but report the error by turning all the red and green (labels ERROR ERRORE2) and resetting the card. Thus, the circuit does not block and returns to the ring waiting for the command from the host. As for the read operation, also in this case we use CMD13 to know the Status of the DS. At the end we return to the label AVVIOP to await the next command sequence through USB.
"Listing 1.Thus, the maximum accessible sector is recalculated. The number refers to the amount of sections of 512 bytes used to store data.
; ********************************************* *************************
; TABLE SETTINGS GENERAL
; ******************************************* ***************************
EP0_BUFF_SIZE 8
# define # define # define MAX_NUM_INT 1
MAX_EP_NUMBER
1 # define NUM_CONFIGURATIONS
# 1 define a NUM_INTERFACES
# define # define MODE_PP _PPBM0
UCFG_VAL _TRINT
; TABLE PARAMETERS CLASS HID
; ****************************************** ********
HID_INTF_ID 0x00 # define # define
HID_UEP UEP1
HID_BD_OUT ep1Bo
# define # define # define HID_INT_OUT_EP_SIZE 8 HID_BD_IN ep1Bi HID_INT_IN_EP_SIZE 8 # define # define HID_NUM_OF_DSC 1
" Listing 3.
; ********************************************* *****
; INTERFACE DESCRIPTOR TABLE 3
; ************************************* *************
Interface1
retlw (HIDDescriptor1-Interface1) / 2; blength
retlw DSC_INTF;
retlw 0x00 bDescriptorType;
retlw 0x00 bInterfaceNumber, bAlternateSetting retlw 0x02; retlw 0x03 bNumEndpoints ;
retlw 0x01 bInterfaceClass, bInterfaceSubClass
retlw 0x02; bInterface Protocol
retlw 0x05; iInterface
"Listing" 4.
; ********************************************* *********************
; DESCRIPTOR TABLE 5 'end-point
; ***************** *************************************************
Endpoint1
retlw (Endpoint2-Endpoint1)/2 ; bLength
retlw DSC_EP ; bDescriptorType
retlw 0x81 ; bEndpointAddress retlw 0x03 ; bmAttributes retlw 0x01 ; wMaxPacketSize (low-b)
retlw 0x00 ; wMaxPacketSize (high-b)
retlw 0x0A ; bInterval
Endpoint2
retlw (EndConfig1-Endpoint2)/2 ; bLength
retlw DSC_EP ; bDescriptorType
retlw 0x01 ; bEndpointAddress retlw 0x03 ; bmAttributes
retlw 0x05 ; wMaxPacketSize (low-b) retlw 0x00 ; wMaxPacketSize (high-b)
retlw 0x0A ; bInterval
EndConfig1
"Listing" 5.
ReportDescriptor retlw 0x06 ; Octet de préfixe (bTag,bType,bSize)
retlw 0x01 ; Usage Page (low-b) (“Vendor Defined Page 1”)
retlw 0xFF ; Usage Page (high-b) (“Vendor Defined Page 1”)
retlw 0x09 ; Octet de préfixe (bTag,bType,bSize)
retlw 0x01 ; Usage (“Vendor Defined Usage 1”)
retlw 0xA1 ; Octet de préfixe (bTag,bType,bSize)
retlw 0x01 ; Collection (“Application”) retlw 0x09 ; Octet de préfixe (bTag,bType,bSize) retlw 0x02 ; Usage (“Vendor Defined Usage 2”) retlw 0xA1 ; Octet de préfixe (bTag,bType,bSize) retlw 0x00 ; Collection (“Physical”)
retlw 0x06 ; Octet de préfixe (bTag,bType,bSize)
retlw 0x02 ; Usage Page (low-b) (“Vendor Defined Page 2”)
retlw 0xFF ; Usage Page (high-b) (“Vendor Defined Page 2”)
retlw 0x09 ; Octet de préfixe (bTag,bType,bSize)
retlw 0x03 ; Usage (“Vendor Defined Usage 3”)
retlw 0x09 ; Octet de préfixe (bTag,bType,bSize)
retlw 0x04 ; Usage (“Vendor Defined Usage 4”)
retlw 0x15 ; Octet de préfixe (bTag,bType,bSize)
retlw 0x00 ; Logical Minimum (0)
retlw 0x26 ; Octet de préfixe (bTag,bType,bSize)
retlw 0xFF; Logical Maximum (low-b) (255)
retlw 0x00; Logical Maximum (high-b)
retlw 0x75; byte prefix (BTAG, BTYPE, bsize)
retlw 0x08; Report Size (8 bits)
retlw 0x95; byte prefix (BTAG, BTYPE, bsize)
retlw 0x01; Report Count (1 campo dati)
retlw 0x81; byte prefix (BTAG, BTYPE, bsize)
retlw 0x02; Input (Data, Var, Abs)
retlw 0x09; byte prefix (BTAG, BTYPE, bsize)
retlw 0x05; Use ("Vendor Defined Usage 5) retlw 0x15; byte prefix (BTAG, BTYPE, bsize)
retlw 0x00; Logical Minimum (0)
retlw 0x26; byte prefix (BTAG, BTYPE, bsize)
retlw 0xFF; Logical Maximum (low-b) (255)
retlw 0x00; Logical Maximum (high-b)
retlw 0x75; byte prefix (BTAG, BTYPE, bsize)
retlw 0x08; Report Size (8 bits)
retlw 0x95; byte prefix (BTAG, BTYPE, bsize)
retlw 0x05; Report Count (5 campi dati)
retlw 0x91; byte prefix (BTAG, BTYPE, bsize)
retlw 0x02; Output (Data, Var, Abs)
retlw 0xC0; End Collection ("Physical")
retlw 0xC0; End Collection ("Application")
end_ReportDescriptor
"Listing" 6.
DEVICE NAME: Reading / Writing SDCARD MANIFACTURER: Microchip
SERIAL NUMBER: TAU333
CONFIGURATION: CFG1
INTERFACE: EP1/INOUT
"Listing" 7.
‘*********************************
‘*Connexion avec la SDCard
‘*********************************
SCK var PORTB.6 ‘CLOCK-CARD PIN5 (27 PIC)
SDI var PORTB.5 ‘DONNEES-ENTREE-CARD PIN2 (26 PIC)
SS var PORTB.4 ‘SELECTION-CARD PIN1 (25 PIC)
SDO var PORTB.2 ‘DONNEES-SORTIE-CARD PIN7 (23 PIC)
‘******** '* LED '******** ROSSO was PORTA.3' LED ROUGE VERDE was PORTA.5 'LED VERT
'***************
'* Application
'***************
RISP1 was byte' REPONSE TYPE R1 PAR CARD (8bit)
RISP2 was the word 'REPONSE PAR CARD TYPE R2 (16bit)
IND1 was the word 'WORD ADDRESS sdcard HAUTE BIT 16-31
IND0 the word' ADDRESS sdcard WORD BIT BASS 0-15
CAR was byte 'A CARACTERE ECRIRE
CONT VAR BYTE' compteur octets reçus
cmd VAR BYTE [5] 'Séquence Comme + IND0 + IND1
CONTA1 was the word 'COMPTEUR
CONTA2 var word 'COUNTER
CTL var byte' Control byte FRAM
QX var byte 'Data Response 4 BIT ANALYSIS
"Listing" 8.
ADCON1 = 001111 'PIN RA Digital
TRISA = 000000' PORTA output TRISB = 000100
'RB6 RB5 = = CLOCK BACK CARD
' = RB4 RB2 = SELECT CARD BY CARD
PORTA = 0 'Reset LED ROSSO
= 1 = 0
VERDE
USBInit 'Process list at the end the device, enter the configured state Pause 500' Wait
"Listing" 9.
RESET:
SS = 1 FOR = 1 TO 10 CONTA1
SHIFTOUT SDI, SCK, MSBFIRST, [$ FF] 'Send clock cycles vacuum
NEXT CONTA1
SS = 0
PAUSE 50' * ******************************* '* SS 0 CMD0 now '********* *********************** SHIFTOUT SDI, SCK, MSBFIRST, [$ 40, $ 00, $ 00, $ 00, $ 00, $ 95] 'Send CMD0 SHIFTIN SDO SCK, MSBPRE [RISP1] 'Read response from the R1 Card
CONTA1 = 0 WHILE
RISP1 1
SHIFTIN SDO, SCK, MSBPRE [RISP1] 'Read response from the R1 Card
CONTA1 CONTA1 + 1 = IF
CONTA1> = 255 THEN' Time-out expired, he released
GOTO ERROR
ENDIF WEND
SS = 1 PAUSE 50
SS = 0
<>
"Listing 10.
'********************************************* ***********
'* Sends repeat CMD1 until response = 0
'************************ ********************************
CONTA1
RISP1 = 0 = 1 WHILE
RISP1
0
SS = 1 SHIFTOUT SDI, SCK, MSBFIRST, [$ FF] SHIFTIN SDO, SCK, MSBPRE [RISP1] SS = 0 PAUSE 50
SHIFTOUT SDI SCK, MSBFIRST, [$ 41, $ 00, $ 00, $ 00, $ 00, $ FF, $ FF] 'Envoie CMD1
SHIFTIN SDO, SCK, MSBPRE [RISP1]
CONTA1 = CONTA1 + 1
IF CONTA1> = 255 THEN' Time-Out Ecoul, the sort
ENDIF WEND GOTO ERROR
<>
"Listing 11.
AVVIOP:
RED = 0 'Extinction Rouge
GREEN LED = 1' LED Verte allumage
GET:
USBService
COUNT = 5
USBIN 1, CMD, COUNT, GET 'Reçoit séquence commande
USBService IF CMD [0] = 17 THEN' CMD17 = Lecture Secteur GOTO READ ENDIF IF CMD [0] = 24 THEN 'CMD24 = Ecriture Secteur
GOTO WRITE
ENDIF GOTO
AVVIOP
"Listing 12.
read:
RED = 1 'allumage Rouge
GREEN LED = 0' LED Verte Extinction
IND0.BYTE1 = CMD [1]
'Valorisation Adresse à lire
IND0.BYTE0 = CMD [2] ind1 . byte1 = CMD [3] = IND1.BYTE0 CMD [4]
Initialisation Address of the block to read the card through the last 4 bytes of the sequence of 5.
'* READ 512 BYTES ON SDCARD
SS = 1 SHIFTOUT SDI, SCK, MSBFIRST, [$ FF]
SHIFTIN SDO, SCK, MSBPRE [RISP1]
SS = 0 SHIFTOUT SDI, SCK, MSBFIRST, [$ 51,
IND1.BYTE1, IND1.BYTE0, IND0.BYTE1, IND0.BYTE0
, $ FF]
address block to read past the map as a parameter of CMD17.
'Sends CMD17
SHIFTIN SDO, SCK, MSBPRE [RISP1]
CONTA1 = 0 WHILE
RISP1 0 SHIFTIN SDO, SCK, MSBPRE [RISP1]
CONTA1 = CONTA1 + 1
IF CONTA1 >= 255 THEN ‘Time-Out écoulé, il sort GOTO ERRORE
ENDIF
WEND ‘Réception START BLOCK
SHIFTIN SDO,SCK,MSBPRE,[RISP1]
CONTA1 = 0
WHILE RISP1
$FE <>
Réception du Start-Block 11111110.
SHIFTIN SDO,SCK,MSBPRE,[RISP1]
CONTA1 = CONTA1 + 1
IF CONTA1 >= 255 THEN ‘Time-Out écoulé, il sort <> GOTO ERRORE ENDIF WEND
‘Réception BLOC DONNEES
FOR CONTA2= 0 TO 511
SHIFTIN SDO,SCK,MSBPRE,[CAR]
INVIA: USBService USBOUT 1, CAR 1, INVIA
'Send via USB
reception of 1 byte and writing on FRAM.
NEXT CONTA2
'Receiving CRC SHIFTIN SDO, SCK, MSBPRE [RISP1]
SHIFTIN SDO, SCK, MSBPRE [RISP1]
' As soon as the card has finished reading checks the status of the card 'Sends CMD13
SS = 1
SHIFTOUT SDI, SCK, MSBFIRST, [$ FF] SHIFTIN SDO, SCK, MSBPRE [RISP1]
SS = 0
SHIFTOUT SDI, SCK, MSBFIRST, [$ 4D, $ 00, $ 00 , $ 00, $ 00, $ FF]
Reception card status through the response to 16 bits.
'Get the response status to 16-bit format 2
SHIFTIN SDO, SCK, MSBPRE [RISP2 \\ 16]
CONTA2 = 0 WHILE
RISP2.BYTE0
0
SHIFTIN SDO, SCK, MSBPRE [RISP2 \\ 16]
CONTA2 CONTA2 + 1 = IF
CONTA2> = 255 THEN GOTO ERRORE2
ENDIF WEND GOTO AVVIOP
<> "Listing 13.
Scriver:
ROSSO = 1 'Red LED Lighting
VERDE = 0' LED goes Green
IND0.BYTE1 = CMD [1] "Address to write Valuation
IND0.BYTE0 = CMD [2] =
IND1.BYTE1 CMD [3] =
IND1.BYTE0 CMD [4]
'------------------------------------------------ ------------ '* WRITE 512 BYTES ON SDCARD '---------------------------- --------------------------------
USBService
SS = 1
SHIFTOUT SDI, SCK, MSBFIRST, [$ FF ]
SHIFTIN SDO, SCK, MSBPRE [RISP1]
'Sends CMD24 block write on sdcard
SS = 0
SHIFTOUT SDI, SCK, MSBFIRST, [$ 58,
IND1.BYTE1, IND1.BYTE0, IND0.BYTE1, IND0.
Byte 0, $ FF]
Passage of the block address to write.
SHIFTIN SDO, SCK, MSBPRE [RISP1]
CONTA2 = 0 WHILE
RISP1 0
Checks if the card is ready to receive data.
SHIFTIN SDO, SCK, MSBPRE [RISP1]
CONTA2 CONTA2 + 1 = IF
CONTA2> 10000 THEN GOTO ERROR <> ENDIF WEND
'Send Start Block% 11111110 = $ FE
SHIFTOUT SDI, SCK, MSBFIRST , [$ FE]
"Listing" 14.
CONTA1 FOR = 1 TO 102
RX5:
USBService
CONTA = 5
USBIN 1, CMD, CONTA, RX5
reception block 5 bytes.
USBService
'Start Writing on SDCARD
FOR CONTA = 0 TO 4
CAR = CMD [CONT]
SHIFTOUT SDI, SCK, MSBFIRST [CAR]
Writing last 5 bytes received.
NEXT NEXT CONTA
CONTA1
RX6: USBService CONTA = 5
USBIN 1, CMD, CONTA, RX6 USBService
CAR = CMD [0] SHIFTOUT SDI, SCK, MSBFIRST [CAR]
CAR = CMD [1]
SHIFTOUT SDI, SCK, MSBFIRST [CAR]
Closing sector.
"Listing" 15.
SHIFTOUT SDI, SCK, MSBFIRST, [$ FF, $ FF]
SHIFTIN SDO, SCK, MSBPRE [RISP1] QX =
000000
RISP1 QX = & $ 0F
4 bits Derniers réponse de la commande d'écriture: DONNÉES ACCEPTEES 0101 1011 1101 DONNÉES REFUSEES erreur CRC
DONNÉES REFUSEES erreur Ecriture
QX 000101 IF THEN
ENDIF GOTO ERROR
'Reçois the busy bit of the écriture pendant la carte SHIFTIN SDO, SCK, MSBPRE [RISP1]
Account2
= 0 = 0 WHILE RISP1
SHIFTIN SDO, SCK, MSBPRE [RISP1]
+ 1 = Account2 Account2
Account2 IF> = 255 THEN GOTO ERROR
ENDIF WEND
<> 'Envoie the CMD13
SS = 1
SHIFTOUT SDI, SCK, MSBFIRST, [$ FF]
SHIFTIN SDO, SCK, MSBPRE [RISP1]
SS = 0
SHIFTOUT SDI, SCK, MSBFIRST, [$ 4D, $ 00, $ 00, $ 00, $ 00, $ FF]
SHIFTIN SDO, SCK, MSBPRE [RISP2 \\ 16]
reception status of the card.
CONTA2 = 0 WHILE
RISP2.BYTE0
0
SHIFTIN SDO, SCK, MSBPRE [RISP2 \\ 16] = CONTA2 CONTA2 IF CONTA2 + 1> = 255 THEN GOTO
ERRORE2
WEND ENDIF GoTo
AVVIOP
PC software
<> Now for the software we'll turn on the computer to control the read / write SD. It was
written in Delphi and uses the main subject TJvHidDevice-Controller: This is a component of a project conceived at the JEDI (Joint Endeavour of Delphi Innovators), that is to say an international community of a thousand developers Delphi, whose aim is to disseminate this environment and his younger brother Kylix. The program interface is very simple to use and it can immediately experience the features we've introduced in the curriculum.
The main screen (Figure 5) displays three panels: one contains data on USB, one can choose the size of map and the third includes the necessary buttons to the functions of reading / writing. This is complemented by a simple grid of 512 cells divided into 32 lines of 16 elements.
It is thus possible to monitor and change values. To avoid errors, there is provided a procedure for checking the congruence of data inserted, when a read / write or export / import is started.
When inserting a value not admissible (incongruously) a message indicating the line number and that of column (or the coordinates of the faulty cell) is viewed. If we
link up the circuit to the USB port (the DS is already inserted in the drive) following the enumeration process, the identifier fields are loaded into the panel (value inserted in the Descriptor String).
In the list of devices appears the word read / write SD card. The Status of the communication is updated (Hardcover or unplug) and if we look at our deck, we see that the first yellow LED (supply voltage reaches well), followed by the green LED (map exceeded the phase reset, the SPI input mode and the initialization process). Note if it connects the circuit without SD in the drive, the LED will glow green and red together (to indicate the error).
After this first phase, you can position yourself on the Settings panel to select the card through the two small arrows capacity of the card.
can then be positioned on the panel Procedure. Here we insert the number of sectors that we want to develop, of course, modification of these fields is related to the dimensional limit of the card we have just established. Using the buttons of the panel, we can launch 5 basic functions (we will analyze below). Leggi
: Clicking this button launches a reading area that we specified in the field (Let Blocco / Scr); progress of the procedure is controlled by the applet window red (see Figure 5); As to the arrival of the sequence of bytes to the PC, the values are inserted into the grid and are directly visible and editable. Scrivi : Starts writing information sector as we stated in the field (Let Blocco / Scr) and directly support data grid. Cancel: empty grid by inserting the value FFh in all cells.
Importa: load data into the grid from an external file.
Esporta sends the data grid to an external file. Regarding the latter two functions, consider that the files have used an extension type. Ndc, however, that these are text files.
Their structure is very simple: each line represents a value to insert in the grid.
The sequence is generated by reading each row from left to right and top to bottom, as one would read a sheet of paper. With a click on the button Importa it opens a dialog, as shown in Figure 6.
It is therefore possible to select the file and load it by clicking on Apri. Control data inserted is made to signal a possibly erroneous line. The export procedure operates essentially complementary.
Again, a dialog opens where you can insert the name of the file you want to create.
Then, with a click on the button Salva, the grid is transferred to the selected file.
Figure 4: To program the PIC we use the MELAB Program Microengineering Labs, maintaining the configuration visible in this dialog.
Figure 5: The main screen has three panels.
Figure 6: Clicking the button opens the Import dialog.
The practical The practical realization of this player / recorder data on SD-Card USB is the easiest and fastest (the complexity of the device from the resident program and software for PC ). The plate consists of a small single-sided PCB, which 2b gives a scale drawing. Make it through the method known as "blue film" and when you have before you, engraved, drilled, tinned, first insert the two mounting integrated circuits and both "straps" (in R3 and between C4 and C6). Double check your solder (or short-circuit between tracks or pads or cold solder joints). Insert and then solder all components (as shown in Figures 2a and 3), continuing with the resistors, capacitors, Schottky diodes, LED, quartz (standing) and regulator (standing without heatsink metal sole and outward-looking of the plate) and ending with "peripheral" to know the USB-B PCB. Attention to the orientation of polarized components: integrated circuits (marked U-notches facing down well, but put them at the very end), diodes, LEDs, regulator and electrolytic. Remember also to weld the tabs on the shield connector USB-B. Check out all the polarities and (again) the quality of welds.
That's the face "components".
back plate and solder very thoroughly (directly on the slopes of the "copper side) the card reader (or door-SD), SD1. Insert the ICs. The microcontroller is already available in factory programmed (see our advertisers). Check everything again. You can now install the deck in a plastic box of appropriate size: the lid is pierced with three holes for the LED, one of the smaller sides of a square recess for the USB connector and the other short side a slot to insert the SD Card. The supply of 5 V is therefore by the computer's USB port. To connect the turntable to the computer, use an ordinary USB cable.
Conclusion Although physically simple, this device can become familiar with this new storage medium and perform experiments trainers before tackling the more complex arguments: for example, this tour will help you anlysis key sectors Formatting as FAT16 "boot-sector" and "root-directory (see previous articles devoted to arranging implementing an SD-Card).
But apart from this aspect of teaching (which, admittedly, we were once again guided), this player / recorder USB data will be useful to convey to a computer data written by all types of devices in an SD card, or to transfer the same SD of files in the PC.
0 comments:
Post a Comment