(SKU:RB-02S018A) TF卡讀寫模塊

來自ALSROBOT WiKi
跳轉(zhuǎn)至: 導(dǎo)航、 搜索
02S018A01.png

目錄

產(chǎn)品概述

該模塊(MicroSD Card Adapter)是Micro SD卡讀寫模塊,通過文件系統(tǒng)及SPI接口驅(qū)動(dòng)程序,單片機(jī)系統(tǒng)即可完成MicroSD卡內(nèi)的文件進(jìn)行讀寫。Arduino用戶可直接使用Arduino IDE自帶的SD卡程序庫(kù)即可完成卡的初始化和讀寫。
模塊特點(diǎn)如下:

  • 支持Micro SD卡、Micro SDHC卡(高速卡)
  • 板載電平轉(zhuǎn)換電路,即接口電平可為5V或3.3V
  • 供電電源為4.5V - 5.5V,板載3.3V穩(wěn)壓電路
  • 通信接口為標(biāo)準(zhǔn)SPI接口
  • 4個(gè)M2螺絲定位孔,便于安裝

規(guī)格參數(shù)

  1. 工作電壓:3.3V - 5V
  2. 產(chǎn)品尺寸:40mm * 28mm
  3. 重量大?。?g
  4. 信號(hào)類型:模擬信號(hào)
  5. 固定孔:M3 * 4個(gè)
  6. 通信接口:標(biāo)準(zhǔn) SPI 接口
  7. 支持卡類型:Micro SD 卡(< = 2G),Micro SDHC 卡(< = 32G)

接口定義

  • + :電源正
  • - :電源地
  • DI :串行數(shù)據(jù)輸入
  • DO :串行數(shù)據(jù)輸出
  • CK :串行時(shí)鐘
  • CS :片選信號(hào),由控制器進(jìn)行控制
02S018A02.png

使用方法

工作原理

TF 卡模塊使用 SPI 總線連接方式實(shí)現(xiàn)與 Arduino 控制器的通信,穩(wěn)壓芯片輸出的 3.3V 為電平轉(zhuǎn)換芯片、Micro SD 卡進(jìn)行供電,電平轉(zhuǎn)換電路往 Micro SD 卡方向的信號(hào)轉(zhuǎn)換成 3.3V,Micro SD 卡往控制接口方向的 MISO 信號(hào)也轉(zhuǎn)換成了 3.3V,一般 AVR 單片機(jī)系統(tǒng)都可以讀取該信號(hào),產(chǎn)品使用自彈式卡座,方便卡的插拔。

編程原理

TF 卡模塊共引出 6 個(gè)引腳,其中 DO、CK、DI 是 SPI 總線接口,“+”為電源正,“-”為電源GND,CS為片選端,實(shí)際使用時(shí)依照下面的接線圖連接即可,使用 Arduino IDE 自帶的例子程序就可以進(jìn)行測(cè)試。

連接示意圖

02S018A03.png

例子程序

/*
  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) {

}

程序效果

程序編譯上傳無誤之后,將準(zhǔn)備好的 TF 卡插入到模塊中,連接 TF 卡模塊和 Arduino UNO 控制器,連接正常情況下,會(huì)顯示出卡的信息,如下圖所示:

02S018A04.png

產(chǎn)品相關(guān)推薦

Erweima.png

產(chǎn)品購(gòu)買地址

周邊產(chǎn)品推薦

相關(guān)問題解答

相關(guān)學(xué)習(xí)資料

奧松機(jī)器人技術(shù)論壇