목차
WAT-MSD347
본 제품은 커맨드(시리얼통신)으로 MicroSD 카드를 제어할 수 있는 모듈로 AVR, PIC, 8051 등의 MCU에 연결하여 사용할 수 있습니다.
- 입력 전압 : 5~ 12V
- FILE : FAT
- 제어방식 : 시리얼 통신 커맨드 사용
핀 설명
Number | Symbol | Note |
---|---|---|
1 | GND | GND |
2 | GND | GND |
3 | VCC | 5V |
4 | RXD | RXD |
5 | TXD | TXD |
6 | RESET | RESET |
7 | 3.3V | 3.3V OUTPUT |
간편 방식
데이터 쓰기
한줄의 커맨드로 데이터를 쓸 수 있는 방식이며 적은 데이터를 다루는데 편리합니다.
$write1 파일명 데이터
$write1ln 파일명 데이터ex) “myfile.txt” 파일에 “HI! This is my data. Good!!” 데이트 쓰는 예제
$write1 myfile.txt HI! This is my data. Good!!
일반 방식
많은 데이터를 다루는데 사용되며 각각의 명령어로 파일을 다룰 수 있습니다.
파일을 open 한 상태에서 연속적으로 데이터 라이팅이 가능하며 저장을 위해서는 close 명령을 해줘야 합니다.
파일 열기
파일을 읽거나 쓰기 위해서는 먼저 ‘open’을 해줘야 합니다.
$open 파일명
ex) $open myfile2.txt
데이터 쓰기
파일에 데이터를 쓰는 방법입니다. (먼저 open 되어 있어야 합니다.)
$write 데이터
$writeln 데이터
ex) $write test Data….. $write teset
ex) $writeln test Data….. $writeln teset
데이터 읽기
자료 준비중입니다.(현재는 제공하지 않습니다.)
파일 닫기
파일을 쓰거나 읽은 후에는 필히 ‘close’ 해 줘야 합니다.
$close
커맨드
시리얼 통신 커맨드로 열기, 읽기, 쓰기, 닫기 등을 제어할 수 있습니다.
Commands | Description | Parameters | Examples |
---|---|---|---|
$write1 f d | 한줄로 파일 쓰기 | f : filename d : data | $write1 f.txt 1234 abcd // f.txt 파일에 1234 abcd 파일을 쓰기 |
$write1ln f d | 한줄로 파일 쓰고 CRLF 추가 | f : filename d : data | $writeln f.txt 1234 abcd // f.txt 파일에 1234 abcd\r\n 파일을 쓰기 |
$open f | 파일 열기 | f : filename | $open f.txt // f.txt 파일 열기 |
$write d | 데이터 쓰기 | d : data | $write data1234 // 현재 열려진 파일에 "data1234 쓰기" |
$writeln d | 데이터를 쓰고 '\n' 추가 | d : data | $writeln data1234 // 현재 열려진 파일에 "data1234\n" 쓰기 |
$close | 파일 닫기 | $close 열려진 파일 닫기 |
ATMEGA128A 예제
연결
ATMEGA128 (WAT-AVR128 Plus 보드 사용)과 WAT-MSD347 모듈을 아래와 같이 연결합니다.
RESET 핀과 3.3V 출력핀은 사용하지 않습니다.
번호 | ATMEGA128A | WAT-MSD347 핀명 |
---|---|---|
1 | GND | GND |
2 | GND | GND |
3 | +5V | VCC |
4 | TXD1 (PD3) | TXD |
5 | RXD1 (PD2) | RXD |
6 | x | RESET |
7 | x | 3.3V out |
ATMEGA128 소스코드
전체 코드는 http://whiteat.com/bPDS_AVR/57204 에서 제공합니다.
/* WAT_MSD347_AVR WAT-MSD347 MicroSD card module Test Program AVRStudio 4.18 2017-03-02 HOMEPAGE: http://WhiteAT.com SHOPPING: http://kit128.com */ #include <avr/io.h> #include "WAT128.h" #define WAIT_SD_CARD while(GetByte1() !='!'){} int main() { OpenSCI1(115200); // USART 1 열기 PutString1("$reset\n"); DelayMS(2000); while(GetByte1() !=-1){} PutString1("$write1 1one.txt This is $write1 command 1This is $write1 command 1.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 2This is $write1 command 2.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 3This is $write1 command 3.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 4This is $write1 command 4.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 5This is $write1 command 5.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 6This is $write1 command 6.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 7This is $write1 command 7.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 8This is $write1 command 8.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 9This is $write1 command 9.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 10This is $write1 command 10.\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 11This is $write1 command 11\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 12This is $write1 command 12\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 13This is $write1 command 13\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 14This is $write1 command 14\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 15This is $write1 command 15\n"); WAIT_SD_CARD; PutString1("$write1 1one.txt This is $write1 command 16This is $write1 command 16\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 1.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 2.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 3.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 4.\n");WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 5.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 6.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 7.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command 8.\n");WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command a.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command b.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command c\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command d\n");WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command e.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command f.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command g.\n"); WAIT_SD_CARD; PutString1("$write1ln 2oneln.txt This is $write1ln command h.\n");WAIT_SD_CARD; PutString1("$open 3cmd.txt\n"); WAIT_SD_CARD; PutString1("$write This is $open,$write,$close command 1\n"); WAIT_SD_CARD; PutString1("$write This is $open,$write,$close command 2\n"); WAIT_SD_CARD; PutString1("$write This is $open,$write,$close command 3\n"); WAIT_SD_CARD; PutString1("$write This is $open,$write,$close command 4\n"); WAIT_SD_CARD; PutString1("$close\n"); WAIT_SD_CARD; PutString1("$open 4cmdln.txt\n"); WAIT_SD_CARD; PutString1("$writeln This is $open,$writeln,$close command 1\n"); WAIT_SD_CARD; PutString1("$writeln This is $open,$writeln,$close command 2\n"); WAIT_SD_CARD; PutString1("$writeln This is $open,$writeln,$close command 3\n"); WAIT_SD_CARD; PutString1("$writeln This is $open,$writeln,$close command 4\n"); WAIT_SD_CARD; PutString1("$close\n"); WAIT_SD_CARD; while(1) { } }
결과
기본적으로 생성되는 WHITEAT.TXT 파일과 4개의 파일이 생성됩니다.
제품 구매
[WAT-MSD347] 시리얼통신 MicroSD Card 모듈 은 https://kit128.com/goods/view?no=347 에서 구매하실 수 있습니다.