Skip to content

serial problem ( sensor, st - iis3dwb) #7219

@savagerex

Description

@savagerex

Board

ESP32 c3

Device Description

ESP32-C3-DevKitM-1

Hardware Configuration

NONE

Version

v2.0.4

IDE Name

Arduino

Operating System

Windows 10

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

921600

Description

Before we encountered the problem of receiving data, we received 4,000 transactions per second.

Later, as you mentioned, it was a tool problem, so I solved it

Now that the sensor has been changed, it needs to receive 26.6k data per second.

Is this still a tool issue?

Or is this a problem with esp32

Sketch

#include "SPI.h"
#include "BoardConfig.h"
#include "Sensor.h"
#include "IIS3DWB.h"

#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif


const char Version[]="1.0.0";
const char CompileDate[]= __DATE__ " " __TIME__;
#define CSPIN    10

uint8_t Ascale = AFS_2G;

float aRes;                              // scale resolutions per LSB for the accel 
float accelBias[3] = {0.0f, 0.0f, 0.0f}; // offset biases for the accel 
int16_t IIS3DWBData[4] = {0};            // Stores the 16-bit signed sensor output
uint8_t IIS3DWBRawData[6] = {0};            // Stores the 16-bit signed sensor output
float ax, ay, az, accelTemp;             // variables to hold latest accel data values 
uint8_t IIS3DWBstatus;
//long values[40];
uint8_t ui8txLogBuf[20];
uint16_t i, j, k, m;
int DryFlag = 1;
int packet_counter = 1;

unsigned long StartTime;
unsigned long EndTime;

IIS3DWB IIS3DWB(CSPIN);


// Pins used for the connection with the sensor
const int CHIP_SELECT_PIN = 10;  //7

uint8_t ascii_trans(uint8_t ui8Code) {
  if((ui8Code == 0 || ui8Code > 0) && ui8Code <= 9){
    ui8Code += 48;  //0x30;
  }else if(ui8Code >= 10 && ui8Code <= 15){
    ui8Code += 55;  //0x37;
  }
  return ui8Code;
}

void IRAM_ATTR IntOneIsr() {
     DryFlag = 1;  
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  //Serial.begin(1536000);

  Serial1.begin(1536000, SERIAL_8N1, 19, 18);
  
  SPI.begin(GPIO_OUTPUT_SCLK, GPIO_INPUT_MISO, GPIO_OUTPUT_MOSI, GPIO_OUTPUT_CS);
  //SPI.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
 
  // Initalize the  data ready and chip select pins:
  pinMode(CSPIN, OUTPUT);
  digitalWrite(CSPIN, HIGH);

  Serial.println("IIS3DWB accel...");
  uint8_t c = IIS3DWB.getChipID();  // Read CHIP_ID register for IIS3DWB
  Serial.print("IIS3DWB "); Serial.print("I AM "); Serial.print(c, HEX); Serial.print(" I should be "); Serial.println(0x7B, HEX);
  Serial.println(" ");

  if(c == 0x7B) // check if all SPI sensors have acknowledged
  {
   Serial.println("IIS3DWB is online...");  
   Serial.println(" ");

   // reset IIS3DWB to start fresh
   IIS3DWB.reset();  

   // get accel sensor resolution, only need to do this once
   aRes = IIS3DWB.getAres(Ascale);

   IIS3DWB.selfTest();

   IIS3DWB.init(Ascale); // configure IIS3DWB  

   IIS3DWB.offsetBias(accelBias);
   Serial.println("accel biases (mg)"); Serial.println(1000.0f * accelBias[0]); Serial.println(1000.0f * accelBias[1]); Serial.println(1000.0f * accelBias[2]);
   Serial.println(" ");
   delay(1000); 
   
   
  }
  else 
  {
  if(c != 0x6A) Serial.println(" IIS3DWB not functioning!"); 
  while(1){};
  }

  // Give the sensor time to set up:
  delay(100);
  attachInterrupt(INTONE, IntOneIsr, RISING);

}

void loop() {
  


         if(DryFlag == 1) {
          DryFlag = 0;
//         if(m == 0)
//         {
//           StartTime = millis();
//         }
         IIS3DWB.readAccelRawData(IIS3DWBRawData); 
//           m += 1;
//
//           if (m==26000){     //400
//           EndTime = millis();
//           Serial.print("**************UART Read Time*************");
//           Serial.println(EndTime-StartTime);
//           m=0;
//           }

          for(i = 0; i < 6; i++) {
            ui8txLogBuf[j] = ascii_trans((IIS3DWBRawData[i] >> 4));
            ui8txLogBuf[j+1] = ascii_trans((IIS3DWBRawData[i] & 0x0F));
            j+=2;
          }

          if (packet_counter < 10) {
            Serial.write(ui8txLogBuf, 12);
          } else if (packet_counter == 10) {
            ui8txLogBuf[j] = '\r';
            ui8txLogBuf[j + 1] = '\n';
            Serial.write(ui8txLogBuf, 14); 
            //m += 1;
            //j = 0;
            packet_counter = 0;
          }
          packet_counter++;
          j = 0;

       }
         
//         Serial.print(IIS3DWBRawData[0]);
//         Serial.print(IIS3DWBRawData[1]);
//         Serial.print(IIS3DWBRawData[2]);
//         Serial.print(IIS3DWBRawData[3]);
//         Serial.print(IIS3DWBRawData[4]);
//         Serial.println(IIS3DWBRawData[5]);

  // Next data in 100 milliseconds
  //delay(1000);
  //delayMicroseconds(211);   //250

}

Debug Message

NONE

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions