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);
}

参数:

None.

返回:

None.

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);
}

参数:
  • I2Sx[in] Selected I2S peripheral.

  • I2S_InitStruct[in] Pointer to a I2S_InitTypeDef structure that contains the configuration information for the specified I2S peripheral

返回:

None.

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);
}

参数:

I2S_InitStruct[in] Pointer to an I2S_InitTypeDef structure which will be initialized.

返回:

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);
}

参数:
  • 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.

返回:

None.

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);
}

参数:
  • 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: ENABLE or DISABLE.

返回:

None.

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);
}

参数:

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.

返回:

The new state of I2S_INT (SET or RESET).

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);
}

参数:

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.

返回:

None.

void I2S_SendData(I2S_TypeDef *I2Sx, uint32_t Data)

Transmits a data through the SPIx/I2Sx peripheral.

Example usage

void i2s_demo(void)
{
    I2S_SendData(I2S0, 0x02);
}

参数:
  • I2Sx[in] To select the I2Sx peripheral, x can be 0 or 1.

  • Data[in] Data to be transmitted.

返回:

None.

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);
}

参数:

I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

返回:

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);
}

参数:

I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

返回:

the transmit FIFO free length.

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);
}

参数:

I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

返回:

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);
}

参数:

I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

返回:

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);
}

参数:

I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

返回:

The reception error counter value .

void I2S_SwapBytesForSend(I2S_TypeDef *I2Sx, FunctionalState NewState)

Swap audio data bytes sequence which sent by the I2Sx peripheral.

Example usage

void i2s_demo(void)
{
    I2S_SwapBytesForSend(I2S0, ENABLE);
}

参数:
  • I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

  • NewState[in] New state of the bytes sequence. This parameter can be: ENABLE or DISABLE.

返回:

None.

void I2S_SwapBytesForRead(I2S_TypeDef *I2Sx, FunctionalState NewState)

Swap audio data bytes sequence which read by the I2Sx peripheral.

Example usage

void i2s_demo(void)
{
    I2S_SwapBytesForRead(I2S0, ENABLE);
}

参数:
  • I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

  • NewState[in] New state of the bytes sequence. This parameter can be: ENABLE or DISABLE.

返回:

None.

void I2S_SwapLRChDataForSend(I2S_TypeDef *I2Sx, FunctionalState NewState)

Swap audio channel data which sent by the I2Sx peripheral..

Example usage

void i2s_demo(void)
{
    I2S_SwapLRChDataForSend(I2S0, ENABLE);
}

参数:
  • 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.

返回:

None.

void I2S_SwapLRChDataForRead(I2S_TypeDef *I2Sx, FunctionalState NewState)

Swap audio channel data which read by the I2Sx peripheral.

Example usage

void i2s_demo(void)
{
    I2S_SwapLRChDataForRead(I2S0, ENABLE);
}

参数:
  • 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.

返回:

None.

void I2S_MCLKOutputSelectCmd(I2S_TypeDef *I2Sx)

MCLK output selection which can be from I2S0 or I2S1.

Example usage

void i2s_demo(void)
{
    I2S_MCLKOutputSelectCmd(I2S0);
}

参数:
  • I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

  • NewState[in] New state of MCLK output. This parameter can be: ENABLE or DISABLE.

返回:

None.

void I2S_WithExtCodecCmd(I2S_TypeDef *I2Sx, FunctionalState NewState)

I2S0 communication selection which can be from intrnal codec or external codec.

Example usage

void i2s_demo(void)
{
    I2S_WithExtCodecCmd(ENABLE);
}

参数:

NewState[in] new state of I2S0 communication selection. This parameter can be: ENABLE or DISABLE.

返回:

None.

void I2S_UpdateBClk(I2S_TypeDef *I2Sx, uint32_t dir, uint16_t I2S_BClockMi, uint16_t I2S_BClockNi)

Config BClk clock.

Example usage

void i2s_demo(void)
{
    FlagStatus status = I2S_UpdateBClk(I2S0, 0x271, 0x10);
}

参数:
  • I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

  • I2S_BClockMi[in] Mi parameter.

  • I2S_BClockNi[in] Ni parameter.

返回值:
  • SET – Success.

  • RESET – Failure.

返回:

Execution status.

FlagStatus I2S_GetBClkStatus(I2S_TypeDef *I2Sx)

Get BClk clock status.

Example usage

void i2s_demo(void)
{
    FlagStatus status = I2S_GeRxBClkStatus(I2S0);
}

参数:

I2Sx[in] To select I2Sx peripheral, where x can be: 0 or 1.

返回值:
  • SET – BLCK is updating.

  • RESET – BLCK update is done.

返回:

Execution status.