TB-S5D5 How to receive data using I2S

TB-S5D5 How to receive data using I2S


Creating I2S data reception processing with reference to SK-S7G2 How to receive and transmit data using I2S

The return value of g_i2s0.p_api-> read is SSP_SUCCESS, but the value of the buffer for saving PCM samples is all 0

 Please tell me how to read correctly.

 

Running with the following settings.

=================================
I2S DEVICE
=================================

Adafruit I2S MEMS Microphone - SPH0645

=================================
Verified signals using o-scope
=================================
The S5 is generating a fixed 2.8 MHz clock.
GOOD: S5 I2S bit clock is working.
The S5 is toggling the S5.SSI0.SSIWS
GOOD: S5 I2S word select is working.
S7 S5 RX (audio data from SPH0645).
GOOD: Outputting data from SPH0645.

=================================
I2S Thread
=================================
Channel: 0
Data Bits: 18
Word Length: 32 bits

=================================
Wiring between S5 and SPH0645
=================================
S5.VCC -> SPH0645.3V
S5.GND -> SPH0645.GND
S5.GND -> SPH0645.SEL (left channel mono)
S5.GPT0.GTIOCA (P512) -> S7.SSI.AUDIO_CLK (P400)
S5.SSI0.SSISCK (P403) -> SPH0645.BCLK (bit clock)
S5.SSI0.SSIWS (P404) -> SPH0645.LRCLK (word select)
S5.SSI0.SSIRXD (P406) <- SPH0645.DOUT (data output)
S5.SSI0.SSITXD (P406) -> O-scope

=================================
i2s_thread_entry.c
=================================

#include "i2s_thread.h"

#define MAX_RX_SAMPLES 64
#define MAX_TX_SAMPLES 2

typedef struct {
  int32_t signed18bits : 24; // 18 signed bits
  int32_t not_used : 8; // 14 bits of ones
} T_I2S_SAMPLE;


typedef struct {
  union
  {
    struct {
      uint32_t left;
      uint32_t right;
    } words;
    uint8_t bytes[8];
    struct {
      T_I2S_SAMPLE left;
      T_I2S_SAMPLE right;
    } samples;
  };
} T_DATA_BUFFER;


int rx_index = 0;
T_DATA_BUFFER rx_buffer[MAX_RX_SAMPLES];

int tx_index = 0;
T_DATA_BUFFER tx_buffer[MAX_TX_SAMPLES] = {
  { .words = {0x55555555, 0x66666666}},
  { .words = {0x55555555, 0x66666666}}
};
int flg = 0;

/* I2S Thread entry function */
void i2s_thread_entry(void)
{
  ssp_err_t err;

  memset(rx_buffer, 0, sizeof(rx_buffer));

  err = g_i2s0.p_api->open(g_i2s0.p_ctrl, g_i2s0.p_cfg);
  if (err != SSP_SUCCESS)
  {
    __BKPT(0);
  }

  err = g_i2s0.p_api->read(g_i2s0.p_ctrl, &rx_buffer[rx_index].bytes[0], sizeof(T_DATA_BUFFER));
  if (err != SSP_SUCCESS)
  {
    __BKPT(0);
  }

}

void i2s_callback(i2s_callback_args_t * p_args)
{

  ssp_err_t err;

  switch(p_args->event)
  {
    case I2S_EVENT_IDLE:
    err = g_i2s0.p_api->write(g_i2s0.p_ctrl, &tx_buffer[tx_index].bytes[0], sizeof(T_DATA_BUFFER));
    if (err != SSP_SUCCESS)
    {
      __BKPT(0);
     }
     break;
  case I2S_EVENT_TX_EMPTY:
    err = g_i2s0.p_api->write(g_i2s0.p_ctrl, &tx_buffer[tx_index].bytes[0], sizeof(T_DATA_BUFFER));
    if (err != SSP_SUCCESS)
    {
      __BKPT(0);
    }
    break;
  case I2S_EVENT_RX_FULL:
    err = g_i2s0.p_api->read(g_i2s0.p_ctrl, &rx_buffer[rx_index].bytes[0], sizeof(T_DATA_BUFFER));
    if (err != SSP_SUCCESS)
    {
      __BKPT(0);
    }
    else
    {
      ++rx_index;
      if (MAX_RX_SAMPLES <= rx_index)
      {
        rx_index = 0;
      }
    }
    break;
  default:
    break;
  }
}