I2S Exported Functions
- group I2S_Exported_Functions
Functions
-
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(I2S_NUM, &I2S_InitStruct); I2S_Cmd(I2S_NUM, I2S_MODE_TX, ENABLE); }
- Parameters:
I2Sx – [in] selected I2S peripheral.
I2S_InitStruct – [in] pointer to an I2S_InitTypeDef structure that contains the configuration information for the specified I2S peripheral
- Returns:
None.
-
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.
- Returns:
None.
-
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_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:
I2S_InitStruct – [in] pointer to an I2S_InitTypeDef structure which will be initialized.
- Returns:
None
-
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.
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. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void I2S_INTConfig(I2S_TypeDef *I2Sx, uint32_t I2S_INT, FunctionalState newState)
Enable or disable the specified I2S interrupts.
Example usage
void i2s_demo(void) { I2S_INTConfig(I2S_NUM, I2S_INT_RX_READY, ENABLE); NVIC_InitTypeDef NVIC_InitStruct; NVIC_InitStruct.NVIC_IRQChannel = I2S0_RX_IRQn; NVIC_InitStruct.NVIC_IRQChannelPriority = 3; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStruct); }
- Parameters:
I2S_INT – [in] Specify the I2S interrupt sources to be enable or disable. This parameter can be 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.
NewState – [in] new state of the specified I2S interrupts. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
ITStatus I2S_GetINTStatus(I2S_TypeDef *I2Sx, uint32_t I2S_INT)
Get the specified I2S flag status.
Example usage
void I2S0_RX_Handler(void) { ITStatus int_status = I2S_GetINTStatus(I2S0, I2S_INT_RX_READY); }
- Parameters:
I2S_INT – [in] the specified I2S interrupt. This parameter can be one of the following values, which refers to I2S Interrupts 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 new state of I2S_FLAG (SET or RESET).
-
void I2S_ClearINTPendingBit(I2S_TypeDef *I2Sx, uint32_t I2S_CLEAR_INT)
Clear the I2S interrupt pending bits.
Example usage
void I2S0_RX_Handler(void) { I2S_ClearINTPendingBit(I2S0, I2S_INT_RX_READY); }
- Parameters:
I2S_CLEAR_INT – [in] Specify the interrupt pending bit to clear. This parameter can be any combination of the following values, which refers to I2S Clear Interrupts Definition.
I2S_CLEAR_INT_RX_READY: Clear ready to receive interrupt.
I2S_CLEAR_INT_TX_READY: Clear ready to transmit interrupt.
- Returns:
None
-
void I2S_SendData(I2S_TypeDef *I2Sx, uint32_t Data)
Transmit data through the SPIx/I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SendData(I2S0, 0x12348800); }
- Parameters:
I2Sx – [in] To select the I2Sx peripheral, x can be 0 or 1.
Data – [in] Data to be transmitted.
- Returns:
None
-
uint32_t I2S_ReceiveData(I2S_TypeDef *I2Sx)
Return the most recent received data by the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint32_t data = I2S_ReceiveData(I2S0); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
- Returns:
The value of the received data.
-
uint8_t I2S_GetTxFIFOFreeLen(I2S_TypeDef *I2Sx)
Return the transmit FIFO free length of the I2Sx peripheral.
Example usage
void i2s_demo(void) { if (I2S_GetTxFIFOFreeLen(I2S0)) { I2S_SendData(I2S0, i++); } }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
- Returns:
The free length of the transmit FIFO.
-
uint8_t I2S_GetRxFIFOLen(I2S_TypeDef *I2Sx)
Return the receive FIFO data length of the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint8_t len = I2S_GetRxFIFOLen(I2S0); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
- Returns:
The data length of the receive FIFO.
-
uint8_t I2S_GetTxErrCnt(I2S_TypeDef *I2Sx)
Return the send error counter value of the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint8_t len = I2S_GetTxErrCnt(I2S0); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
- Returns:
The send error counter value.
-
uint8_t I2S_GetRxErrCnt(I2S_TypeDef *I2Sx)
Return the reception error counter value of the I2Sx peripheral.
Example usage
void i2s_demo(void) { uint8_t len = I2S_GetRxErrCnt(I2S0); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
- Returns:
The reception error counter value.
-
void I2S_SwapBytesForSend(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio data byte sequence sent by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapBytesForSend(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
NewState – [in] New state of the byte sequence. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void I2S_SwapBytesForRead(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio data byte sequence read by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapBytesForRead(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
NewState – [in] New state of the byte sequence. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void I2S_SwapLRChDataForSend(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio channel data sent by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapLRChDataForSend(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
NewState – [in] New state of the left and right channel data sequence. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void I2S_SwapLRChDataForRead(I2S_TypeDef *I2Sx, FunctionalState NewState)
Swap audio channel data read by the I2Sx peripheral.
Example usage
void i2s_demo(void) { I2S_SwapLRChDataForRead(I2S0, ENABLE); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
NewState – [in] New state of the left and right channel data sequence. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void I2S_MCLKOutputSelectCmd(I2S_TypeDef *I2Sx)
MCLK output selection, only I2S0 can be selected.
Example usage
void i2s_demo(void) { I2S_MCLKOutputSelectCmd(I2S0); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, only I2S0 can be selected.
NewState – [in] New state of MCLK output. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
void I2S0_WithExtCodecCmd(FunctionalState NewState)
I2S0 communication selection which can be from internal codec or external codec.
Example usage
void i2s_demo(void) { I2S0_WithExtCodecCmd(ENABLE); }
- Parameters:
NewState – [in] New state of I2S0 communication selection. This parameter can be: ENABLE or DISABLE.
- Returns:
None.
-
FlagStatus I2S_UpdateBClk(I2S_TypeDef *I2Sx, uint16_t I2S_BClockMi, uint16_t I2S_BClockNi)
Update BClk clock parameter.
Example usage
void i2s_demo(void) { uint16_t I2S_BClockMi = 0x271; uint16_t I2S_BClockNi = 0x10; I2S_UpdateBClk(I2S0, I2S_BClockMi, I2S_BClockNi); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
I2S_BClockMi – [in] Mi parameter.
I2S_BClockNi – [in] Ni parameter.
- Returns:
Execution status: SET: success, RESET: failure.
-
FlagStatus I2S_GetBClkStatus(I2S_TypeDef *I2Sx)
Get BClk clock status.
Example usage
void i2s_demo(void) { FlagStatus status = I2S_GetBClkStatus(I2S0); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
- Returns:
Execution status: SET: BLCK is updating, RESET: BLCK update is done.
-
void I2S_ConfigChannelType(I2S_TypeDef *I2Sx, uint32_t I2S_ChannelType)
Configure Channel parameter.
Example usage
void i2s_demo(void) { I2S_ConfigChannelType(I2S0, I2S_Channel_stereo); }
- Parameters:
I2Sx – [in] To select I2Sx peripheral, where x can be: 0 or 1.
I2S_ChannelType – [in] The channel type used for the I2S communication. This parameter can be one of the following values, which refers to I2S Channel Type.
I2S_Channel_Mono: Mono channel.
I2S_Channel_stereo: Stereo channel.
- Returns:
None.
-
void I2S_Init(I2S_TypeDef *I2Sx, I2S_InitTypeDef *I2S_InitStruct)