Professional Documents
Culture Documents
I2s Protocol
I2s Protocol
I2s Protocol
PROTOCOL
INTRODUCTION
The protocol which is used to transmit digital audio data from one device to another
device is known as I2S or Inter-IC Sound protocol.
The digital audio signals in most systems are being processed by a number of devices, such as ADCs,
DACs, DSPs, Digital I/O interfaces, and many more.
In order for these devices to communicate audio data with each other a standard protocol
is required. One such is I2S protocol.
PINS
The I2S communication protocol is a 3 Wire protocol that simply handles audio data through a 3-line serial
bus which includes
1. No channel-side information
2. Short and long frame formats (configure with PCMSYNC bit)
a. Long frame: WS asserted for 13 bits
b. Short frame : WS asserted for 1 bit
PCM standard - Wavaform
MODES OF TRANSMISSION :
2.The ODD bit (odd factor for the prescaler)in the SPI_I2SPR register also has to be defined.
3. Select the CKPOL bit to define the steady level for the communication clock.
4.Set the MCKOE bit in the SPI_I2SPR register if the master clock MCK needs to be provided to the external
DAC/ADC audio component.
First data is written into the TX buffer corresponds to channel left, when it is transferred to shift register,
then the data in channel right is written into TX buffer.
Here one full transaction means transmission of channel left data followed by channel right data.
The data half word is parallel loaded into the 16bit shift register during the first bit transmission and then
shifted out serially to the MOSI/SD pin, MSB first.
For continuous audio data transmission, it is mandatory to write the SPI_DR with the next data to
transmit before the end of the current transmission.
To switch off the I2S, by clearing I2SE, it is mandatory to wait for TXE = 1 and BSY = 0.
Reception sequence
The audio data are received by 16 bit packet.
This means that each time the Rx buffer is full, the RXNE flag is set and an
interrupt is generated if the RXNEIE bit is set in SPI_CR2 register.
Clearing the RXNE bit is performed by reading the SPI_DR register.
CHSIDE is updated after each reception. It is sensitive to the WS signal
generated by the I2S cell.
If we receive new data before the previous data is read an overrun error is
generated.(OVR flag is set, the ERRIE BIT is set in SPI_CR2 register an interrupt
is generated which indicates error ).
I2s slave mode:
In master mode for transmission and reception
- i2sx is used for Half duplex mode.
- I2sx and i2sx_ext are used for full duplex mode.
The clock and ws signal are input from the external master connected to I2S
interface.
Set I2SMOD bit in SPI_I2SCFGR to activate i2s functionality.
i2SSTD[1:0] $ PCMSYNC for standard.
DALEN[1:0] for data length.
CHLEN bit for channel length.
I2SCFG[1:0] bits for I2S master mode and its direction.
Transmission sequence
The sequence starts when the external master device send clock and ws signals.
The slave has to be enabled before the external master starts the communication. The I2S
data register has to be loaded before the master initiates the communication.(data in channel
left)
As the communication starts the data from the TX buffer is transmitted to shift register.
As the communication starts the data half-word is parallel-loaded into the 16-bit shift register
(from the internal bus) and then shifted out serially to the MOSI/SD pin MSB first.
The TXE flag is set after each transfer from the Tx buffer to the shift register and an interrupt is
generated if the TXEIE bit in the SPI_CR2 register is set.
Transmission sequence (contd.,)
For continuous transmission SPI_DR must be loaded with next data to be transmitted
before the end of the current transmission.
If the data is not loaded into the SPI_DR register before the first clock edge of the next
data communication an underrun error will be generated and UDR flag gets high.
If the ERRIE bit is set into the SPI_CR2 register, an interrupt is generated when the UDR
flag (underrun) in the SPI_SR register goes high.
In this it is mandatory to switch off the I2S and to restart a data transfer starting from
the left channel.
To switch off the I2S, by clearing the I2SE bit, it is mandatory to wait for TXE = 1 and
BSY = 0
Reception sequence
Configure the register into slave reception mode.
The data which is being received is stored in RX buffer. Then the RXNE flag is set and also an
interrupt is generated if the RXNEIE is set in the SPI_CR2 register.
The CHSIDE flag is updated each time data are received to be read from SPI_DR.
RXNE bit is cleared by reading the SPI_DR register.
If the new data is received before the previous data is read an overrun error is generated.
OVR bit is set and if ERRIE is set in the SPI_CR2 register an interrupt is generated to
indicate the error.
To switch off the I2S in reception mode, I2SE has to be cleared immediately after receiving the
last RXNE = 1.