NRF5340 for audio reception

Hi ,I am new to nrf .I am currently using nrf5340,so i want to just print raw data of sph0645 using zephyr.I tested with examples of echo but i didnt achieved to print raw data and i have defined pin specifications in overlay file.Please provide any source.

Parents
  • Hi, 

    You can take a look at the functions i2s_read() which reads the data from Rx queue and i2s_buf_read() which reads the data from Rx queue into the buffer.

    Regards,
    Amanda H.

  • I have used the same thing but I am getting return value of -5,when I checked with the corresponding error code ,It shows I/O error.I don't know why that error came as i mentioned pins correctly.I attached my overlay layer

    &pinctrl {
    i2s0_default_alt: i2s0_default_alt {
    group1 {
    psels = <NRF_PSEL(I2S_SCK_M, 0, 7)>,
    <NRF_PSEL(I2S_LRCK_M, 0, 12)>,
    <NRF_PSEL(I2S_SDIN, 1, 0)>;
    //<NRF_PSEL(I2S_SDOUT, 1, 0)>;
    };
    };
    };


    &clock {
    hfclkaudio-frequency = <11289600>;
    };

    i2s_rxtx: &i2s0 {
    status = "okay";
    pinctrl-0 = <&i2s0_default_alt>;
    pinctrl-names = "default";
    clock-source = "ACLK";
    };
  • #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/i2s.h>

    #if DT_NODE_EXISTS(DT_NODELABEL(i2s_rxtx))
    #define I2S_RX_NODE DT_NODELABEL(i2s_rxtx)
    #define I2S_TX_NODE I2S_RX_NODE
    #endif
    #define AUDIO_BUFFER_SIZE 1024
    uint8_t audio_buffer[AUDIO_BUFFER_SIZE];


    #define SAMPLE_FREQUENCY 44100
    #define SAMPLE_BIT_WIDTH 24
    #define BYTES_PER_SAMPLE sizeof(int32_t)
    #define NUMBER_OF_CHANNELS 1


    static const struct device *mic = DEVICE_DT_GET(I2S_RX_NODE);

    void print_raw_data(void) {
    struct i2s_config cfg = {
    .word_size = SAMPLE_BIT_WIDTH,
    .channels = NUMBER_OF_CHANNELS,
    .format = I2S_FMT_DATA_FORMAT_I2S,
    .options = I2S_OPT_LOOPBACK,
    };

    int ret = i2s_configure(mic, I2S_DIR_RX, &cfg);
    printk("%d",ret);
    if (ret > 0) {
    printk("Failed to configure I2S: %d\n", ret);
    return;
    }

    while (1) {

    ret = i2s_read(mic, audio_buffer, AUDIO_BUFFER_SIZE);
    if (ret >= 0) {
    printk("Raw data:\n");
    for (size_t i = 0; i < AUDIO_BUFFER_SIZE; i++) {
    printk("%02X ", audio_buffer[i]);
    }
    printk("\n");
    } else {
    printk("Failed to read from mic: %d\n", ret);
    break;
    }
    }
    }

    void main(void) {
    if (!device_is_ready(mic)) {
    printk("Microphone device is not supported : %s\n", mic->name);
    return;
    }

    print_raw_data();
    }
     
    And this is source code I just tested for.
  • Kashyap23 said:
    I am getting return value of -5,when I checked with the corresponding error code ,It shows I/O error.

    • -EIO  means The interface is in NOT_READY or ERROR state and there are no more data blocks in the RX queue.

    Kashyap23 said:
    <NRF_PSEL(I2S_LRCK_M, 0, 12)>,

    Use other pins since P0.12 is for Trace, SPIM4. See the pin used in the nrf5340dk_nrf5340_cpuapp.overlay as an example.

Reply Children
No Data
Related