B4R Question Timer interrupts in B4R?

positrom2

Active Member
Licensed User
I am asking this since the Arduino-IDE up to the recent one (1.8.9) has a serious problem (a bug, at least for me) with the UNDO function, screwing up the code when used, occasionally, so it can't be used.
https://forum.arduino.cc/index.php?topic=609254.0
So I consider to come back to B4R...
I am using the ESP32. In the Arduino-IDE, I am using a timer-interrupt to get a position reading as fast as possible from a sensor attached to SPI (50µs works at present), so the void loop (almost) always knows the position and can react on that.
B4X:
void IRAM_ATTR onTimer() {
  portENTER_CRITICAL_ISR(&timerMux);
  digitalWrite(CSB, LOW);
  SPI.transfer(0xA1);
  dataLSB = SPI.transfer(0x00);
  digitalWrite(CSB, HIGH);
  digitalWrite(CSB, LOW);
  SPI.transfer(0xA2);
  dataMSB = SPI.transfer(0x00);
  digitalWrite(CSB, HIGH);
  position = (dataMSB << 8) | (dataLSB);
  position = (position >> 6)-90;
  dacWrite(DAC_Channel_1, position);
  portEXIT_CRITICAL_ISR(&timerMux);
  // Give a semaphore that we can check in the loop
  //  xSemaphoreGiveFromISR(timerSemaphore, NULL);
  // It is safe to use digitalRead/Write here if you want to toggle an output
}
I read that interrupts are not implemented in B4R,(?).
Would the use of the timers in B4R be equivalent to using the timer interrupts in the Arduino-IDE?
 

Erel

Administrator
Staff member
Licensed User

positrom2

Active Member
Licensed User
Thank you, I will see.
But please help me (after two years coming back to B4R):
I have an older project, containing, e.g. "Private ssd As AdafruitSSD1306"
That line displays as usual (but compiling throws a lot of errors).
Adafruit_SSD1306::begin(uint8_t, uint8_t, bool)':
Adafruit_SSD1306.cpp:178:17: error: cannot convert 'volatile uint32_t* {aka volatile unsigned int*}' to 'PortReg* {aka volatile unsigned char*}' in assignment
csport = portOutputRegister(digitalPinToPort(cs));
Now I make a new project by
"File, New, pasting the old code into the new project, and saving in the same directory as the old one.
But there "ssd As AdafruitSSD1306" and references to "ssd.GFX" are underlined in red and "ssd" is posted as "Undeclared variable".
Why are statements like "ssd As AdafruitSSD1306" recognized in the old code but not in the same code pasted in a new project?
 
Top