cancel
Showing results for 
Search instead for 
Did you mean: 

About IIS3DWB FIFO watermark setting

chenjy96
Associate

I modified this IIS3DWB example to use IIS3DWB on my nRF board.

This example set the size of watermark as 256,

and in the while loop, the data will be retrieved when FIFO_WTM_IA is triggered.

 

In my program, it seems that I can get the correct accel data, but the value of num is not as I expected.

The value of num is 256 in the first loop, and is always 512 after the second loop.  

 

 

 

 

while (1) {
    uint16_t num = 0, k;
    /* Read watermark flag */
    iis3dwb_fifo_status_get(&dev_ctx, &fifo_status);
    if (fifo_status.fifo_th == 1) {
        num = fifo_status.fifo_level;
        /** other code **/
    }    
    /** other code **/
}

 

 

 I'm concerned that FIFO_WTM_IA is not being triggered properly, maybe resulting in getting data that will be missing.

 

And here is my SPI read and write implementation.

 

 

uint8_t SpiInOut (stmdev_ctx_t* spi_ctx, uint8_t outData)
{
    uint32_t err_code;
    uint8_t inData ;
    
    if ((spi_ctx == NULL) || (&(spi_ctx->spi_handle) == NULL))
    {
        APP_ERROR_CHECK_BOOL (false);
    }

    err_code = nrf_drv_spi_transfer (&(spi_ctx->spi_handle), &outData, 1, &inData, 1);
    APP_ERROR_CHECK(err_code);

    return inData;
}

int32_t SpiWriteRegisters(void* handle, uint8_t reg, const uint8_t* buffer, uint16_t len)
{
    UNUSED_PARAMETER(handle);

    GpioWrite(&iis3dwb_.spi.Nss, 0);
    SpiInOut(&iis3dwb_.spi, reg);
    for(uint16_t i = 0; i < len; i++)
    {
        SpiInOut(&iis3dwb_.spi, buffer[i]);
    }
    GpioWrite(&iis3dwb_.spi.Nss, 1);

    return 0;
}

int32_t SpiReadRegisters(void* handle, uint8_t reg, uint8_t* buffer, uint16_t len)
{
    UNUSED_PARAMETER(handle);
    
    // Set first bit to 1;
    reg |= 0x80;
    GpioWrite(&iis3dwb_.spi.Nss, 0);
    SpiInOut(&iis3dwb_.spi, reg);
    
    for(uint16_t i = 0; i < len; i++)
    {
        buffer[i] = SpiInOut(&iis3dwb_.spi, 0);
    }

    GpioWrite(&iis3dwb_.spi.Nss, 1);

    return 0;
}

 

 

 

 

 

 

 

 

1 REPLY 1
Federica Bossi
ST Employee

Hi @chenjy96 ,

Did you modify `platform_write` and `platform_read`? In addition, `tx_com` and 'platform_init' is required.

Let me know if you have already made all the necessary changes.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.