'Why does the SparkFunDMX library give me a timer error on ESP32?

I'm trying to get an ESP32 to interface with DMX via the SparkFun EPS32 DMX Shield, but can't get a very basic DMX reading code to work without an error. I am using the Arduino Framework in PlatformIO within VSCode, and the library I'm using to use DMX is SparkFunDMX.

Here is the code I'm using to test:

#include <Arduino.h>
#include <SparkFunDMX.h>

SparkFunDMX dmx;

unsigned long oldTime = 0;

void setup() {
  Serial.begin(115200);
  dmx.initRead(1);
}

void loop() {
  dmx.update();
  if (millis() - oldTime > 2000)
  {
    Serial.println(dmx.read(1));
    oldTime = millis();
  }
}

It compiles, but when I try to run it I get this error in the Serial Monitor:

_drv:0x00,q_E (31) timer_group: timer_init(271): HW TIMER divider outside of [2, 65536] range error
E (31) timer_group: timer_set_counter_value(86): HW TIMER NEVER INIT ERROR
E (35) timer_group: timer_start(97): HW TIMER NEVER INIT ERROR       
E (40) timer_group: timer_enable_intr(380): HW TIMER NEVER INIT ERROR
E (46) timer_group: timer_get_config(327): HW TIMER NEVER INIT ERROR 
E (52) timer_group: timer_get_alarm_value(167): HW TIMER NEVER INIT ERROR 
E (59) timer_group: timer_isr_callback_add(225): HW TIMER NEVER INIT ERROR
E (65) timer_group: timer_set_alarm_value(155): HW TIMER NEVER INIT ERROR
E (72) timer_group: timer_set_auto_reload(132): HW TIMER NEVER INIT ERROR
E (79) timer_group: timer_set_alarm(179): HW TIMER NEVER INIT ERROR

After this, it prints to the Serial Monitor every 2 seconds as the code is written to do.

It's also worth noting 2 things:

  1. That I'm not using the SparkFun ESP32 Thing Plus that the shield is designed for, but rather a standard ESP32 devkit v1 module. I looked at the pinout of both of the ESP32s and the PCB file for the shield to find the relevant pins and have connected them with jumper cables.
  2. I unfortunately don't have active access to a device that can send DMX, but the last time I tested this I encountered this issue.

I don't think either of these things should have an effect on this specific problem as it seems like a strictly code issue at this point.

After some looking at the source code for the library I figured out that it was a problem with this block of code in initializing the DMX reading (specifically the first four lines at the top regarding the timer):

void SparkFunDMX::initRead(int chanQuant) {
    
  timer = timerBegin(0, 1, true);
  timerAttachInterrupt(timer, &onTimer, true);
  timerAlarmWrite(timer, 320, true);
  timerAlarmEnable(timer);
  _READWRITE = _READ;
  if (chanQuant > dmxMaxChannel || chanQuant <= 0) 
  {
    chanQuant = defaultMax;
  }
  chanSize = chanQuant;
  pinMode(13, OUTPUT);
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW);
  pinMode(rxPin, INPUT);
}

After a lot of looking around at other forums and problems I believe it may have an issue with not clearing the interrupt with this function, but that's only a guess at this point. I couldn't get any of it to work with what I have now.

void timer_group_clr_intr_status_in_isr(timer_group_t *group_num*, timer_idx_t *timer_num*)

Thanks for the help to anyone who responds and I hope this can help others with a similar issue.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source