Ameba Arduino: [RTL8195AM] SDIO - Edit files in SD card

  • Ameba x 1
  • SD card or MicroSD card x 1
  • SD sniffer x 1 (optional)
Ameba can act as SD Host to handle applications related to SD devices. For instance, this example use Ameba to perform read/write operations on SD card. Ameba uses the commonly used FAT format, therefore, the data written by Ameba can be accessed through computer easily. We can connect Ameba to SD card through wires directly. The figure below shows SD card pins: 1 We can weld wires on these pins and connect to Ameba: 2 Note: D1 & D0 (correspond to WP & CD) need to be connected to GND. SD host determines status of the SD card according these two pins. WP & CD staus: Low: GND High: Vcc
WP CD Description
High High SD card is not inserted.
HIGH LOW SD card inserted, write pretected.
LOW LOW SD card inserted, without write protected.
Instead of welding, there are some transition board can be used to connect Ameba and SD card: SD Sniffer: SD Breakout: No matter the SD card is connected via welding or transition board, the connecting wire should not be too long, since the wire length affects transmission quality. In the example, we use a 20cm dupont wire. Below is the wiring diagram of SD transition board: 3 The wiring of MicroSD card is similar. The figure below shows MicroSD card pins: 4 Afterwards, open the sample code in “File” -> “Examples” -> “AmebaSdFatFs” -> “file_read_write” In the sample code, we first create a text file “test.txt” with content “hello world!”, then read the file and print content to serial monitor. 5 Next, insert SD card into card reader, and check whether the operations succeeded. 6
Code reference
In the sample code, first we use a SdFatFs object to manage the FAT file system in the SD card.
SdFatFs fs;
Next, user begin() to initialize FatFs, including the initialization of SD Host and mounting the file system.
Use open() to open the file, the argument requires absolute path of the file to be opened. The return value contains a SdFatFile object which is use to manipulate the opened file.
SdFatFile file =;
SdFatFile class inherits Stream class, therefore we can use println to write to a file.
Then close the file.
To read from the file:, sizeof(buf));
Finally, close the FAT file system:
Please confirm that QQ communication software is installed