Skocz do zawartości

Problemy z Xiao ESP32 C3 i Adafruit microSD / SDFat Library


Pomocna odpowiedź

Napisano

cześć!

niestety znów muszę poprosić Was o pomoc. Tym razem mam problem z następującą kombinacją sprzętu: SeedStudio Xiao ESP-32 C3 i dedykowana do XIAO nakładka  Adafruit microSD Card BFF Add-On for QT Py and Xiao z biblioteką SdFat - AdaFriut Fork. Poniżej zamieszczam przykładowy kod, który odpalam. Jak nic nie robię to działa dobrze. Dziwne rzeczy zaczynają się gdy w Arduino IDE otwieram i zamykam Serial Monitor. Wtedy Xiao C3 się resetuje. Zapisy w pliku tekstowym to potwierdzają. W innych projektach nie zaobserwowałem takich problemów z Xiao C3. Na potrzeby testów podpiąłem też Adafriud microSD Card do Arduino Giga R1 (tu mała gwiazdka - zamiast SPI, użyłem SPI1 bo w R1 SPI działa w logice 5V, a SPI1 3V3). Na R1 wszystko działa poprawnie. Włączanie i wyłączanie Serial Monitor nie powoduje resetów ani innych dziwnych zachowań.

Macie jakieś pomysły co może być problemem? 

 

// SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT
/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 14 Feb 2023
 by Liz Clark

 This example code is in the public domain.

 */

#include <SPI.h>
//#include <SD.h>
#include "SdFat.h"
SdFat SD;

#define SD_FAT_TYPE 3

// default CS pin is TX for microSD BFF
#define SD_CS_PIN A0

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ;  // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  SdSpiConfig spiConf(A0, DEDICATED_SPI, SD_SCK_MHZ(10), &SPI);


  if (!SD.begin(spiConf)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test_ADA.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    myFile.println("hello bff!");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test_ADA.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

int i = 0;

void loop() {
  // nothing happens after setup
  if (i < 20) {
    Serial.println(i);
    myFile = SD.open("test_ADA.txt", FILE_WRITE);

    // if the file opened okay, write to it:
    if (myFile) {
      Serial.print("LOOP: \t\t Writing to test.txt...");
      myFile.print("zapis ");
      myFile.println(i);
      // close the file:
      myFile.close();
      Serial.println("LOOP: \t\tdone.");
    } else {
      // if the file didn't open, print an error:
      Serial.println("LOOP: \t\terror opening test.txt");
    }
  }
  i++;
  delay(1500);
}

 

dobra, update. Reset jest za każdym razem jak zamknę i uruchomię Serial Monitor w Arduino IDE. Niezależnie od programu i podłączonych peryferiach. Sprawdzone na dwóch C3 oraz jednym S3. Może to być taka przypadłość różnych modeli ESP32?

Nie używam arduino ide, więc nie wiem co tam się dzieje pod maską.

Ale jak to idzie przez wbudowany konwerter usb/uart to pamiętaj że sygnały dtr/rts często używane są do resetowania kontrolera.

Podepnij tylko rx/tx przez jakiś zewnętrzny konwerter. Albo używaj jakiegoś uczciwego terminala (np realterm)

 

Akurat zdaniem twórców IDE "it's not bug, it's feature". Chodziło o to, żeby Arduino po włączeniu monitora startowało od początku. Idea zacna - szczególnie w czasie nauki - ale mogłaby istnieć jakaś wajcha do wyłączania.

Bądź aktywny - zaloguj się lub utwórz konto!

Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony

Utwórz konto w ~20 sekund!

Zarejestruj nowe konto, to proste!

Zarejestruj się »

Zaloguj się

Posiadasz własne konto? Użyj go!

Zaloguj się »
×
×
  • Utwórz nowe...