ΣSigmaStudio Ask AI Русский Log in

Pluto SDR - rx/tx C example

Processors & DSP throwaway Dec 11, 2020 00:00 4 replies Original on forum ↗
Subscribe
throwaway Question
Dec 11, 2020 00:00

#include <iio.h>

int main (int argc, char **argv)
{
struct iio_context *ctx;
struct iio_device *phy;

ctx = iio_create_context_from_uri("ip:192.168.2.1");

phy = iio_context_find_device(ctx, "ad9361-phy");

iio_channel_attr_write_longlong(
iio_device_find_channel(phy, "altvoltage0", true),
"frequency",
2400000000); /* RX LO frequency 2.4GHz */

iio_channel_attr_write_longlong(
iio_device_find_channel(phy, "voltage0", false),
"sampling_frequency",
5000000); /* RX baseband rate 5 MSPS */

receive(ctx);

iio_context_destroy(ctx);

return 0;
}
int receive(struct iio_context *ctx)
{
struct iio_device *dev;
struct iio_channel *rx0_i, *rx0_q;
struct iio_buffer *rxbuf;

dev = iio_context_find_device(ctx, "cf-ad9361-lpc");

rx0_i = iio_device_find_channel(dev, "voltage0", 0);
rx0_q = iio_device_find_channel(dev, "voltage1", 0);

iio_channel_enable(rx0_i);
iio_channel_enable(rx0_q);

rxbuf = iio_device_create_buffer(dev, 4096, false);
if (!rxbuf) {
perror("Could not create RX buffer");
shutdown();
}

while (true) {
void *p_dat, *p_end, *t_dat;
ptrdiff_t p_inc;

iio_buffer_refill(rxbuf);

p_inc = iio_buffer_step(rxbuf);
p_end = iio_buffer_end(rxbuf);

for (p_dat = iio_buffer_first(rxbuf, rx0_i); p_dat < p_end; p_dat += p_inc, t_dat += p_inc) {
const int16_t i = ((int16_t*)p_dat)[0]; // Real (I)
const int16_t q = ((int16_t*)p_dat)[1]; // Imag (Q)

/* Process here */

}
}

iio_buffer_destroy(rxbuf);

}

I've been using this example file from the docs with my plutoSDR. What I want to do is take the I/Q data im given there and
try to select out frequencies that I want using C. I am kind of confused what is the size of the band that I am receiving
here? I can't find anywhere to read the internals of the functions. Any help appreciated!

c

sdr

pluto

throwaway Reply
Dec 11, 2020 00:00

nvm :)

throwaway Reply
Dec 11, 2020 00:00

possibly also if someone could clarify how is the iio.py working with the C files

throwaway Reply
Dec 22, 2020 00:00

whats the difference between the RX LO and sampling frequency being set in iio_channel_attr_write_longlong() is there informaton on the string identifiers? I know with "ad9361-phy" it is initializing the phy layer. I want to make a single receive radio station in C. So I am wondering what the data is at this point so I know what steps to perform on it to output the audio eventually. Hopefully someone sees this :)

ADIApproved Reply
Feb 12, 2021 00:00

Hi,

Apologies for the delayed response.

Can you please let us know which processor and tool are you using ? This will help us to assist you better on your issue.

Regards,
Anand Selvaraj.