SKU:RB-02S018A TF卡读写模块

来自ALSROBOT WiKi
2017年4月28日 (五) 11:30Arduino77讨论 | 贡献的版本

跳转至: 导航搜索
02S018A001.png

目录

产品概述

该模块(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螺丝定位孔,便于安装

规格参数

  1. 工作电压:3.3V - 5V
  2. 产品尺寸:40mm * 28mm
  3. 重量大小:3g
  4. 信号类型:模拟信号
  5. 固定孔:M3 * 4个
  6. 通信接口:标准 SPI 接口
  7. 支持卡类型:Micro SD 卡(< = 2G),Micro SDHC 卡(< = 32G)
  8. 电源指示灯:红色
  9. 数据传输指示灯:蓝色

接口定义

  • + :电源正
  • - :电源地
  • DI :串行数据输入
  • DO :串行数据输出
  • CK :串行时钟
  • CS :片选信号,由控制器进行控制
02S018A02.png

使用方法

工作原理

TF 卡模块使用 SPI 总线连接方式实现与 Arduino 控制器的通信,稳压芯片输出的 3.3V 为电平转换芯片、Micro SD 卡进行供电,电平转换电路往 Micro SD 卡方向的信号转换成 3.3V,Micro SD 卡往控制接口方向的 MISO 信号也转换成了 3.3V,一般 AVR 单片机系统都可以读取该信号,产品使用自弹式卡座,方便卡的插拔。
注意:Arduino 的 sd.h 库文件目前对 2G 及其以下的支持比较好,对 2G 以上的支持不好,所以在使用时,建议选用 2G 或以下的内存卡。

编程原理

TF 卡模块共引出 6 个引脚,其中 DO、CK、DI 是 SPI 总线接口,“+”为电源正,“-”为电源 GND,CS 为片选端,实际使用时依照下面的接线图连接即可,使用 Arduino IDE 自带的例子程序就可以进行测试。

连接示意图

02S018A03.png

例子程序

#include <SPI.h>
#include <SD.h>

Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 4;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("\nInitializing SD card...");

  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.");
  }

  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");
  }

  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  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);

  root.ls(LS_R | LS_DATE | LS_SIZE);
}


void loop(void) {

}

程序效果

程序编译上传无误之后,将准备好的 TF 卡插入到模块中,连接 TF 卡模块和 Arduino UNO 控制器,连接正常情况下,会显示出卡的信息,如下图所示:

02S018A100.png

产品相关推荐

Erweima.png

例子程序下载

下载链接:http://pan.baidu.com/s/1mikbyg4 密码:m59a

产品购买地址

Arduino TF卡读写存储模块:http://www.alsrobot.cn/goods-782.html

相关学习资料

奥松机器人技术论坛