djuseeq / Ch376msc

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

CH376 on Raspberry Pico RP2040 #90

Open roboticboyer opened 4 hours ago

roboticboyer commented 4 hours ago

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 commented 3 hours ago

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
}