AnsweredAssumed Answered

Ad7266 - How to use the buffer and trigger with libiio?

Question asked by eddi on Jul 28, 2016
Latest reply on Aug 29, 2016 by eddi

Hallo ,

 

I'm currently try to use the buffer and trigger functionality of ad7266 to fetch 2048 Samples every 20ms from channel 0.

I wanted to understand the functionality on the terminal with this documentation AD7266 Differential/Single-Ended Input, Dual, Simultaneous Sampling, 2 MSPS, 12-Bit, 3-Channel SAR A/D Converter Linux D…

 

In scan_elements I wrote 1 to in_voltage0_en. The file trigger/current_trigger is empty, so I wrote bfintmr3 to this file, but the file is still empty. What I have to write in this file?

 

In buffer/length I write 2048 like the wanted samples. Now I tried to enable the buffer with writing 1 to buffer/enable but I got an error message "Invalid argument". Maybe this depends on the trigger I mentioned above.

 

Anyway I tried to use the buffer and trigger functionality with libiio with this code. Questions as comment in the code:

I tried it with this documentation: About libiio [Analog Devices Wiki]

 

#include <stdio.h>

#include <iio.h>

 

int main()

{

     struct iio_context *context = iio_create_local_context();

     struct iio_device *device = iio_context_get_device(context, 3);

     struct iio_channel *channel = iio_device_get_channel(device, 0); 

     iio_channel_enable(channel); /* In the right in_voltage0_en in  scan_elements is 1, so I think I chose the correct channel and device  */

 

     /* I think I missed to configure the trigger and configure the buffer correctly, but how I can achive this?  */

     struct iio_buffer *buffer = iio_device_create_buffer(device, 2048, 0);

 

     iio_buffer_refill(buffer);

     int solBuf[2048] = {0};

     iio_channel_read_raw(channel, buffer, solBuf, 2048);

 

     /* Only the index of 2 till 11 are correct. The same number of digits like in in_voltage0_raw */

     for (; i < 2048; ++i)

     {

        printf("%d - %d\n", i, solBuf[i]);   

    }

 

     return 0;

}

 

I hope someone can help me. First I'd like to understand the correct usage of this on the terminal and afterwards with libiio.

 

Greetings

 

P.S.: Is their a code-tag in this editor?

Outcomes