I2S Exported Functions
- group I2S_Exported_Functions
Functions
-
void I2S_DeInit(I2S_TypeDef *I2Sx)
Deinitializes the I2S peripheral registers to their default values.
Example usage
void driver_i2s_init(void) { I2S_DeInit(I2S0); }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 I2S Declaration.
-
void I2S_Init(I2S_TypeDef *I2Sx, I2S_InitTypeDef *I2S_InitStruct)
Initializes 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, where x can be 0 to 3 I2S Declaration.
I2S_InitStruct – [in] Pointer to a I2S_InitTypeDef structure that contains the configuration information for the specified I2S peripheral.
-
void I2S_StructInit(I2S_InitTypeDef *I2S_InitStruct)
Fills 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_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); }
Note
The default settings for the I2S_InitStruct member are shown in the following table:
I2S_InitStruct Member
Default Value
I2S_ClockSource
I2S_BClockMi
0x271
I2S_BClockNi
0x30
I2S_BClockDiv
0x3F
I2S_DeviceMode
I2S_TxChannelType
I2S_RxChannelType
I2S_TxDataFormat
I2S_RxDataFormat
I2S_TxBitSequence
I2S_RxBitSequence
I2S_TxDataWidth
I2S_Width_16Bits
I2S_RxDataWidth
I2S_Width_16Bits
I2S_TxChannelWidth
I2S_Width_32Bits
I2S_RxChannelWidth
I2S_Width_32Bits
I2S_TxTdmMode
I2S_RxTdmMode
I2S_DMACmd
I2S_TxWaterlevel
16
I2S_RxWaterlevel
16
I2S_ControlMode
- 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_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(I2S_NUM, &I2S_InitStruct); I2S_Cmd(I2S_NUM, I2S_MODE_TX, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 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.
I2S_MODE_TRX: Transmission & Receiving mode.
NewState – [in] New state of the operation mode. This parameter can be one of the following values:
ENABLE: Enable I2S transmission or receiving.
DISABLE: Disable I2S transmission or receiving.
-
void I2S_INTConfig(I2S_TypeDef *I2Sx, uint32_t I2S_MCU_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, where x can be 0 to 3 I2S Declaration.
I2S_INT – [in] Specifies the I2S interrupt source to be enable or disable. This parameter can be the following values:
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. This parameter can be one of the following values:
ENABLE: Enable the specified I2S interrupt.
DISABLE: Disable the specified I2S interrupt.
-
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, where x can be 0 to 3 I2S Declaration.
I2S_INT – [in] The specified I2S interrupt. This parameter can be one of the following values:
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 new state of I2S_INT (SET or RESET).
-
void I2S_ClearINTPendingBit(I2S_TypeDef *I2Sx, uint32_t I2S_CLEAR_INT)
Clears the I2S interrupt pending bits.
Example usage
void I2S_RX_Handler(void) { if (I2S_GetINTStatus(I2S_NUM, I2S_MCU_INT_RX_READY)) { //add user code here I2S_ClearINTPendingBit(I2S_NUM, I2S_CLEAR_INT_RX_READY); } }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 I2S Declaration.
I2S_CLEAR_INT – [in] Specifies 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_CodecSelInternal(I2S_TypeDef *I2Sx, FunctionalState newState)
Select I2S connect to external I2S peripheral or internal codec.
Example usage
void i2s_demo(void) { I2S_CodecSelInternal(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 I2S Declaration.
NewState – [in] New state of the I2S bridge selection. This parameter can be one of the following values:
ENABLE: Enable the I2Sx connect to internal codec.
DISABLE: Disable the I2Sx connect to internal codec.
-
void I2S_SendData(I2S_TypeDef *I2Sx, uint32_t Data)
Transmits a Data through the I2Sx peripheral.
Example usage
void i2s_send_data(void) { uint32_t pattern = 0x12345678; I2S_SendData(I2S0, pattern); }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 I2S Declaration.
Data – [in] Data to be transmitted.
-
uint32_t I2S_ReceiveData(I2S_TypeDef *I2Sx)
Returns the most recent received data by the I2Sx peripheral.
Example usage
void I2S_RX_Handler(void) { if (I2S_GetINTStatus(I2S0, I2S_MCU_INT_RX_READY)) { uint8_t len = I2S_GetRxFIFOLen(I2S0); for (uint8_t i = 0; i < len; i++) { data = I2S_ReceiveData(I2S0); } } }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 I2S Declaration.
- Returns:
The value of the received data.
-
uint8_t I2S_GetTxFIFODepth(I2S_TypeDef *I2Sx)
Returns the transmit FIFO free length by the I2Sx peripheral.
Example usage
void i2s_send_data(void) { if (I2S_GetTxFIFODepth(I2S0)) { //add user code here I2S_SendData(I2S_NUM, pattern); } }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 I2S Declaration.
- Returns:
The free length of the transmit FIFO.
-
uint8_t I2S_GetRxFIFOLen(I2S_TypeDef *I2Sx)
Returns the receive FIFO data length by the I2Sx peripheral.
Example usage
void I2S_RX_Handler(void) { if (I2S_GetINTStatus(I2S0, I2S_MCU_INT_RX_READY)) { uint8_t len = I2S_GetRxFIFOLen(I2S0); for (uint8_t i = 0; i < len; i++) { data = I2S_ReceiveData(I2S0); } } }
- Parameters:
I2Sx – [in] Selected I2S peripheral, where x can be 0 to 3 I2S Declaration.
- Returns:
The data length of the receive FIFO.
-
void I2S_DeInit(I2S_TypeDef *I2Sx)