PIC18

PIC18, MPLAB X IDE, XC8, SPI, FATFS, petit_fatfs

CoyoteUgly 2018. 9. 18. 16:27

PIC18, MPLAB X IDE, XC8, SPI, FATFS, petit_fatfs




FATFS 를 사용하여 SD카드를 제어합니다.

sandisk 8gb를 사용하였습니다.


pic 용으로 테스트한 코드가 있어서 이를 토대로 적용하여 확인하였습니다.


pic24 코드에서 pic18 코드로 포팅하는 과정이 필요하여 

핵심 api 외에 많은 부분을 변환하거나 추가/삭제하였습니다.


테스트 결과 ( 최신 소스(FatFs R0.13b)가 아닌 옛날 버전 기준 )

  • [OK] Initialize physical drive
  • [OK] Mount the volume
  • [OK] Directory listing
  • [OK] Open a file
  • [......] Write data to the file
    • 문자 또는 문자열
      • 코드 구현 필요
    • 10진수
      • [OK] 10진수 1개 write
      • [FAIL] 10진수 2개 write
        • 코드 정리? 필요
    • 16진수
      • 테스트하지 않음
    • 2진수
      • 테스트하지 않음
  • [OK] Move file pointer of the file
  • [OK] Read the file 128 bytes and dump it
  •  
  • [FAIL] File Create
    • 기능 없음
  • [FAIL] Directory Create
    • 기능 없음
  •  
  • 기타 등등

0. 참고 사항




1. HW 연결

sandisk 8gb 사용


2. 소스 설명

full 소스는 아래 github를 통해 확인하세요.


     Test Sequence


    > di - Initialize physical drive

    > fi - Mount the volum

    > fl [<path>] - Directory listing

    > fo <file> - Open a file

    > fw <len> <val> - Write data to the file

    > fe <pos> - Move file pointer of the file

    > fd - Read the file 128 bytes and dump it

    >  


3. 소스


4. 결과

0byte Text 파일을 사용하는 경우입니다.

file write가 되지 않습니다.





Petit FatFs test monitor

>di

        Initialize physical drive

        rc=0

>fi

        Mount the volume

        rc=0 FR_OK

>fl

        Directory listing

           <DIR>   SYSTEM~1

                0  A.TXT

        2 item(s)

>fo a.txt

        Open a file

        rc=0 FR_OK

>fw 1 1

        Write data to the file

        cnt != w

        rc=0 FR_OK

        0 bytes written.

>fe 0

        rc=0 FR_OK

        fptr = 0(0x0)

>fd

        Read the file 128 bytes and dump it




10byte Text 파일을 사용하는 경우입니다.

file write가 정상적으로 동작합니다.


10진수를 입력 받아서 hex 형식으로 저장합니다.





Petit FatFs test monitor

>di

        Initialize physical drive

        rc=0

>fi

        Mount the volume

        rc=0 FR_OK

>fl

        Directory listing

           <DIR>   SYSTEM~1

               10  A.TXT

        2 item(s)

>fo a.txt

        Open a file

        rc=0 FR_OK

>fw 1 1

        Write data to the file

        rc=0 FR_OK

        1 bytes written.

>fe 0

        rc=0 FR_OK

        fptr = 0(0x0)

>fd

        Read the file 128 bytes and dump it

        addr:        0 |  1  0  0  0  0  0  0  0  0  0 

>