(SKU:RB-02S018A) TF卡读写模块
来自ALSROBOT WiKi
目录 |
产品概述
该模块(MicroSD Card Adapter)是Micro SD卡读写模块,通过文件系统及SPI接口驱动程序,单片机系统即可完成MicroSD卡内的文件进行读写。Arduino用户可直接使用Arduino IDE自带的SD卡程序库即可完成卡的初始化和读写。
模块特点如下:
- 支持Micro SD卡、Micro SDHC卡(高速卡)
- 板载电平转换电路,即接口电平可为5V或3.3V
- 供电电源为4.5V - 5.5V,板载3.3V稳压电路
- 通信接口为标准SPI接口
- 4个M2螺丝定位孔,便于安装
规格参数
- 工作电压:3.3V - 5V
- 产品尺寸:40mm * 28mm
- 重量大小:3g
- 信号类型:模拟信号
- 固定孔:M3 * 4个
- 通信接口:标准 SPI 接口
- 支持卡类型:Micro SD 卡(< = 2G),Micro SDHC 卡(< = 32G)
接口定义
- + :电源正
- - :电源地
- DI :串行数据输入
- DO :串行数据输出
- CK :串行时钟
- CS :片选信号,由控制器进行控制
使用方法
工作原理
TF 卡模块使用 SPI 总线连接方式实现与 Arduino 控制器的通信,稳压芯片输出的 3.3V 为电平转换芯片、Micro SD 卡进行供电,电平转换电路往 Micro SD 卡方向的信号转换成 3.3V,Micro SD 卡往控制接口方向的 MISO 信号也转换成了 3.3V,一般 AVR 单片机系统都可以读取该信号,产品使用自弹式卡座,方便卡的插拔。
编程原理
TF 卡模块共引出 6 个引脚,其中 DO、CK、DI 是 SPI 总线接口,“+”为电源正,“-”为电源GND,CS为片选端,实际使用时依照下面的接线图连接即可,使用 Arduino IDE 自带的例子程序就可以进行测试。
连接示意图
例子程序
/* SD card test * SD card attached to SPI bus as follows: ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila ** CS - depends on your SD card shield or module. Pin 4 used here for consistency with other Arduino examples */ // include the SD library: #include <SPI.h> #include <SD.h> // set up variables using the SD utility library functions: Sd2Card card; SdVolume volume; SdFile root; // change this to match your SD shield or module; // Arduino Ethernet shield: pin 4 // Adafruit SD shields and modules: pin 10 // Sparkfun SD shield: pin 8 const int chipSelect = 4; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print("\nInitializing SD card..."); // we'll use the initialization code from the utility libraries // since we're just testing if the card is working! if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println("initialization failed. Things to check:"); Serial.println("* is a card inserted?"); Serial.println("* is your wiring correct?"); Serial.println("* did you change the chipSelect pin to match your shield or module?"); return; } else { Serial.println("Wiring is correct and a card is present."); } // print the type of card Serial.print("\nCard type: "); switch (card.type()) { case SD_CARD_TYPE_SD1: Serial.println("SD1"); break; case SD_CARD_TYPE_SD2: Serial.println("SD2"); break; case SD_CARD_TYPE_SDHC: Serial.println("SDHC"); break; default: Serial.println("Unknown"); } // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!volume.init(card)) { Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); return; } // print the type and size of the first FAT-type volume uint32_t volumesize; Serial.print("\nVolume type is FAT"); Serial.println(volume.fatType(), DEC); Serial.println(); volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters volumesize *= 512; // SD card blocks are always 512 bytes Serial.print("Volume size (bytes): "); Serial.println(volumesize); Serial.print("Volume size (Kbytes): "); volumesize /= 1024; Serial.println(volumesize); Serial.print("Volume size (Mbytes): "); volumesize /= 1024; Serial.println(volumesize); Serial.println("\nFiles found on the card (name, date and size in bytes): "); root.openRoot(volume); // list all files in the card with date and size root.ls(LS_R | LS_DATE | LS_SIZE); } void loop(void) { }
程序效果
程序编译上传无误之后,将准备好的 TF 卡插入到模块中,连接 TF 卡模块和 Arduino UNO 控制器,连接正常情况下,会显示出卡的信息,如下图所示: