I2S Exported Functions
- group I2S_Exported_Functions
Functions
-
void I2S_DeInit(I2S_TypeDef *I2Sx)
Deinitialize the I2S peripheral registers to their default values.
Example usage
void driver_i2s_init(void) { I2S_DeInit(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
-
void I2S_Init(I2S_TypeDef *I2Sx, I2S_InitTypeDef *I2S_InitStruct)
Initialize the I2S peripheral according to the specified parameters in the I2S_InitStruct.
Example usage
void driver_i2s_init(void) { RCC_PeriphClockCmd(APB_I2S, APB_I2S_CLOCK, ENABLE); I2S_InitTypeDef I2S_InitStruct; I2S_StructInit(&I2S_InitStruct); I2S_InitStruct.I2S_ClockSource = I2S_CLK_40M; I2S_InitStruct.I2S_BClockMi = 0x271; I2S_InitStruct.I2S_BClockNi = 0x10; I2S_InitStruct.I2S_DeviceMode = I2S_DeviceMode_Master; I2S_InitStruct.I2S_ChannelType = I2S_Channel_stereo; I2S_InitStruct.I2S_DataWidth = I2S_Width_16Bits; I2S_InitStruct.I2S_DataFormat = I2S_Mode; I2S_InitStruct.I2S_DMACmd = I2S_DMA_DISABLE; I2S_Init(I2S0, &I2S_InitStruct); I2S_Cmd(I2S0, I2S_MODE_TX, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
I2S_InitStruct – [in] Pointer to a I2S_InitTypeDef structure which will be initialized.
-
void I2S_StructInit(I2S_InitTypeDef *I2S_InitStruct)
Fill each I2S_InitStruct member with its default value.
Example usage
void driver_i2s_init(void) { RCC_PeriphClockCmd(APB_I2S, APB_I2S_CLOCK, ENABLE); I2S_InitTypeDef I2S_InitStruct; I2S_StructInit(&I2S_InitStruct); I2S_InitStruct.I2S_ClockSource = I2S_CLK_40M; I2S_InitStruct.I2S_TxBClockMi = 0x271; I2S_InitStruct.I2S_TxBClockNi = 0x10; I2S_InitStruct.I2S_DeviceMode = I2S_DeviceMode_Master; I2S_InitStruct.I2S_TxChannelType = I2S_Channel_stereo; I2S_InitStruct.I2S_TxDataWidth = I2S_Width_16Bits; I2S_InitStruct.I2S_TxDataFormat = I2S_Mode; I2S_InitStruct.I2S_DMACmd = I2S_DMA_DISABLE; I2S_Init(I2S0, &I2S_InitStruct); I2S_Cmd(I2S0, I2S_MODE_TX, ENABLE); }
Note
The default settings for the I2S_InitStruct member are shown in the following table:
I2S_InitStruct member
Default value
I2S_ClockSource
I2S_Scheme
I2S_TxBClockMi
0x271
I2S_TxBClockNi
0x10
I2S_TxBClockDiv
0x3F
I2S_RxBClockMi
0x271
I2S_RxBClockNi
0x10
I2S_RxBClockDiv
0x3F
I2S_DeviceMode
I2S_TxChannelType
I2S_RxChannelType
I2S_TxChSequence
I2S_RxChSequence
I2S_TxDataFormat
I2S_RxDataFormat
I2S_TxBitSequence
I2S_RxBitSequence
I2S_TxDataWidth
I2S_RxDataWidth
I2S_TxChannelWidth
I2S_RxChannelWidth
I2S_TxFifoUsed
I2S_RxFifoUsed
I2S_TxWaterlevel
16
I2S_RxWaterlevel
16
I2S_BClockFixEn
DISABLE
- Parameters:
I2S_InitStruct – [in] Pointer to an I2S_InitTypeDef structure which will be initialized.
-
void I2S_Cmd(I2S_TypeDef *I2Sx, uint32_t mode, FunctionalState NewState)
Enable or disable the selected I2S mode.
Example usage
void driver_i2s_init(void) { RCC_PeriphClockCmd(APB_I2S, APB_I2S_CLOCK, ENABLE); I2S_InitTypeDef I2S_InitStruct; I2S_StructInit(&I2S_InitStruct); I2S_InitStruct.I2S_ClockSource = I2S_CLK_40M; I2S_InitStruct.I2S_TxBClockMi = 0x271; I2S_InitStruct.I2S_TxBClockNi = 0x10; I2S_InitStruct.I2S_DeviceMode = I2S_DeviceMode_Master; I2S_InitStruct.I2S_TxChannelType = I2S_Channel_stereo; I2S_InitStruct.I2S_TxDataWidth = I2S_Width_16Bits; I2S_InitStruct.I2S_TxDataFormat = I2S_Mode; I2S_InitStruct.I2S_DMACmd = I2S_DMA_DISABLE; I2S_Init(I2S_NUM, &I2S_InitStruct); I2S_Cmd(I2S_NUM, I2S_MODE_TX, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
mode – [in] Selected I2S operation mode. This parameter can be the following values:
I2S_MODE_TX: Transmission mode.
I2S_MODE_RX: Receiving mode.
NewState – [in] New state of the operation mode.
ENABLE: Enable the specified mode of I2S.
DISABLE: Disable the specified mode of I2S.
-
void I2S_INTConfig(I2S_TypeDef *I2Sx, uint32_t I2S_INT, FunctionalState newState)
Enable or disable the specified I2S interrupt source.
Example usage
void i2s_demo(void) { I2S_INTConfig(I2S0, I2S_INT_TF_EMPTY, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
I2S_INT – [in] Specify the specified interrupt of I2S. This parameter can be the following values, refer to I2S Interrupt Definition.
I2S_INT_TX_IDLE: Transmit idle interrupt source.
I2S_INT_RF_EMPTY: Receive FIFO empty interrupt source.
I2S_INT_TF_EMPTY: Transmit FIFO empty interrupt source.
I2S_INT_RF_FULL: Receive FIFO full interrupt source.
I2S_INT_TF_FULL: Transmit FIFO full interrupt source.
I2S_INT_RX_READY: Ready to receive interrupt source.
I2S_INT_TX_READY: Ready to transmit interrupt source.
newState – [in] New state of the specified I2S interrupt.
ENABLE: Enable the specified interrupt of I2S.
DISABLE: Disable the specified interrupt of I2S.
-
ITStatus I2S_GetINTStatus(I2S_TypeDef *I2Sx, uint32_t I2S_INT)
Get the specified I2S interrupt status.
Example usage
void i2s_demo(void) { ITStatus int_status = I2S_GetINTStatus(I2S0, I2S_INT_TF_EMPTY); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
I2S_INT – [in] Specify the specified interrupt of I2S. This parameter can be one of the following values, refer to I2S Interrupt Definition.
I2S_INT_TX_IDLE: Transmit idle interrupt.
I2S_INT_RF_EMPTY: Receive FIFO empty interrupt.
I2S_INT_TF_EMPTY: Transmit FIFO empty interrupt.
I2S_INT_RF_FULL: Receive FIFO full interrupt.
I2S_INT_TF_FULL: Transmit FIFO full interrupt.
I2S_INT_RX_READY: Ready to receive interrupt.
I2S_INT_TX_READY: Ready to transmit interrupt.
- Returns:
The status of I2S specified interrupt.
SET: The interrupt status of I2S is set.
RESET: The interrupt status of I2S has not been set.
-
void I2S_ClearINTPendingBit(I2S_TypeDef *I2Sx, uint32_t I2S_CLEAR_INT)
Clear the I2S interrupt pending bit.
Example usage
void i2s_demo(void) { I2S_ClearINTPendingBit(I2S0, I2S_CLEAR_INT_RX_READY); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
I2S_CLEAR_INT – [in] Specify the interrupt pending bit to clear. This parameter can be any combination of the following values:
I2S_CLEAR_INT_RX_READY: Clear ready to receive interrupt.
I2S_CLEAR_INT_TX_READY: Clear ready to transmit interrupt.
-
void I2S_SendData(I2S_TypeDef *I2Sx, uint32_t Data)
Transmits a data through the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SendData(I2S0, 0x02); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
Data – [in] Data to be transmitted.
-
uint32_t I2S_ReceiveFIFOData(I2S_TypeDef *I2Sx)
Received data by the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint32_t data = I2S_ReceiveData(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
- Returns:
Return the most recent received data.
-
uint8_t I2S_GetTxFIFOFreeLen(I2S_TypeDef *I2Sx)
Get transmit FIFO free length by the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint8_t data_len = I2S_GetTxFIFOFreeLen(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
- Returns:
The free length of transmit FIFO .
-
uint8_t I2S_GetRxFIFOLen(I2S_TypeDef *I2Sx)
Get receive FIFO data length by the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint8_t data_len = I2S_GetRxFIFOLen(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
- Returns:
The data length of the receive FIFO.
-
uint8_t I2S_GetTxErrCnt(I2S_TypeDef *I2Sx)
Get the send error counter value by the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint8_t conter = I2S_GetTxErrCnt(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
- Returns:
The send error counter value.
-
uint8_t I2S_GetRxErrCnt(I2S_TypeDef *I2Sx)
Get the reception error counter value by the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint8_t conter = I2S_GetRxErrCnt(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
- Returns:
The reception error counter value.
-
void I2S_SwapBytesForSend(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio data bytes sequence that is sent by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapBytesForSend(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
NewState – [in] New state of the bytes sequence.
ENABLE: Enable swapping of the sent audio data byte sequence.
DISABLE: Disable swapping of the sent audio data byte sequence.
-
void I2S_SwapBytesForRead(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio data bytes sequence that is read by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapBytesForRead(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
NewState – [in] New state of the bytes sequence.
ENABLE: Enable the swapping of the audio data byte sequence that is read.
DISABLE: Disable the swapping of the audio data byte sequence that is read.
-
void I2S_SwapLRChDataForSend(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio channel data that is sent by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapLRChDataForSend(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
NewState – [in] New state of the left and right channel data sequence.
ENABLE: Enable swapping of the sent audio channel data sequence.
DISABLE: Disable swapping of the sent audio channel data sequence.
-
void I2S_SwapLRChDataForRead(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio channel data that is read by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapLRChDataForRead(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
NewState – [in] New state of the left and right channel data sequence.
ENABLE: Enable the swapping of the audio channel data sequence that is read.
DISABLE: Disable the swapping of the audio channel data sequence that is read.
-
void I2S_MCLKOutputSelectCmd(I2S_TypeDef *I2Sx, FunctionalState NewState)
Enable or disable the MCLK output selection.
Example usage
void i2s_demo(void) { I2S_MCLKOutputSelectCmd(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
NewState – [in] New state of MCLK output.
ENABLE: Enable the MCLK output selection.
DISABLE: Disable the MCLK output selection.
-
void I2S_WithExtCodecCmd(I2S_TypeDef *I2Sx, FunctionalState NewState)
I2S0 communication selection which can be from internal codec or external codec.
Example usage
void i2s_demo(void) { I2S_WithExtCodecCmd(ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
NewState – [in] New state of I2S0 communication selection.
ENABLE: I2S communication selects the internal codec.
DISABLE: I2S communication selects the external codec.
-
void I2S_UpdateBClk(I2S_TypeDef *I2Sx, uint32_t dir, uint16_t I2S_BClockMi, uint16_t I2S_BClockNi)
Configure BCLK clock.
Example usage
void i2s_demo(void) { I2S_UpdateBClk(I2S0, 0x271, 0x10); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
dir – [in] Selected I2S operation mode. This parameter can be the following values:
I2S_MODE_TX: Transmission mode.
I2S_MODE_RX: Receiving mode.
I2S_BClockMi – [in] Mi parameter.
I2S_BClockNi – [in] Ni parameter.
-
FlagStatus I2S_GetTxBClkStatus(I2S_TypeDef *I2Sx)
Get Tx BCLK clock status.
Example usage
void i2s_demo(void) { FlagStatus status = I2S_GetTxBClkStatus(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
- Returns:
Execution status.
SET: BLCK is updating.
RESET: BLCK update is done.
-
FlagStatus I2S_GetRxBClkStatus(I2S_TypeDef *I2Sx)
Get Rx BCLK clock status.
Example usage
void i2s_demo(void) { FlagStatus status = I2S_GeRxBClkStatus(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral. Refer to I2S Declaration.
- Returns:
Execution status.
SET: BLCK is updating.
RESET: BLCK update is done.
-
void I2S_DeInit(I2S_TypeDef *I2Sx)