Stufin
Home Quick Cart Profile

CH376 USB Host Interface Module Flash Disk Drive RW Module

Buy Now

Pin Configuration

  • CH376 USB Host Interface Module Flash Disk Drive RW Module Pinout
  • The CH376 USB Host Interface Module Flash Disk Drive RW Module is a versatile component that enables microcontrollers to read and write data to USB flash drives. This module features a compact design and is compatible with various microcontrollers. Here's a detailed explanation of each pin and how to connect them:
  • Pinout Structure:
  • The module has a total of 10 pins, which are arranged in two rows of 5 pins each.
  • Top Row ( Left to Right ):
  • 1. VCC (Power Supply):
  • Description: Power supply pin for the module.
  • Connection: Connect to a 5V power source (e.g., a microcontroller's VCC pin or a power supply module).
  • 2. GND (Ground):
  • Description: Ground pin for the module.
  • Connection: Connect to the ground pin of the power source or the microcontroller's GND pin.
  • 3. D- (USB Data-):
  • Description: Negative data line for USB communication.
  • Connection: Connect to the D- pin of a USB port or a USB connector.
  • 4. D+ (USB Data+):
  • Description: Positive data line for USB communication.
  • Connection: Connect to the D+ pin of a USB port or a USB connector.
  • 5. RST (Reset):
  • Description: Reset pin for the module.
  • Connection: Connect to a digital output pin of the microcontroller, which is used to reset the module.
  • Bottom Row ( Left to Right ):
  • 1. CS (Chip Select):
  • Description: Chip select pin for the module.
  • Connection: Connect to a digital output pin of the microcontroller, which is used to select the module.
  • 2. CLK (Clock):
  • Description: Clock pin for the module.
  • Connection: Connect to a digital output pin of the microcontroller, which provides the clock signal.
  • 3. MISO (Master In Slave Out):
  • Description: Data output pin for the module.
  • Connection: Connect to a digital input pin of the microcontroller, which receives data from the module.
  • 4. MOSI (Master Out Slave In):
  • Description: Data input pin for the module.
  • Connection: Connect to a digital output pin of the microcontroller, which sends data to the module.
  • 5. INT (Interrupt):
  • Description: Interrupt pin for the module.
  • Connection: Connect to a digital input pin of the microcontroller, which is used to detect interrupts from the module.
  • Connection Example:
  • Here's an example of how to connect the CH376 module to an Arduino Uno microcontroller:
  • VCC -> Arduino Uno's 5V pin
  • GND -> Arduino Uno's GND pin
  • D- -> USB connector's D- pin
  • D+ -> USB connector's D+ pin
  • RST -> Arduino Uno's digital pin 2
  • CS -> Arduino Uno's digital pin 10
  • CLK -> Arduino Uno's digital pin 13
  • MISO -> Arduino Uno's digital pin 12
  • MOSI -> Arduino Uno's digital pin 11
  • INT -> Arduino Uno's digital pin 3
  • Note: Make sure to check the specific pinouts and connection requirements for your microcontroller and USB connector, as they may vary.

Code Examples

CH376 USB Host Interface Module Flash Disk Drive RW Module Documentation
Overview
The CH376 USB Host Interface Module Flash Disk Drive RW Module is a USB interface module that allows microcontrollers to read and write data to USB flash drives. This module is based on the CH376 chip, which is a USB host controller that supports USB 1.1 and 2.0 specifications.
Pinouts and Connections
The module has the following pinouts:
VCC: Power supply (3.3V or 5V)
 GND: Ground
 CS: Chip select (active low)
 SCK: Clock signal
 MOSI: Master out, slave in (data transmission)
 MISO: Master in, slave out (data reception)
 INT: Interrupt signal
 D+: USB differential signal
 D-: USB differential signal
Communication Protocol
The CH376 module communicates with the microcontroller using a SPI protocol. The module acts as a slave device, and the microcontroller acts as the master device.
Example Code
Example 1: Reading a File from a USB Flash Drive using Arduino
This example demonstrates how to use the CH376 module to read a file from a USB flash drive using an Arduino board.
```c++
#include <SPI.h>
#define CH376_CS 10  // Chip select pin
#define CH376_INT 2  // Interrupt pin
void setup() {
  Serial.begin(9600);
  pinMode(CH376_CS, OUTPUT);
  pinMode(CH376_INT, INPUT);
  SPI.begin();
}
void loop() {
  // Initialize the CH376 module
  digitalWrite(CH376_CS, LOW);
  SPI.transfer(0x57);
  SPI.transfer(0x03);
  digitalWrite(CH376_CS, HIGH);
// Wait for the USB flash drive to be recognized
  while (digitalRead(CH376_INT) == LOW) {
    delay(1);
  }
// Open a file on the USB flash drive
  char filename[] = "example.txt";
  uint8_t buffer[256];
  int bytesRead = 0;
  digitalWrite(CH376_CS, LOW);
  SPI.transfer(0x57);
  SPI.transfer(0x04);
  digitalWrite(CH376_CS, HIGH);
  while (bytesRead < 256) {
    digitalWrite(CH376_CS, LOW);
    SPI.transfer(0x57);
    SPI.transfer(0x01);
    for (int i = 0; i < 256; i++) {
      buffer[i] = SPI.transfer(0x00);
    }
    digitalWrite(CH376_CS, HIGH);
    bytesRead += 256;
  }
// Print the file contents
  for (int i = 0; i < bytesRead; i++) {
    Serial.print(buffer[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}
```
Example 2: Writing Data to a USB Flash Drive using Raspberry Pi (Python)
This example demonstrates how to use the CH376 module to write data to a USB flash drive using a Raspberry Pi board.
```python
import spidev
import RPi.GPIO as GPIO
# Initialize the SPI interface
bus = 0
device = 0
spi = spidev.SpiDev()
spi.open(bus, device)
spi.max_speed_hz = 1000000
# Initialize the GPIO interface
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)  # Chip select pin
GPIO.setup(23, GPIO.IN)  # Interrupt pin
# Initialize the CH376 module
GPIO.output(17, GPIO.LOW)
spi.xfer2([0x57, 0x03])
GPIO.output(17, GPIO.HIGH)
# Wait for the USB flash drive to be recognized
while GPIO.input(23) == GPIO.LOW:
    time.sleep(0.1)
# Open a file on the USB flash drive
filename = "example.txt"
data = bytearray("Hello, World!", 'utf-8')
# Write data to the file
GPIO.output(17, GPIO.LOW)
spi.xfer2([0x57, 0x04])
for byte in data:
    spi.xfer2([0x57, 0x01, byte])
GPIO.output(17, GPIO.HIGH)
```
Example 3: Enumerating USB Devices using ESP32 (C++)
This example demonstrates how to use the CH376 module to enumerate USB devices using an ESP32 board.
```c++
#include <WiFi.h>
#include <SPI.h>
#define CH376_CS 5  // Chip select pin
#define CH376_INT 18  // Interrupt pin
SPIClass spi = NULL;
void setup() {
  Serial.begin(115200);
  pinMode(CH376_CS, OUTPUT);
  pinMode(CH376_INT, INPUT);
  spi = new SPIClass(VSPI);
  spi->begin();
  spi->setFrequency(1000000);
}
void loop() {
  // Initialize the CH376 module
  digitalWrite(CH376_CS, LOW);
  spi->transfer(0x57);
  spi->transfer(0x03);
  digitalWrite(CH376_CS, HIGH);
// Wait for the USB device to be enumerated
  while (digitalRead(CH376_INT) == LOW) {
    delay(1);
  }
// Get the device count
  uint8_t deviceCount = 0;
  digitalWrite(CH376_CS, LOW);
  spi->transfer(0x57);
  spi->transfer(0x05);
  deviceCount = spi->transfer(0x00);
  digitalWrite(CH376_CS, HIGH);
// Print the device list
  for (int i = 0; i < deviceCount; i++) {
    digitalWrite(CH376_CS, LOW);
    spi->transfer(0x57);
    spi->transfer(0x06);
    uint8_t deviceInfo[8];
    for (int j = 0; j < 8; j++) {
      deviceInfo[j] = spi->transfer(0x00);
    }
    digitalWrite(CH376_CS, HIGH);
    Serial.print("Device ");
    Serial.print(i);
    Serial.print(": ");
    for (int j = 0; j < 8; j++) {
      Serial.print(deviceInfo[j], HEX);
      Serial.print(" ");
    }
    Serial.println();
  }
}
```
Note: These examples are for illustration purposes only and may require modifications to work with your specific setup. Ensure that you have the correct pinouts, voltage levels, and communication protocols configured for your application.