Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing on file slowly! #47

Open
etoshey opened this issue Mar 31, 2021 · 3 comments
Open

Writing on file slowly! #47

etoshey opened this issue Mar 31, 2021 · 3 comments

Comments

@etoshey
Copy link

etoshey commented Mar 31, 2021

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
Copy link
Owner

djuseeq commented Apr 1, 2021

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
Copy link
Author

etoshey commented Apr 3, 2021

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
Copy link
Owner

djuseeq commented Apr 7, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants