khoih-prog/ESP32TimerInterrupt

1k sampling

i17brn opened this issue · 1 comments

I can't generate 1k sampling code, in order to fill a buffer with accelerometer data, I am trying to do in a ESP32, there is a error and the module restart every sec

#include "ESP32TimerInterrupt.h"

#ifndef LED_BUILTIN
#define LED_BUILTIN       2
#endif

String myBuffer[5000];
int pos = 0;

#define TIMER0_INTERVAL_MS 1    //1 sec
#define TIMER1_INTERVAL_MS 5000 //5 sec

ESP32Timer ITimer0(0);
ESP32Timer ITimer1(1);



void IRAM_ATTR TimerHandler0(void) { 
  myBuffer[pos] = String(pos);               
  pos++;                             
}

void IRAM_ATTR TimerHandler1(void) { 
  Serial.println(pos);
  
  pos = 0;
  
  ITimer0.stopTimer();               
  ITimer0.restartTimer();
              
  ITimer1.stopTimer();       
  ITimer1.restartTimer();            
  
  ITimer0.disableTimer();
  ITimer1.disableTimer();
}


void setup() {
  Serial.begin(115200);
  while (!Serial);

  ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS*1000, TimerHandler0);
  ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS*1000, TimerHandler1);
}

void loop() {
  
}

You don't know how to use tricky ISR, and I don't know what you are doing with that kind of messy code.

You need to learn more about ISR in attachinterrupt and many more documents on Internet.

For example, volatile, not to use Serial.print(), delay(), etc.

Please spend more time to research and learn from the problem, and it's professional not to post an issue every time you have just a small issue.

I won't reply and will close any of your new post.