News:

;) This forum is the property of Proton software developers

Main Menu

Proton24 SD File System

Started by Nickma, Mar 04, 2021, 07:37 AM

Previous topic - Next topic

Nickma

Hi everyone
I am designing an SD Card recording device using the Proton24 SD FAT File System (by top204). Don't know how to set record of file attributes (date / time). If anyone has examples, please share.

Craig

#1
Hi Nickman

This was written from GPS date and time received and was taken from Les's Examples.
SD Card Wired up as per Les's Example.
Pic 24FJ64GA004

'==========================================================================================
' Setup the SD Card - SPI For Use with The SD Card And Les's Inc SD Card File!
' Must ADD 10K Pull Up on (SDI Data In Pin) To Pic Otherwise It Might Get Stuck and Can't Initialize!!
'------------------------------------------------------------------------------------------
        $define SD_CLK        =  PORTB.14     ' (0) SPI CLK to SD cards CLK pin
        $define SD_SDI         =  PORTC.8      ' (I) SPI DI To SD cards  DO pin   
        $define SD_SDO       =  PORTB.9      ' (0) SPI Do To SD cards  DI pin   
        $define SD_CS          =  PORTA.7      ' (0) SPI CS to SD cards  CS pin [CHIP Dectect] (active low)[Output]
        $define SD_Power     =  PORTA.8      ' Enable/Disable the SD card's VDD (active low)
        Symbol Card_Dete    =  PORTC.7      ' (I) SD CARD Detect [Low Card IN, High Card OUT] [Input]



'=======================================================================================
' Set up the Include Files
'---------------------------------------------------------------------------------------
       
        Include "SPI_24.inc"                                            ' Load the PIC24 SPI procedures into the program       
        Include "filesys24.inc"                                         ' Load the FAT file system procedures into the program

'-----------------------------------------------------------------------------------------------------------------------------
' SD Card
'=============================================================================================================================
SD_Card:
   
    If Card_Detect = 0 Then
     DelayMS 10
     High RF_LED
    Else Low RF_LED
    EndIf

    MyFilename = "TEST.csv"                                                       ' "file1.csv" Excel
                 
    If FAT_Init() = cErrOK Then                                                  ' Can we initialise the FAT?
     If File_Exists(MyFilename) = False Then                                     ' Does the file already exist?
      File_Create(MyFilename)                                                    ' No. So create it
      File_Close()                                                               ' Then close it
     EndIf

    If DistFlag = 115 Then                                                   
      If File_Append(MyFilename) = cErrOK Then                                    ' Can we append to an existing file?
      ''  HRSOut "Writing", 13                                                    ' Yes. So transmit a message
      string2Hold = ","                                                           ' (Prints SD CARD ICON),string2Hold = "SD"   
      Print_At(Arial_Symbols,6,50,Str string2Hold,0)                              ' ST7565R Eadog Diaplay
   
 '------------------------------------------------------------------------------------
 ' Write to the file
 '------------------------------------------------------------------------------------
      File_Write "TEST TIME:    ",
      File_Write "TIME: " ,Dec HOURS, " : " ,Dec2 MINUTES ," : " ,Dec2 SECONDS, " "       
      File_Write "   DATE: " ,DATA_STRING_0, DATA_STRING_1," : ", DATA_STRING_2, DATA_STRING_3," : 20", DATA_STRING_4, DATA_STRING_5," "
      File_Write 13                                                             ' Null Terminate File
      File_Close()                                                              ' Close the file
    EndIf                                                                     
' ------------------------------------------------------------------------------------
' Read from the file
'------------------------------------------------------------------------------------
      If File_Open(MyFilename) = cErrOK Then                                     ' Can we open the file?
      While File_tEOF = False                                                    ' Yes. So read until the file is finished
      MyChar = File_Read                                                         ' Read from the file
      ' HRSOut MyChar                                                            ' Transmit what was read from the file
       Print At 2,1, Str MyChar
       string2Print = Str$(Dec MyChar)
       Wend
       File_Close()                                                              ' Close the file
       Else                                                                      ' Otherwise...
      ' HRSOut "Cannot open ", MyFileName, 13                                    ' Transmit an error response
       string2Hold = "Cant Open"
       string2Print = MyFilename + string2Hold
       Print_At(ArialNarrow8,4,5,"SD:" + Str string2Print + "     ",0)
       EndIf
       Else
      ' HRSOut "Cannot append ", MyFileName, 13
       string2Hold = "Cant appd"
       string2Print = MyFilename + string2Hold
       Print_At(ArialNarrow8,4,5,"SD:" + Str string2Print + "     ",0)
       EndIf
       Else                                                                      ' Otherwise...
       ' HRSOut "Cannot initialise SD\r"                                         ' Transmit an error response
       string2Hold = "Cant Int"
       Print_At(ArialNarrow8,4,5,Str string2Hold,0)
      EndIf
 
Return

'--------------------------

Regards
Craig

Nickma

Craig, thanks for the answer.
In your example, the time and date are recorded as data to be written to a file. These data are not ATTRIBUTES of the file. Time and date attributes are created via Global_bMinutes, Global_bHours etc. (see the FileSys.inc file in Includes for Proton24) My attributes are being written, but the data that I am trying to write is not written at all.

Nickma

Hi everyone.
Proton24 SD FAT File System problem.
I'm stumped with writing the attributes of the data file being created. I tried many options, but nothing works.

    Device = 24FJ64GA004
    Declare Xtal = 8
       PORTA = 0: PORTB = 0: PORTC = 0
       TRISA = 0: TRISB = 0: TRISC = 0
    $ define SD_CLK PORTB.13 'SPI CLK to SD card pin5 CLK pin
    $ define SD_SDO PORTB. 14 'SPI DO to SD card pin2 DI pin
    $ define SD_SDI PORTB. 12 'SPI DI to SD card pin7 DO pin
    $ define SD_CS PORTB. 15 'SPI CS to SD card pin1 CS pin
       Include "FileSys24.inc" 'Load the FAT file system
    Declare LCD_Type ALPHA
    Declare LCD_DTPin = PORTB.4
    Declare LCD_RSPin = PORTA.0
    Declare LCD_ENPin = PORTA.1
    Declare LCD_Interface = 4
    Declare LCD_Lines = 4
    Declare LCD_CommandUs = 2000
    Declare LCD_DataUs = 50
      Declare HRSOut1_Pin = PORTB.2
      Declare Hserial1_Baud = 9600 'Set baud rate to 9600
     Dim CR As $ 0D 'Carriage Return
    Dim LF As $ 0A 'Line Feed
    Dim i As Word
    Dim MyFileName As String * 11
      CLKDIV = 0 'CPU peripheral clock ratio set to 1: 1
      Write_OSCCONH (% 00000000) 'Internal OSC 8MHz
       
      PPS_Output (cOut_Pin_RP2, cOut_Fn_U1TX)
  PPS_Output (cOut_Pin_RP13, cOut_Fn_SCK1OUT) 'To SPI peripheral's CLK pin
  PPS_Output (cOut_Pin_RP13, cOut_Fn_SDO1) 'To SPI peripheral's SDO pin
  PPS_Input (cIn_Pin_RP12, cIn_Fn_SDI1) 'From SPI peripheral's SDI pin
  PPS_Input (cIn_Pin_RP15, cIn_Fn_SS1IN) 'SS1 Slave Select Input (SS1IN)
 
            Cls: DelayMS 1500
'************************************************ *************************
Main:
       MyFileName = "VL-101.DAT"
                  Cls
    If FAT_Init () = cErrOK Then 'Can we initialise the FAT?
        If File_Exists (MyFileName) = False Then 'Does the file already exist?
            File_Create (MyFileName) 'No. So create it
            File_Close () 'Then close it
        EndIf
         
        If File_Append (MyFileName) = cErrOK Then 'Can we append to an existing file?
            HRSOut "Writing \ r" 'Yes. So transmit a message
            Print At 2.4, "Writing"
                  GoSub Pause_1000
            File_Write "Integer Data \ r"
            For MyWord = 0 To 6 '\
                File_Write Dec MyWord, "," '| Write ASCII data to the file
            Next '/
            File_Write 13
              Global_bSeconds = 0
              Global_bMinutes = 15
              Global_bHours = 11
              Global_bDay = 12
              Global_bMonth = 11
              Global_bYear = 21
            File_Close () 'Close the file
            HRSOut "Finished Writing \ r"
            Print At 2,4, "Finished Writing"
                  GoSub Pause_1000
        Else
            HRSOut "Cannot append", MyFileName, 13
            Print At 2,4, "Cannot append"
                  GoSub Pause_1000
        EndIf
    Else 'Otherwise ...
        HRSOut "Cannot initialise SD \ r" 'Transmit an error response
        Print At 2,1, "Cannot initialise SD"
                  GoSub Pause_1000
    EndIf
 End
'************************************************ *************************
 Pause_10: For i = 1 To 10: DelayMS 1: Next i: Return
 Pause_1000: For i = 1 To 1000: DelayMS 1: Next i: Return
 Pause_1500: For i = 1 To 1500: DelayMS 1: Nexti: Return
'************************************************ *************************
'For internal 8MHz oscillator without PLL
'OSC pins are general purpose I / O
   Config Config1 = JTAGEN_OFF, GCP_OFF, BKBUG_OFF, COE_OFF, ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
   Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRC, FCKSM_CSECME, OSCIOFNC_ON, POSCMOD_NONE

As a result, I get: VL-101.DAT 08/01/2021 12:15
moreover, if I change the value of the day or month, then nothing changes. Only the year is recorded correctly.
I ask for help (especially from top204 as the author of the File System)

Wimax

The post is quite old, but I assign all the variables (Global_bSeconds etc.) just before writing to SD and the attributes are correctly saved.

Now I'm trying to reverse the problem...how to send to a serial port the directory list of a SD card with file name, extension AND creation date & creation time ?

Nickma

Hello Wimax. Can you provide a fragment of your program for recording data on an SD Card. I'm interested in where in the program you assign all the variables (Global_bSeconds etc.)

Wimax

Hello Nickma,

My date & time info come from an RTC: RTC_Day, RTC_Month, RTC_Year  and so on. I assign these variables to Global_bDay, Global_bMonth etc within FileSys24.inc library.
I modified FileSys24.inc as follows:

'--------------------------------------------------------------------------------------------------------------------------
' Set modified time & date for file
' Input     : Global variables contain the date and time
' Return    : pSectorPos
' Notes     : None
'
Proc FAT_SetFileTimeModified(pSectorPos As Word)

 '***************  ADDED ***************
 '**************************************
 
Global_bDay=RTC_Day 
Global_bMonth=RTC_Month 
Global_bYear=RTC_Year 

Global_bHours=RTC_Hour
Global_bMinutes=RTC_Minute
Global_bSeconds=RTC_Second 

    FAT_InsertByteIntoBuffer(pSectorPos, (Global_bSeconds / 2) | (Global_bMinutes << 5))    ' Create time & date - Seconds/Minutes
    Inc pSectorPos
    FAT_InsertByteIntoBuffer(pSectorPos, (Global_bMinutes >> 3) | (Global_bHours << 3))     ' Create time & date - Minutes/Hours
    Inc pSectorPos
    FAT_InsertByteIntoBuffer(pSectorPos, Global_bDay | (Global_bMonth << 5))                ' Create time & date - Day/Month
    Inc pSectorPos
    FAT_InsertByteIntoBuffer(pSectorPos, (Global_bMonth >> 3) | ((Global_bYear + 20) << 1)) ' Create time & date - Month/Year
EndProc

In this way, when I write to SD, the creation date & time are correctly written.
Let me know if this works  ;)


Nickma

Wimax, thank you. I don't have a chance to check right now, but I hope everything will be OK.

wirecut

Leo.
Luck does not exist: there is a moment when talent meets opportunity. SENECA