I2S format

Matt141
Posts: 8
Joined: Fri Oct 04, 2019 2:24 pm

I2S format

Postby Matt141 » Wed Aug 23, 2023 3:52 pm

Hi,
I use the I2S (deprecated) to send audio data from ESP32 to another chip. The received values are wrong so I checked the data on scope. I send 0x31 with:

Code: Select all

int i;
for(i=0; i<item_size/2; i++){
      data[2*i] = 1; //0x31, little endian
       data[2*i+1] = 3;
}
i2s_write(0, data, item_size, &bytes_written, portMAX_DELAY);
The i2s is configured as follow:

Code: Select all

i2s_config_t i2s_config = {
        .mode = I2S_MODE_MASTER | I2S_MODE_TX,                                  // Only TX
        .sample_rate = 44100,
        .bits_per_sample = 16,
        .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,     //2-channels
        .communication_format = I2S_COMM_FORMAT_I2S_MSB,
        .dma_buf_count = 6,
        .dma_buf_len = 1024,
        .intr_alloc_flags = 0,                                                  //Default interrupt priority
        .tx_desc_auto_clear = true,                                             //Auto clear tx descriptor on underflow
    };
The scopes shows the clock (blue), le data (yellow) and the word select (pink):
Image
Looking at this picture, it seems the issue is that the data (yellow) is 1 clock tick late compared to the word select because the i2s is configure with most significant bit first.

Any idea with this occurs ?

Regards,
Matt
Last edited by Matt141 on Thu Aug 24, 2023 9:00 am, edited 1 time in total.

Matt141
Posts: 8
Joined: Fri Oct 04, 2019 2:24 pm

Re: I2S synchronisation: 1 bit late

Postby Matt141 » Thu Aug 24, 2023 8:59 am

The issue was the format. I was using I2S_COMM_FORMAT_I2S_MSB=0x01, but I should use I2S_COMM_FORMAT_STAND_MSB = 0X02 even though I am using the deprecated version of I2S.

Code: Select all

/**
 * @brief I2S communication standard format
 */
typedef enum {
    I2S_COMM_FORMAT_STAND_I2S        = 0X01, /*!< I2S communication I2S Philips standard, data launch at second BCK*/
    I2S_COMM_FORMAT_STAND_MSB        = 0X02, /*!< I2S communication MSB alignment standard, data launch at first BCK*/
    I2S_COMM_FORMAT_STAND_PCM_SHORT  = 0x04, /*!< PCM Short standard, also known as DSP mode. The period of synchronization signal (WS) is 1 bck cycle.*/
    I2S_COMM_FORMAT_STAND_PCM_LONG   = 0x0C, /*!< PCM Long standard. The period of synchronization signal (WS) is channel_bit*bck cycles.*/
    I2S_COMM_FORMAT_STAND_MAX,               /*!< standard max*/

    //old definition will be removed in the future.
    I2S_COMM_FORMAT_I2S       __attribute__((deprecated)) = 0x01, /*!< I2S communication format I2S, correspond to `I2S_COMM_FORMAT_STAND_I2S`*/
    I2S_COMM_FORMAT_I2S_MSB   __attribute__((deprecated)) = 0x01, /*!< I2S format MSB, (I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_MSB) correspond to `I2S_COMM_FORMAT_STAND_I2S`*/
    I2S_COMM_FORMAT_I2S_LSB   __attribute__((deprecated)) = 0x02, /*!< I2S format LSB, (I2S_COMM_FORMAT_I2S |I2S_COMM_FORMAT_I2S_LSB) correspond to `I2S_COMM_FORMAT_STAND_MSB`*/
    I2S_COMM_FORMAT_PCM       __attribute__((deprecated)) = 0x04, /*!< I2S communication format PCM, correspond to `I2S_COMM_FORMAT_STAND_PCM_SHORT`*/
    I2S_COMM_FORMAT_PCM_SHORT __attribute__((deprecated)) = 0x04, /*!< PCM Short, (I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_SHORT) correspond to `I2S_COMM_FORMAT_STAND_PCM_SHORT`*/
    I2S_COMM_FORMAT_PCM_LONG  __attribute__((deprecated)) = 0x08, /*!< PCM Long, (I2S_COMM_FORMAT_PCM | I2S_COMM_FORMAT_PCM_LONG) correspond to `I2S_COMM_FORMAT_STAND_PCM_LONG`*/
} i2s_comm_format_t;

Who is online

Users browsing this forum: No registered users and 142 guests