lsm303agr-rs icon indicating copy to clipboard operation
lsm303agr-rs copied to clipboard

Proper way to read from fifo?

Open akda5id opened this issue 7 months ago • 1 comments

I'm poking around, and trying to understand how the fifo is set up. EDIT: Skip the rest of this comment, I have resolved most of my confusion in the second comment in the thread.

From the datasheet it seems you have to set fifo mode to bypass to clear the fifo after you read it, which seems to be sorta working, but I am not sure if this is how the reading is intended, I seem to always get "dead" data for the first sensor.acceleration() read. Is there a better way to read a chunk from the buffer? Is there a way to see how much is in the buffer? In my bogus test code below, I am intentionally reading too far, and just get duplicated data for the last item(s).

sensor.set_accel_mode_and_odr(
            &mut delay,
            lsm303agr::AccelMode::LowPower,
            lsm303agr::AccelOutputDataRate::Hz10,
        )
        .unwrap();

    let _ = sensor.acc_set_fifo_mode(lsm303agr::FifoMode::Fifo, 31);

    loop {
        for _ in 0..12 {
            let data = sensor.acceleration().unwrap();
            rprintln!(
                "x {} y {} z {}",
                data.x_mg(),
                data.y_mg(),
                data.z_mg()
            );
        }
        rprintln!(" ");
        let _ = sensor.acc_set_fifo_mode(lsm303agr::FifoMode::Bypass, 0);
        let _ = sensor.acc_set_fifo_mode(lsm303agr::FifoMode::Fifo, 31);

        delay.delay_ms(1000_u32);

     }

akda5id avatar Jul 07 '24 09:07 akda5id