| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
I2S Loopback Example
This information applies to the nRF52 Series only.

The I2S Loopback Example demonstrates how to take advantage of the I2S driver when creating an application that uses the Inter-IC Sound (I2S) peripheral. It uses a loopback to check that data is transmitted and received correctly. To complete the loopback, the pins configured as the SDOUT and SDIN lines of the I2S peripheral must be wired together.

Data transfers consisting of a specified number of blocks are continuously performed with 500 ms delays between them. The number of blocks is specified by BLOCKS_TO_TRANSFER. The length of each block is half the size of the used memory buffer.

LED 1 and LED 2 are used to visualize the transfers. One of the LEDs is constantly off and the other one is toggled after each transferred block, thus it is blinking at a pace corresponding to the size of the buffer and the used sampling frequency. As long as the data is transferred correctly, LED 1 is toggled. If an error occurs, the toggling is switched to LED 2 until the end of the transfer. This blinking scheme makes it easy to check the correctness of the transfers. Additionally, messages are output on UART.

The following messages indicate successful transfers:

     1: OK
     2: OK
     3: OK
     ...

Messages similar to the following one indicate an error:

     1: 0000/0000, expected: cafd/caff

The first pair of values shows the values of the samples that were received (for the left channel / for the right channel). The second pair shows the values of the samples that were sent.

# Setup

You can find the source code and the project file of the example in the following folder: `<InstallFolder>\examples\peripheral\i2s`

Hardware configuration:

- SDOUT must be connected to SDIN.

The default pin assignments for the SDOUT and SDIN lines (I2S_CONFIG_SDOUT_PIN and I2S_CONFIG_SDIN_PIN) can be found in `sdk_config.h`.

# Testing

Test the I2S Loopback Example application by performing the following steps:

1. Compile and program the application.
2. Start a terminal emulator like PuTTY and connect to the used COM port with the following UART settings:
   - Baud rate: 115.200
   - 8 data bits
   - 1 stop bit
   - No parity
   - HW flow control: RTS/CTS
3. Observe the following behavior:
   1. When transfers are successful, LED 1 is blinking and OK messages are output on UART.
   2. When transfers are not successful (for example, if the SDOUT and SDIN lines are not wired together), LED 2 is blinking and error messages are output on UART.