Skip to content

I2S Example*

Tip

Warning

  • When the 8006 operates as an I2S Slave, there are still issues with using Aout to play audio from the Master. If needed, please contact NationalChip support for clock frequency adjustment.
  • Currently, it is only recommended for use as the Master device.

1. Overview*

I2S audio transceiver example App, demonstrating how to communicate with an external audio codec via the I2S bus. Supports multiple master/slave mode combinations, with independently configurable TX (transmit) and RX (receive) directions. Microphone audio is transmitted to the external codec via I2S TX, while external audio can be received via I2S RX and played back.

2. Features*

  • 5 selectable operating modes (TX Master, RX Slave, RX Master + TX Master, RX Slave + TX Slave, RX Slave + TX Slave Lite)
  • TX path: Automatically pushes microphone audio frames to I2S DMA transmission
  • RX path: Receives I2S audio frames and routes them to the speaker for playback
  • Configurable RX buffer (buffer duration × frame count)
  • Automatic SDM/ADC clock configuration, supporting loopback

3. Directory Structure*

app/i2s_app/
├── i2s_app.c            # Main program
├── app.mk                # Build configuration
├── app.name              # Kconfig option
├── Kconfig               # Sub-configuration (mode selection)
├── i2s/
│   ├── i2s.c             # I2S configuration and initialization
│   ├── i2s.h
│   ├── i2s_rx.c          # I2S reception
│   ├── i2s_rx.h
│   ├── i2s_tx.c          # I2S transmission
│   ├── i2s_tx.h
│   ├── i2s_types.h       # Type definitions
│   ├── spk.c             # Speaker playback
│   └── spk.h
└── spk/
    ├── spk.c
    └── spk.h
File Description
i2s_app.c Main program, selects mode based on Kconfig and completes I2S initialization
i2s/i2s.c Core I2S configuration (clock, pins, format)
i2s/i2s_tx.c TX transmission logic, retrieves data from the microphone ring buffer for transmission
i2s/i2s_rx.c RX reception logic, feeds received data into the playback path
i2s/i2s_types.h I2S configuration structure I2S_Config
i2s/spk.c Speaker playback wrapper

4. Configuration Description*

4.1 Kconfig Mode Selection*

Configuration Item Description
APP_I2S_TX_M TX only, master mode
APP_I2S_RX_S RX only, slave mode
APP_I2S_RX_M_TX_M RX master + TX master
APP_I2S_RX_S_TX_S RX slave + TX slave
APP_I2S_RX_S_TX_S_LITE RX slave + TX slave (Lite mode)

4.2 Macro Definitions*

#define I2S_RX_CACHE_MS    40     // RX buffer duration (ms)
#define I2S_RX_FREME_NUM   4      // RX buffer frame count

4.3 I2S Pin Mapping*

Signal Pin Direction Description
MCLK PAD 7 Output Master clock
BCLK PAD 8 Output/Input Bit clock
LRCLK PAD 10 Output/Input Left/right channel clock
DATA IN PAD 5 Input I2S data reception
DATA OUT PAD 9 Output I2S data transmission

4.4 I2S Parameters*

  • Sample rate: 16kHz
  • BCLK: 64FS (64 × 16kHz = 1.024MHz)
  • Data format: I2S standard format
  • PCM bit width: 16bit
  • Storage bit width: 16bit

5. Operating Principle*

5.1 Initialization Flow*

  1. Enable AUDPCLK and I2S clocks
  2. Configure pin multiplexing for I2S functionality
  3. Call gx_i2s_init() to initialize the I2S hardware
  4. Call the corresponding i2s_config_xxx() based on the selected mode to configure TX/RX
  5. Configure SDM/ADC clock source for loopback

5.2 TX Transmission Mechanism*

  1. During initialization, i2s_tx_push_mic_frame() enqueues the first frame
  2. Subsequent frames are handled by the _i2s_tx_cb() callback
  3. The callback iterates through the microphone ring buffer, advancing the read address by frame size, wrapping around when necessary

5.3 RX Reception Mechanism*

_i2s_rx_cb() receives I2S frames and feeds them into the speaker playback path via spk_put_frame().

5.4 Event Handling*

app_event_response() is an empty implementation; all data transfer is driven by DMA interrupts.

5.5 Main Loop*

app_task_loop() is an empty implementation.

6. Usage*

6.1 Compilation*

cp configs/example/app/8006_i2s_sample_app.config .config
make defconfig
make clean; make

Alternatively, select the mode and parameters via menuconfig:

make menuconfig
# OVP Application Settings → Applications Selection → I2S Sample
# Application Settings → Select I2S operating mode

6.2 Flashing and Running*

cd tools/bootx/
./flash_nor.sh 0 -r 1000000

7. Expected Output*

  • TX mode: External codec receives microphone audio data
  • RX mode: Speaker plays audio from the external codec

8. Notes*

  1. External codec required: This App requires an external I2S audio codec connection and cannot run standalone
  2. Master/slave matching: Mode selection must match the external codec's master/slave configuration; mismatched clock directions will result in no output
  3. Pin conflicts: I2S pins (PAD 5/PAD 7/PAD 8/PAD 9/PAD 10) cannot be shared with other functions
  4. Cache consistency: TX DMA accesses memory directly; ensure data has been written to physical memory
  5. Sleep/wake-up not implemented: The current SDK does not support sleep functionality; app_suspend() and app_resume() can remain as empty implementations