Ch376msc icon indicating copy to clipboard operation
Ch376msc copied to clipboard

CH376 on Raspberry Pico RP2040

Open roboticboyer opened this issue 1 year ago • 1 comments

CH376 works on Raspberry Pico RP2040 using SPI, connecting also INT pin I've tried with the UART (HW and SW) but the connection doesn't always work (to be better investigated why)

roboticboyer avatar Oct 26 '24 07:10 roboticboyer

This is my example code

#include <Ch376msc.h>
//..............................................................................................................................
// Connect to SPI port: MISO, MOSI, SCK
#define pin_SCK 2
#define pin_MOSI 3 //SPI_Tx
#define pin_MISO 4 //SPI_Rx
#define pin_CS 5
#define pin_INT 8

// use this if no other device are attached to SPI port(MISO pin used as interrupt)
//Ch376msc flashDrive(pin_CS); // chipSelect
//If the SPI port shared with other devices e.g SD card, display, etc. remove from comment the code below and put the code above in a comment
Ch376msc flashDrive(pin_CS, pin_INT); // chipSelect, interrupt pin


void setup() {
   // initialize digital pin 13 as an output.
  pinMode(LED_BUILTIN, OUTPUT);
    Serial.begin();
#ifdef DEBUG_SERIAL
  while (!Serial){} //to see Serial messages of the Setup after boot
#endif

  digitalWrite(LED_BUILTIN, HIGH);
  Serial.println("Setup");
delay(1000); 
 digitalWrite(LED_BUILTIN, LOW); 

SPI.setRX(pin_MISO);
SPI.setCS(pin_CS);
SPI.setSCK(pin_SCK);
SPI.setTX(pin_MOSI);
SPI.begin();
Serial.println("SPI");

  flashDrive.init();
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.println("USB");
  
delay(100); 
while (!flashDrive.pingDevice()){ 
  Serial.print(".");
  delay(100); 
  }
  Serial.println("ok CH376");
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() {
//your code
}

roboticboyer avatar Oct 26 '24 07:10 roboticboyer