Questions about the reading speed of the SPI sensor

device:esp32+mt6816 SPI clock 14mhz
I’m sorry to translate into English.

First of all I tested the speed of sensor.update() It’s about 32.83khz.
I found out beginTransaction() and endTransaction() cost a lot time.
so i do it

uint16_t MT6816::readRawAngle() 

    uint16_t angle_data = 0;


    angle_data = spi->transfer16(MT6816_READ_REG_03) << 8;
    angle_data |= spi->transfer16(MT6816_READ_REG_04);


and then the speed of sensor.update() increase to 60khz.
and then i modified beginTransaction() and endTransaction(),Removed mutex:

void SPIClass::endTransaction()
    if (_inTransaction)
        _inTransaction = false;

the sensor.update() speed Up to 80KHZ.
so What can I do to make it faster?

Hey @AXU , welcome to SimpleFOC!

We have a driver for the MT6816 here:

I assume you are modifying it?

The 32 bit read seems like a good idea!

Removing mutex is fine as an individual solution, I guess, but not something that we could do generally. If your system works well in this way, then great!

That’s very fast… With a 14MHz SPI clock, you would get a maximum rate of about 218kHz for 32 bit reads.

You could see if the sensor works just reading continuously, without switching nCS off in-between… this might save a little time.

But the sensor also has a ABZ output mode with only 1us latency. So I think you will be able to interface much faster if you:

Thanks for the answer,
I don’t know how to set the parameters of this sensor through SPI so that it is programmed in ABZ mode
But the good news is that the update frequency is now 150kHz。There is an error in the above。80kHz is the speed at which the mutex is not removed。
I’m now finding that the ADC (GPIO35 34) read causes the VSPI read speed to be halved, is it because of the occupancy issue?

I am not sure what you mean by “occupancy issue”.

Probably the ADC reads are just taking their time, so you have less CPU time for other tasks, so the update frequency is lower.

If your ESP32 has two cores you can try reading the ADC on the other core. If the sensor updates go back to 150kHz then it was the time of the ADC reads you were seeing…

I read MT6816 in core 1 and core 2 read current, at this point MT6816 speed is about 75khz,
and when I close the read current task in core 2, MT6816 speed returns to 150khz
Now I’m trying to use dma to read the adc, does simpleFOC support ESP32 latest arduino library (V3.0.1)?
because I need to use the API for ESP-IDFV5.1.X

No, it does not support 3.0.0 yet… but we are working on it and it should be supported in the next release.