2016-03-01 10:56 AM
So I am trying to output an I2S signal from a STM32F0 but although I believe I am initializing the peripheral correctly I am not getting any signal on the pins. I believe I am enabling the appropriate clocks and have the pin/DMA mapping correct based on the information I have. What am I missing? My code is as follows:
I2S_InitTypeDef I2S_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; DMA_InitTypeDef DMA_InitStructure; audio[0] = 0x5555; audio[1] = 0x0; audio[2] = 0x5555; audio[3] = 0x0; audio[4] = 0x5555; audio[5] = 0xffff; audio[6] = 0xffff; audio[7] = 0xffff; audio[8] = 0xffff; audio[9] = 0xffff; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_0); // I2S1 WS (word select) GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_0); // I2S1 CK (serial clock) GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_0); // I2S1 SD (serial data) // I2S1 peripheral configuration RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;//32b;//24b; I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k; I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;//Disable;// I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx; I2S_Init(SPI1, &I2S_InitStructure); // DMA configuration for audio streaming RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&SPI1->DR; // SPI data register for sending DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)audio; DMA_InitStructure.DMA_BufferSize = 10; 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_Init(DMA1_Channel3, &DMA_InitStructure); SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Tx, ENABLE); DMA_Cmd(DMA1_Channel3, ENABLE); // Enable/Disable DMA I2S_Cmd(SPI1, ENABLE);2016-03-01 11:39 AM
It turns out the particular STM32F03 model I was using does not implement I2S, so I switched to STM32F05 which seems to be working now.