Menu

CH376 File system chip demo

mmotte
2021-03-18
2023-10-26
  • mmotte

    mmotte - 2021-03-18

    Attached is a demo program putting the CH376 chip through it's paces. The chip communicates with the PIC using serial com port and is able to do SPI and parallel but not in this demo. The board is a china module that has a socket for your USB flash drive and cost 3-5$. Documentation for this chip is sparse and pretty cryptic with some chinglish. This has been adapted to GCB from arduino module written by Scott C and I thank him for making this possible. My goal was to be able to datalog with it.

    The Pic chip I chose was the 18F25K80 because it had 2 usart serial ports. Port 1 talks to the CH376, Port 2 talks to the PC to send commands and receive messages,data,errors. Port1 is implemented with a ring buffer that uses the serial interrupt.

    ' This is a limit functionality : write ,read and append
    ' does not have file time and date
    ' does not have directory
    ' does not do sub dir
    ' to use in your program you would comment out the do loop and put your program in place
    ' use the 3 subs :
    ' sub writeFile( fileName as string, data as string)
    ' sub appendFile( fileName as string , data as string)
    ' sub readFile( fileName as string) which needs to be modified to bring the data out. It prints to the console right now.

    There are many other subs but these 3 would be what a user would need.

    The last big problem was lost data writing when crossing 256,512, 1024 thresholds. This has been solved.

    Hope this inspires someone.

    '

     
  • Anobium

    Anobium - 2021-03-18

    Cool. I will give this a try next week. Too much on this week!

    :-)

     
  • mmotte

    mmotte - 2021-03-19

    I forgot to mention the Big advantage is you can unplug the flash drive and plug it in your PC . No additional fiddling around with download programs and such.

    So this morning I added a DS18B20 to the board and added a Logger code to the Main menu.
    Start up I needed to create the "Test4.txt" with a '4' sent from the terminal and then put it into logger mode with a 'L' from the console. So every 2 sec it logs a time from a crude RTC, with comma separating the Temperature, the temperature is next, followed by an enter(0X0D,0X0A).
    That complete "record" is written to the flash drive. I am excited! been trying to do that for couple years off and on.

     

    Last edit: mmotte 2021-03-19
  • William Roth

    William Roth - 2021-03-19

    This could be quite useful.

     
  • mmotte

    mmotte - 2023-10-26

    Just be aware CH376S_V3_17.gcb fails with the newest usart.h . It compiles, loads and locks up after first terminal entry on usart2. I tried an older usart.h and it runs fine. i am investigating.

     
  • mmotte

    mmotte - 2023-10-26

    Found the error in the current usart.h file
    Line 2100 #ifdef Var(RCREG2)

    Logic is wrong . Never gets to the else statement
    I broke it up to 2 if statements
    It works now

     
  • Anobium

    Anobium - 2023-10-26

    OK. I need to resolve in the master build.

    Can you upload your adpated USART.H ? thanks.

     
  • Anobium

    Anobium - 2023-10-26

    Do not upload. I found the issue. There were typos.

    Lines 1655 and 2101. In both cases the conditional check was not checking if a register existed but it checked the value.... err... the conditional check needs to check the register existed.

    Please use the attached, test to confirm resolution.

    This error was introduced on 10 Aug 2023.. by me. Sorry!

     
  • Anobium

    Anobium - 2023-10-26

    This issue was a really good case for the CDF file. The CDF showed the conditional compilation was not working as expected. This is how I found the issue.

    This is a post on using the project CDF file

    The issue was the program was not operating as expected and the ASM showed the creation of a variable called RC2REG

    The CDF contains the operations of the compiler.

    The section we are interested in started at line 2064. The use of USART2.

    This shows the correct register being used on line 2102 of the new USART.H

              2064: CASE 2
              2098: #IFDEF VAR(RCREG2)
              ;Get a byte from register, if interrupt flag is valid
              ;If USART2HasData Then
              2100: IF USART2HASDATA THEN
              2101: #IFDEF VAR(RCREG2) THEN
              ;SerData = RCREG2
              2102: SERDATA = RCREG2
    

    in the original USART.H/CDF is showed this

              2103: #IFNOT VAR(RCREG2) THEN
              ;SerData = RC2REG
              2104: SERDATA = RC2REG
    

    For line 2104 to be present means the register RCREG2 did not exist in the DAT file. But, register RCREG2 did exist.... so, I started to look for a typo/miscoding error. :-(

    Hope this short insight help understand how useful the CDF can expose the compiler operations.

     
  • mmotte

    mmotte - 2023-10-26

    Anobium,

    I think this is still not quite right? Extra stuff not needed.

     #ifdef Var(RCREG2)
              'Get a byte from register, if interrupt flag is valid
              If USART2HasData Then
                #IFDEF var(RCREG2) Then
                  SerData = RCREG2
                #ELSE
                  SerData = RC2REG
                #ENDIF
              End if
            #endif
    

    Back in lines 2071-2086 you did RC2REG so why is it here again and actually will never be executed because the #ELSE won't exist if RCREG2 don't exist. I know this is confusing, moving the 2 around.

     
  • Anobium

    Anobium - 2023-10-26

    Great spot. Best to get this as clean as practical.

    I will change to this.

    Does this look ok? and, does it work? nothing like a real test.

            #ifdef Var(RCREG2)
              'Get a byte from register, if interrupt flag is valid
              If USART2HasData Then
                  SerData = RCREG2
              End if
            #endif
    
     
  • mmotte

    mmotte - 2023-10-26

    Looks good! Works good!

    Now I am back on track making a data logger for radio astronomy.

    Thanks for all your time! I don't know how you do it concentrating on one thing GCB. It is a good project and you recently have new interest.

    BR
    Mike

     
    • Anobium

      Anobium - 2023-10-26

      I am renewed.

      Angel is my saviour. His new packaging, IDE and releasing make my work so easy.


      You get busy!!!


      Please as always.

       

Log in to post a comment.