Beispiel #1
0
void Codec_AudioInterface_Init(uint32_t AudioFreq)
{
	//Setup I2C comms to codec
	Codec_GPIO_Init();
	I2C_Cntrl_Init();

	//Bring Up Codec via the I2C comms
	Codec_Init();

	//Invoke I2S Pin connections
	I2S_GPIO_Init();

	//Now, get down to defining I2S, Full Duplex, Codec Master Configuration
	I2S_InitTypeDef I2S_InitStructure;

	/* Enable the CODEC_I2S peripheral clock */
	RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);

	/* CODEC_I2S peripheral configuration */
	I2S_InitStructure.I2S_AudioFreq = AudioFreq;
	I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
	I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
	I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
	I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveTx;

	I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;

	/* Initialize the I2S peripheral with the structure above */
	I2S_Init(CODEC_I2S, &I2S_InitStructure);
	I2S_FullDuplexConfig(I2S3ext, &I2S_InitStructure);

	//Turn on the I2S interface
	I2S_Cmd(CODEC_I2S, ENABLE);
	I2S_Cmd(I2S3ext, ENABLE);

}
Beispiel #2
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main.
     */

  /* I2S configuration -------------------------------------------------------*/
  I2S_Config();

  /* SysTick configuration ---------------------------------------------------*/
  SysTickConfig();

  /* LEDs configuration ------------------------------------------------------*/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

#ifdef I2S_MASTER
  /* Master full Duplex configuration ----------------------------------------*/
  /* Clear the Rx Master Buffer */
  Fill_Buffer((uint8_t*)aRxMasterBuffer, (TX_MASTER_BUFFERSIZE*2));

  /* Configure I2Sx in Master Transmitter Mode */
  I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
  I2S_Init(I2Sx, &I2S_InitStructure);

  /* Configure the I2Sx_ext (the second instance) in Slave Receiver Mode */
  I2S_FullDuplexConfig(I2Sxext, &I2S_InitStructure);

  /* Enable the I2Sx peripheral */
  I2S_Cmd(I2Sx, ENABLE);
  /* Enable the I2Sx_ext peripheral for Full Duplex mode */
  I2S_Cmd(I2Sxext, ENABLE);

  /* Master full Duplex Communication ----------------------------------------*/
  /* Communication Full Duplex Started */
  ubBufferCounter = 0;
  while ((ubBufferCounter != TX_MASTER_BUFFERSIZE))
  {
    /* Data to transmitted through I2Sx SD pin */
    while (SPI_I2S_GetFlagStatus(I2Sx, SPI_I2S_FLAG_TXE ) != SET);
    SPI_I2S_SendData(I2Sx, aTxMasterBuffer[ubBufferCounter]);

    /* Data Received through I2Sx_ext SD pin */
    while (SPI_I2S_GetFlagStatus(I2Sxext, SPI_I2S_FLAG_RXNE ) != SET);
    aRxMasterBuffer[ubBufferCounter] = SPI_I2S_ReceiveData(I2Sxext);
    ubBufferCounter++;

  }
  /* Communication Full Duplex Finished */
  I2S_Cmd(I2Sx, DISABLE);
  I2S_Cmd(I2Sxext, DISABLE);

  /* Check Communication Result ----------------------------------------------*/
  if (Buffercmp((uint8_t*)aRxMasterBuffer, (uint8_t*)aTxSlaveBuffer, (TX_SLAVE_BUFFERSIZE*2)) != FAILED)
  {
    /* Turn ON LED2 and LED4 */
    STM_EVAL_LEDOn(LED2);
    STM_EVAL_LEDOn(LED4);
  }
#endif /* I2S_MASTER */

#ifdef I2S_SLAVE
  /* Slave full Duplex configuration ----------------------------------------*/
  /* Clear the RxBuffer */
  Fill_Buffer((uint8_t*)aRxSlaveBuffer, (TX_SLAVE_BUFFERSIZE*2));

  /* Configure I2Sx in Slave Receiver Mode */
  I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx;
  I2S_Init(I2Sx, &I2S_InitStructure);

  /* Configure the I2Sx_ext (the second instance) in Slave Transmitter Mode */
  I2S_FullDuplexConfig(I2Sxext, &I2S_InitStructure);

  /* Enable the I2Sx_ext peripheral for Full Duplex mode */
  I2S_Cmd(I2Sxext, ENABLE);
  /* Enable the I2Sx peripheral */
  I2S_Cmd(I2Sx, ENABLE);

  /* Slave full Duplex Communication -----------------------------------------*/
  /* Communication Full Duplex Started */
  ubBufferCounter = 0;
  while ((ubBufferCounter != TX_SLAVE_BUFFERSIZE) )
  {
    /* Data to transmitted through I2Sx_ext SD pin */
    while (SPI_I2S_GetFlagStatus(I2Sxext, SPI_I2S_FLAG_TXE ) != SET);
    SPI_I2S_SendData(I2Sxext, aTxSlaveBuffer[ubBufferCounter]);

    /* Data Received through I2Sx SD pin */
    while (SPI_I2S_GetFlagStatus(I2Sx, SPI_I2S_FLAG_RXNE ) != SET);
    aRxSlaveBuffer[ubBufferCounter] = SPI_I2S_ReceiveData(I2Sx);
    ubBufferCounter++;

  }
  /* Communication full duplex Finished */
  I2S_Cmd(I2Sx, DISABLE);
  I2S_Cmd(I2Sxext, DISABLE);

  /* Check Communication Results ---------------------------------------------*/
  if (Buffercmp((uint8_t*)aRxSlaveBuffer, (uint8_t*)aTxMasterBuffer, (TX_SLAVE_BUFFERSIZE*2)) != FAILED)
  {
    /* Turn ON LED3 */
    STM_EVAL_LEDOn(LED3);
  }
#endif /* I2S_SLAVE */

  while(1)
  {
  }
}