djuseeq / Ch376msc

Arduino library for CH376 mass storage contoller
MIT License
75 stars 17 forks source link

Writing on file slowly! #47

Open etoshey opened 3 years ago

etoshey commented 3 years ago

Hi, Thanks for your useful library. I am trying to write my sensors data on file, but there is a long delay after each writing block (256 bytes), So I have to wait for the next ready(Done) from Ch376 for more than 3 milliseconds. How much is the maximum speed for writing a file?

best regards.

djuseeq commented 3 years ago

Hi, thanks. What communication interface you use? If its serial then you can choose a higher baud rate(up to 115200), in case of using SPI the default speed is low (125kHz) in sake of stability if e.g. using long cables on a breadboard , but you can use these function-like macros when creating an object : (in case of Arduino with 16MHz Sys Clock, the maximum value can be 8MHz, but on this speed the communication it can become unreliable.Try with short wires) SPI_SCK_KHZ( ) or SPI_SCK_MHZ( ) . E.g.

Ch376msc flashDrive( 10, SPI_SCK_MHZ(2) ); // CS pin, com speed
// or
Ch376msc flashDrive( 10, 9, SPI_SCK_MHZ(2) );// CS pin, INT pin, com speed

In addition, the module also needs some time to save the data stored in the buffer to the USB drive. Have you tried with another flash-drive or to format the drive with external software . To be easy to implement for Arduino, the library use blocking functions (wait for answer from module)

etoshey commented 3 years ago

Thanks for your reply. I have done all of them. I am using SPI communication with 12MHZ SCK and every 128 bytes is written at 4 milliseconds. Is it normal?

djuseeq commented 3 years ago

Yes, that is normal ,we have to wait with the next command until the CH376 finish with file writing otherwise data loss will occur. The chip will inform the MCU when is ready to receive the next command or data. The most time consuming part is when writing continuously and the CH376 internal buffer(512byte) is filled up, then the chip require longer time to do some internal processes, this is much depends on the usb-drive used. Here you can find more details about the drives i have been used. 2GB no name drive, worst case is more than 91 ms waiting for the module. Screenshot_20210407_114339

32GB PNY, worst case is 3.5 ms waiting for the module. Screenshot_20210407_114506