GIGA R1 démarrage aléatoire du programme

bonjour,

bonjour,

le programme fonctionne très bien quand il démarre!

je rencontre le souci suivant :

j'alimente par la broche Vin en 13v
le programme démarre et fonctionne très bien.
j'éteins l'alimentation de laboratoire
je reviens 3 jours plus tard
je mets en route l'alimentation --> rien ne se passe
j'éteins et je rallume --> le programme fonctionne

pas de chute de tension lorsque le programme ne fonctionne pas

si vous avez des idées

merci

#include <Arduino_AdvancedAnalog.h>
#include <DigitalOut.h>
#include <Arduino_USBHostMbed5.h>
#include <FATFileSystem.h>

const int inBouttonA = 20; 
int BouttonA;

AdvancedDAC dac0(A12);
USBHostMSD msd;
mbed::FATFileSystem usb("AUDIO");
FILE *file = nullptr;
int sample_size = 0;
int samples_count = 0;
int swapFile;

void setup() {
pinMode(inBouttonA, INPUT_PULLUP);
  Serial.begin(115200);
  while (!Serial);

  pinMode(PA_15, OUTPUT);
  digitalWrite(PA_15, HIGH);

  Serial.println("Please connect a USB stick to the GIGA's USB port ...");
  while (!msd.connect()) delay(100);

  Serial.println("Mounting USB device ...");
  int const rc_mount = usb.mount(&msd);
  if (rc_mount) {
    Serial.print("Error mounting USB device ");
    Serial.println(rc_mount);
    return;
  }
  configFile();
  Serial.println("configfile setup");
}

void loop() {
 BouttonA = digitalRead(inBouttonA);

//Serial.println("debut loop"); 
  if (dac0.available() && !feof(file)) {
    /* Read data from file. */
    uint16_t sample_data[256] = { 0 };
    fread(sample_data, sample_size, 256, file);

    /* Get a free buffer for writing. */
    SampleBuffer buf = dac0.dequeue();

    /* Write data to buffer. */
    for (size_t i = 0; i < buf.size(); i++) {
      /* Scale down to 12 bit. */
      uint16_t const dac_val = ((static_cast<unsigned int>(sample_data[i]) + 32768) >> 4) & 0x0fff;
      buf[i] = dac_val;
    }

    /* Write the buffer to DAC. */
    dac0.write(buf);

    if(feof(file)){
Serial.println("avant close");      
      fclose(file);
      Serial.println("après close");
      //configFile();
     
      
    }
  }

  //int BouttonAlerte = digitalRead(53);

  if (BouttonA == LOW) {
    Serial.println("appui sur bouton");
    delay(1000);
    file = fopen("/AUDIO/Track004.wav", "rb");
//swapFile == 1;
//swapFile = swapFile + 1;
    //swapFile = swapFile + 1;
    //if (swapFile == 4) {
     // swapFile = 0;
    //}
    delay(500);
    configFile();
    Serial.println("configfile bouton ok");
    return;
  }
  
}


void configFile() {
  Serial.println("Opening audio file ...");
  /* 16-bit PCM Mono 16kHz realigned noise reduction */
  //if (swapFile == 0) {
   // file = fopen("/AUDIO/Track010.wav", "rb");
  //} 
  //if (swapFile == 1) {
   // file = fopen("/AUDIO/Track001.wav", "rb");
  //} 
  //else if (swapFile == 2) {
  //  file = fopen("/usb/BASS.wav", "rb");
  //} else if (swapFile == 3) {
    //file = fopen("/usb/SHAKE.wav", "rb");
  //}

  if (file == nullptr) {
    Serial.print("Error opening audio file: ");
    Serial.println(strerror(errno));
    return;
  }

  Serial.println("Reading audio header ...");
  struct wav_header_t {
    char chunkID[4];              //"RIFF" = 0x46464952
    unsigned long chunkSize;      //28 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes] + sum(sizeof(chunk.id) + sizeof(chunk.size) + chunk.size)
    char format[4];               //"WAVE" = 0x45564157
    char subchunk1ID[4];          //"fmt " = 0x20746D66
    unsigned long subchunk1Size;  //16 [+ sizeof(wExtraFormatBytes) + wExtraFormatBytes]
    unsigned short audioFormat;
    unsigned short numChannels;
    unsigned long sampleRate;
    unsigned long byteRate;
    unsigned short blockAlign;
    unsigned short bitsPerSample;
  };

  wav_header_t header;
  fread(&header, sizeof(header), 1, file);

  Serial.println("WAV File Header read:");
  char msg[64] = { 0 };
  snprintf(msg, sizeof(msg), "File Type: %s", header.chunkID);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "File Size: %ld", header.chunkSize);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "WAV Marker: %s", header.format);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Format Name: %s", header.subchunk1ID);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Format Length: %ld", header.subchunk1Size);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Format Type: %hd", header.audioFormat);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Number of Channels: %hd", header.numChannels);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Sample Rate: %ld", header.sampleRate);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Sample Rate * Bits/Sample * Channels / 8: %ld", header.byteRate);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Bits per Sample * Channels / 8: %hd", header.blockAlign);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Bits per Sample: %hd", header.bitsPerSample);
  Serial.println(msg);

  /* Find the data section of the WAV file. */
  struct chunk_t {
    char ID[4];
    unsigned long size;
  };

  chunk_t chunk;
  snprintf(msg, sizeof(msg), "id\t"
                             "size");
  Serial.println(msg);
  /* Find data chunk. */
  while (true) {
    fread(&chunk, sizeof(chunk), 1, file);
    snprintf(msg, sizeof(msg), "%c%c%c%c\t"
                               "%li",
             chunk.ID[0], chunk.ID[1], chunk.ID[2], chunk.ID[3], chunk.size);
    Serial.println(msg);
    if (*(unsigned int *)&chunk.ID == 0x61746164)
      break;
    /* Skip chunk data bytes. */
    fseek(file, chunk.size, SEEK_CUR);
  }

  /* Determine number of samples. */
  sample_size = header.bitsPerSample / 8;
  samples_count = chunk.size * 8 / header.bitsPerSample;
  snprintf(msg, sizeof(msg), "Sample size = %i", sample_size);
  Serial.println(msg);
  snprintf(msg, sizeof(msg), "Samples count = %i", samples_count);
  Serial.println(msg);
  

  /* Configure the advanced DAC. */
  if (!dac0.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16)) {
    Serial.println("Failed to start DAC1 !");
    return;
  }
}
  • qu'est-ce qui est connecté à l'arduino ?

  • est-ce que vous avez le même comportement si le code chargé est juste "blink" ?

  • faut il vraiment attendre les 3 jours ?

bonjour,

une alim de laboratoire
des boutons en input
et des leds en output
une clé usb
un jack stéréo

non pas trois jours, parfois dans l'heure qui suit ou deux heures après, c est aléatoire.

testé avec deux cartes neuves
non blink fonctionne

merci

je n'ai pas de Giga pour tester mais si vous n'utilisez pas Arduino_USBHostMbed5, avez vous le souci ?

il semble qu'il y ait des bugs liés au MEGA

merci , je vais tout ca et vous tiens au jus

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.