2012-11-26 07:14 AM
Hello!
I try to receive data by I2S3 in slave mode.First of all I tried to program I2S controller and received data by program polling:while(1){
while( (SPI3->SR & SPI_I2S_FLAG_RXNE) == 0 );
SPDiffRxBuffer[TimeRXPointer][0] = (long)SPI3->DR;
if( ++TimeRXPointer >= SPDIFF_BUF_LEN ) TimeRXPointer = 0;
}
Second, I add function to use DMAstatic void I2S_DMA_Init( void )
{
DMA_InitTypeDef DMA_InitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
DMA_DeInit( DMA1_Stream2 );
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
DMA_InitStruct.DMA_Channel = DMA_Channel_2;
DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&(SPI3->DR);
DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)SPDiffRxBuffer;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStruct.DMA_BufferSize = SPDIFF_BUF_LEN * 4;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
DMA_InitStruct.DMA_Priority = DMA_Priority_High;
DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
while( DMA_GetCmdStatus( DMA1_Stream2 ) == ENABLE );
DMA_Init( DMA1_Stream2, &DMA_InitStruct );
DMA_ITConfig( DMA1_Stream2, DMA_IT_TC, ENABLE );
DMA_Cmd( DMA1_Stream2, ENABLE );
SPI_I2S_DMACmd( SPI3, SPI_I2S_DMAReq_Rx, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
and interrupt funtionvoid DMA1_Stream2_IRQHandler( void )
{
LEDOn( LED1 );
LEDOff( LED1 );
}
But IRQ not executed and data not filled array SPDiffRxBuffer. Bit RXNE is set and I can read data in polling. But not by DMA. What I write wrong?Addition: error in RM0090. Paragraf: 27.4.6 I2S slave modePoint:Reception sequenceError text:The operating mode is the same as for the transmission mode except for the point 1 (refer tothe procedure described in Section 27.4.6: I2S slave mode), where the configuration shouldset themaster reception mode
using the I2SCFG[1:0] bits in the SPI_I2SCFGR register.2012-11-26 08:05 AM
DMA_InitStruct.DMA_Channel = DMA_Channel_2;
Isn't SPI3_RX Channel 0? Channel 2 is I2S2_EXT_RX2012-11-26 08:20 AM
> Isn't SPI3_RX Channel 0? Channel 2 is I2S2_EXT_RX
Actually, DMA1 Channel2 Stream2 is I2S*3*_EXT_RX. It was a typo in version 1 of the manual. JW2012-11-26 08:51 AM
In RM0090 revision 3 is tha I can use or
DMA1 Channel2 Stream 2orDMA1 Channel3 Stream0for I2S3_EXT_RX. I tried both channels and no get success.2012-11-26 09:07 AM
It was a typo in version 1 of the manual.
Ok, thanks, noted. Rev 3 now posted.