ESP32-POE not working with HSPI class instance

Started by braincurd, April 19, 2023, 01:12:08 PM

Previous topic - Next topic

braincurd

Hello,
I am trying to connect a PAA5100-JE Flow sensor from Pimorini to my Olimex ESP32 POE, but I think there is something not working correctly with HSPI?
Do you have any Suggestions for my Code?:

#include <Arduino.h>
#include <SPI.h>
#include <PAA5100JE.h>

////// SPI FOR SENSOR //////////////////////////////////////////////////////////////////////////////////////
#define HSPI_SCLK 33
#define HSPI_MISO 34
#define HSPI_MOSI 35
#define HSPI_SS 36
SPIClass * hspi = NULL;
////////////////////////////////////////////////////////////////////////////////////////////////////////////

////// SPI FOR PIMORI //////////////////////////////////////////////////////////////////////////////////////
// define SPI chip select pin
#define OF1_CS_PIN 33
// define interrupt motion_ready pin
#define OF1_MOTION_PIN 5

#define PRINT_FREQ 1000 // Define Serial print frequency in Hz

PAA5100JE_OF of1_sensor(OF1_CS_PIN);

unsigned long prev_update_time;
static uint32_t tTime;
double of1_working_height = 31.6; // in mm

// Storing values in counts
int16_t of1_delta_xy[2] = {0, 0};
int16_t of1_xy[2] = {0, 0};

volatile byte readMotion_flag = LOW;

void motionRead()
{
    readMotion_flag = HIGH;
}

void setup()
{
  Serial.println("Setup started!");
  delay(2000);
  Serial.begin(115200);

// SPI ////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////
  // init SPI
  hspi = new SPIClass(HSPI);

hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS);

pinMode(HSPI_SS, OUTPUT); //HSPI SS
  // END SPI ////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////

attachInterrupt(digitalPinToInterrupt(OF1_MOTION_PIN), motionRead, CHANGE);
    if (of1_sensor.init() == false)
    {
        while (true)
        {
            Serial.println("Error in sensors initialization");
        }
    }
    delay(1000);
    // Set sensor working height first.
    // This can be done realtime using distance sensor, if sensor/surface height is changing.
    of1_sensor.setWorkingHeight(of1_working_height);
    // Set X/Y axis orientation.
    of1_sensor.setOrientation(true, false, false);
    delay(5000);
    Serial.println("Test");
}
void loop()
{
    uint32_t t = millis();
    char serRead = Serial.read();
    // Reset values
    if (serRead == 'x')
    {
        //of1_xy[0] = 0;
        of1_xy[1] = 0;
    }
    if (readMotion_flag == HIGH)
    {
        if (of1_sensor.motionRead(of1_delta_xy) == false)
            Serial.println("Error reading sensor values");
        else
        {
            //of1_xy[0] += of1_delta_xy[0];
            of1_xy[1] += of1_delta_xy[1];
            [//Serial.print](notion://serial.print/)("X1: ");
            [//Serial.print](notion://serial.print/)(of1_xy[0]);
            Serial.print(" Y1: ");
            Serial.print(of1_xy[1]);
            Serial.print("\n");
        }
        readMotion_flag = LOW;
    }
    // Read values in normal mode (of1), burst mode (of2)
    if ((t - tTime) >= (1000 / PRINT_FREQ))
    {
        //of1_xy[0] += of1_delta_xy[0];
        of1_xy[1] += of1_delta_xy[1];
        [//Serial.print](notion://serial.print/)("X1: ");
        [//Serial.print](notion://serial.print/)(of1_xy[0]);
        Serial.print(" Y1: ");
        Serial.print(of1_xy[1]);
        Serial.print("\n");
    }

tTime = t;
}

Could you please assist me in resolving these issues? I would greatly appreciate your help.

Thank you for your time and assistance.

Sincerely, braincurd  :)