for Airio-Base. SD card detect check and power on/off test program.

Dependencies:   mbed

Code URL

https://os.mbed.com/users/mbed_crane_elec/code/Airio-Base_SD_detect_power/

Airio-Baseで SDカード検出とカード電源のON/OFF制御をするサンプルコードです。

準備

  • FlashAirをSDカードソケットへ接続

SWスイッチ動作

SDカードが装着された状態でSWを押すと、LED2が点灯し、カードへの電源供給を開始(ON)します。

ISPスイッチ動作

LED2が消灯し、カードへの電源供給を停止(OFF)します。

コードについて

Airio-Baseのポート番号P1_19は、SDカードソケットのカード検出ピンに接続されています。 これはサンプルコード

DigitalIn sd_cd(P1_19, PullUp);//SD card detect port. must set to pullup

で定義されており、入力デジタルポートとなります。 入力ピンのプルアップ処理はMbedプログラム側のソフトウェアプルアップを用いて行います。( ",Pullup" 部)

FlashAirの電源確認

LED2点灯時に、スマートフォンなどからFlashAirにアクセスできることを確認して下さい。 また、LED2消灯時は、FlashAirにアクセスできないことを確認して下さい。

このカード電源の制御機能は、バッテリー駆動用途などの消費電力を抑える必要がある場合に有効です。

Revision:
0:e80122767958
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Aug 11 19:21:50 2018 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+//-------------------------------------------------------------------------------
+//Port Settings
+DigitalOut led1(P0_7,1);
+DigitalOut led2(P1_13,1);
+
+DigitalOut sd_en(P1_16, 0);//SD card power on/off control port. and OFF default.
+DigitalIn sd_cd(P1_19, PullUp);//SD card detect port. must set to pullup
+//DigitalIn sd_dat3(P0_17); // 0x10
+//DigitalIn sd_dat2(P1_22); // 0x08
+//DigitalIn sd_dat1(P1_14); // 0x04
+//DigitalIn sd_dat0(P0_22); // 0x02
+//DigitalIn sd_cmd(P0_21);  // 0x01
+
+DigitalIn sw(P1_20);
+DigitalIn isp(P0_1);
+
+//-------------------------------------------------------------------------------
+//Program
+int main()
+{
+    
+    while(1)
+    {
+        // Button "SW" function
+        if(sw == 0 && sd_cd == 0)
+        {
+            sd_en = 1;//SD card power turn ON
+            led2 = 0;//LED2 turn ON
+        }    
+        
+        // Button "ISP" function
+        if(isp == 0)
+        {
+            sd_en = 0;//SD card power turn OFF
+            led2 = 1;//LED2 turn OFF
+        }
+        
+        // SD Card detect port check
+        if(sd_cd == 0)
+        {
+            led1 = 0;// card detect!
+        }
+        else
+        {
+            led1 = 1;// no card
+        }
+
+    }
+}