cancel
Showing results for 
Search instead for 
Did you mean: 

problem with i2S full duplex mode with DMA for Rx- stm32f4x

usama
Associate II
Posted on January 29, 2014 at 13:03

Hello,

I am new to stm32fx and trying to interface stm32f415 with TI3204 codec, i am operating stm32 in master mode with codec in slave... currently i can not see MCLK being generated by controller i am pasting my current code any help would be highly appreciated

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_StructInit(&GPIO_InitStructure);

I2S_InitTypeDef I2S_InitType;

/* enable clock for I2S peripheral */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);

RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);

RCC_PLLI2SCmd(ENABLE);

/* GPIOA  & GPIOC Peripheral clock enable */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC, ENABLE);

/* I2S pins */

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Pin = I2S3_SCLK_PIN | I2S3_SD_PIN | I2S3_MCLK_PIN | I2S3_SD_EXT_PIN;

GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = I2S3_WS_PIN;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Enable alternate functionality of PA4 | PC7 | PC10 | PC12 | PC11 */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SPI3);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3);

GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3);

/* configure I2S port */

SPI_I2S_DeInit(SPI3);

I2S_InitType.I2S_AudioFreq = I2S_AudioFreq_48k;

I2S_InitType.I2S_MCLKOutput = I2S_MCLKOutput_Enable;

I2S_InitType.I2S_DataFormat = I2S_DataFormat_16b;

I2S_InitType.I2S_Mode = I2S_Mode_MasterTx;

I2S_InitType.I2S_Standard = I2S_Standard_Phillips;

I2S_InitType.I2S_CPOL = I2S_CPOL_Low;

I2S_Init(SPI3, &I2S_InitType);

/* operating I2S3ext as reciever */

I2S_InitType.I2S_Mode = I2S_Mode_MasterRx;

/* Configure for full duplex mode */

I2S_FullDuplexConfig(I2S3ext,&I2S_InitType);

/* enable both I2S3 as transmitter and I2S3ext as reciever */

I2S_Cmd(SPI3, ENABLE);

I2S_Cmd(I2S3ext,ENABLE);

DMA_InitTypeDef DMA_InitStructure;

DMA_StructInit(&DMA_InitStructure);

DMA_DeInit(DMA1_Stream0);

DMA_InitStructure.DMA_Channel = DMA_Channel_3;

DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(SPI3_BASE + 0x0C);

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&I2SRecieveBuffer;

DMA_InitStructure.DMA_BufferSize = I2S3_RX_BUFFER_SIZE;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;

DMA_Init(DMA1_Stream0, &DMA_InitStructure);

/* Enable DMA channel */

DMA_Cmd(DMA1_Stream0, ENABLE);

/* enable SPI interrupts to DMA */

SPI_I2S_DMACmd(I2S3ext, SPI_I2S_DMAReq_Rx, ENABLE);

SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_RXNE, ENABLE);

NVIC_InitTypeDef NVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);

/* Configure the SPI interrupt priority */

NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

#stm32 #dma #i2s #full-duplex
0 REPLIES 0