Anyone have success with CH376 USB flash drive host board?

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to write to USB flash drives.  I would love for it to be easy and not put too much load on a M328.  I have a CH376-based board.  It turns out that the factory documentation is rather poor, and it is hard to tell what it takes exactly to get it to work.  I have found some examples on the net, but they are either incomplete, or for interfacing with SPI or parallel.  To reduce pin count, I am looking to use the serial interface.

 

I have had success in recognizing that a flash disk is attached, and I can write valid data to the file.  I can close the file, and a computer can read the file properly.

 

But.... the best I can manage is write 127 bytes at a time.  I THINK the CH376 is capable of at least 255 at a time, and I THINK that you should be able to tell it to expect more than that because I think you can send 2 bytes (16 bit integer) as the number to expect.

 

But when I tell it anything over 127 byes it fails to write.

 

I certainly could break up my data into 127 byte chunks, but that would be more of a PITA.

 

Does anybody have suggestions or a solution?

 

-Tony

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suppose you will have to live with that, making it work is already an achievement. I took a look at the datasheet; it's not the worst chenglish I've ever seen, but it's still quite confusing...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

making it work is already an achievement

 

Well, I started with an example I found online written in 2015, and nothing appears newer that does better.  But that person also was crippled by having to make guesses about what to do.  Other sources discussing parallel interface mention bugs or inconsistencies in it operation.

 

One thing that I found is that I can only tell the CH386 to expect up to 127 bytes.  An 8 bit value is passed so it OUGHT to be able to accept up to 255, but this does not seem to work.  The code that works with a 127 byte transfer fails with even one more byte.  And it seems as if it might have been intended to be able to tell it a 16 bit value of bytes to expect in the transfer because there is another byte (always 0x00) that follows the first, functional, byte.  And the datasheet seems to indicate that it expects a 16 bit value.  Appears to be a bug with how the serial interface works on the chip.

 

I would consider the parallel or SPI interface to the CH376, but for this particular application I need to have as few pins as possible.  I am using it on a M328 (Arduino), and I am already using 16 pins for an external device interface (8 parallel data pins, and 8 other handshaking/signaling pins.  So, I am running out! 

 

I may end up piggybacking the CH376 onto the hardware serial pins, shared with the USB chip for programming the Arduino).  That would free up 2 pins used for software driven serial.

 

I just can't see how this CH376 chip can be a commercial success.  Over many years, there are no resources on the 'net  demonstrating a fully functional interface.  I can only see "examples" that are partially non-functional.  Once I get this project working well then I will post it to github.

 

I am still keeping my eyes and ears open for examples of fully functional CH376 serial interfacing.

 

-Tony

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi -

I realize that this post is old but I am curious how you  ended up making out with your project. 

A couple of years ago, I designed a commercial boot loader around this chip for the Xmega128 controller using the SPI interface.  I agree that it was a challenge with the datasheet but I worked out my issues and the result turned out just fine.  My only issue as of late is that I have come across certain USB sticks that will not work properly and am challenged as to why. 

 

I would like to correspond regarding the use of this chip and would be willing to share what I know.

take care -

Jim

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PITA is the name of the game in embedded-systems design.

 

If your Mega328 is filled you might be able to use an I2C-to-Input_Output_Ports IC like the Texas Instruments PCF8575 to expand the number of pins available.

 

I haven't heard of this IC before.  There is one module board available on eBay cheaply: https://www.ebay.com/itm/CH376S-...

Is it worth a few dollars to get one and experiment with it? Can you interface to a flash drive with an Arduino using this module board?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi. I wrote a library for this module, feel free to try it out and let me know if you have any problems with it. Thanks

Ch376

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check out the library I wrote for the CH376 IC to work as  USB Host. The library has most if not all the issues you mention solved and has other features. Although it was written using the Atmel Studio 7 IDE in C++. It can be adapted to other IDEs and MCU architectures with little or no modification. Go here to get it and give feedback to help me improve the library's functionality.

https://github.com/BoltSwith/CH376_Library_Cpp

If the facts don't fit the theory, change the facts. ALBERT EINSTEIN

Last Edited: Thu. Oct 10, 2019 - 01:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Spamiam wrote:

making it work is already an achievement

 

Well, I started with an example I found online written in 2015, and nothing appears newer that does better.  But that person also was crippled by having to make guesses about what to do.  Other sources discussing parallel interface mention bugs or inconsistencies in it operation.

 

One thing that I found is that I can only tell the CH386 to expect up to 127 bytes.  An 8 bit value is passed so it OUGHT to be able to accept up to 255, but this does not seem to work.  The code that works with a 127 byte transfer fails with even one more byte.  And it seems as if it might have been intended to be able to tell it a 16 bit value of bytes to expect in the transfer because there is another byte (always 0x00) that follows the first, functional, byte.  And the datasheet seems to indicate that it expects a 16 bit value.  Appears to be a bug with how the serial interface works on the chip.

 

I would consider the parallel or SPI interface to the CH376, but for this particular application I need to have as few pins as possible.  I am using it on a M328 (Arduino), and I am already using 16 pins for an external device interface (8 parallel data pins, and 8 other handshaking/signaling pins.  So, I am running out! 

 

I may end up piggybacking the CH376 onto the hardware serial pins, shared with the USB chip for programming the Arduino).  That would free up 2 pins used for software driven serial.

 

I just can't see how this CH376 chip can be a commercial success.  Over many years, there are no resources on the 'net  demonstrating a fully functional interface.  I can only see "examples" that are partially non-functional.  Once I get this project working well then I will post it to github.

 

I am still keeping my eyes and ears open for examples of fully functional CH376 serial interfacing.

 

-Tony

 

 

Check out the library I wrote for the CH376 IC to work as  USB Host. The library has most if not all the issues you mention solved and has other features. Although it was written using the Atmel Studio 7 IDE in C++. It can be adapted to other IDEs and MCU architectures with little or no modification. Go here to get it and give feedback to help me improve the library's functionality.

https://github.com/BoltSwith/CH376_Library_Cpp

If the facts don't fit the theory, change the facts. ALBERT EINSTEIN