5 years, 6 months ago.

SPI speed and FIFO reading

Hi,

I am try to read an accelerometer's FIFO as fast as possible (KX224). I tried using I2C and I got 45ms for the buffer reading. Because my MCU can use only 400kbits/s, I want to compare the SPI reading time.

In order to read the FIFO buffer, I have to read the same register how many times the accelerometer says it has data for me in buffer. The way that I did is this:

    _cs_spi = 0;
    _spi.write(KX224_BUF_READ | 0x80);

    for(uint16_t i = 0; i < size / 6; i++)
    {
        char x[2] = { _spi.write(0x00), _spi.write(0x00) };
        char y[2] = { _spi.write(0x00), _spi.write(0x00) };
        char z[2] = { _spi.write(0x00), _spi.write(0x00) };
    }
        
    _cs_spi = 1;

It is working and is reading the same register fine. My problem is that I run this code using 1MHz for SPI and it takes 39ms. I tried with 9MHz as well and it takes 25ms. Shouldn't it take 9 times less?

Is there any other way in that I can read the FIFO without using a for loop?

Thanks

Be the first to answer this question.