2012-07-09 12:06 PM
I have a problem. I connected to spi stm32f103 and stm32f405. The data is transmitted, but only 8 bits. Initialization codes below. What is the problem?
Code for master (stm32f103):SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;SPI_InitStructure.SPI_Mode = SPI_Mode_Master;SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;SPI_InitStructure.SPI_CRCPolynomial = 15;SPI_Init(SPI1, &SPI_InitStructure);SPI_SSOutputCmd(SPI1, ENABLE);SPI_Cmd(SPI1, ENABLE);Code for slave (stm32f405):SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx; //SPI_Direction_2Lines_FullDuplex;SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;SPI_InitStructure.SPI_CRCPolynomial = 15;SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;SPI_Init(SPI1, &SPI_InitStructure);SPI_I2S_DeInit(SPI1);SPI_Cmd(SPI1, ENABLE); #spi-16-bit-mode-slave2012-07-09 02:22 PM
Want to do the SPI_I2S_DeInit(SPI1); BEFORE you initialize the SPI not after, and thus destroying all settings.
2012-07-10 11:52 AM
Clive, thank you for remark. Really not correct is written. By tests has adjusted spi slave.
Here is my code.For Master (F103):SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;SPI_InitStructure.SPI_Mode = SPI_Mode_Master;SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;SPI_InitStructure.SPI_CRCPolynomial = 15;SPI_Init(SPI1, &SPI_InitStructure);SPI_SSOutputCmd(SPI1, ENABLE);SPI_Cmd(SPI1, ENABLE);For Slave (F405):SPI_I2S_DeInit(SPI1);SPI_DataSizeConfig(SPI1,SPI_DataSize_16b);SPI_BiDirectionalLineConfig(SPI1,SPI_Direction_1Line_Rx);SPI_Cmd(SPI1, ENABLE);16 bits are sent it is correct.I do not understand why following code does not work for F405? Where mistake?SPI_I2S_DeInit(SPI1);SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Rx; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;SPI_InitStructure.SPI_CRCPolynomial = 15;SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;SPI_Init(SPI1, &SPI_InitStructure);SPI_Cmd(SPI1, ENABLE);I have adjusted DMA mode for spi1. Can who needs.DMA_DeInit(DMA2_Stream0); DMA_InitStructure.DMA_Channel=DMA_Channel_3;DMA_InitStructure.DMA_PeripheralBaseAddr=((uint32_t)SPI1+0x0c);DMA_InitStructure.DMA_Memory0BaseAddr=(uint32_t)&In_Value;DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralToMemory;DMA_InitStructure.DMA_BufferSize=1;DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Disable;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_VeryHigh;DMA_InitStructure.DMA_FIFOMode=DMA_FIFOMode_Disable;DMA_InitStructure.DMA_FIFOThreshold=DMA_FIFOThreshold_HalfFull;DMA_InitStructure.DMA_MemoryBurst=DMA_MemoryBurst_Single;DMA_InitStructure.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;DMA_Init(DMA2_Stream0, &DMA_InitStructure);SPI_DMACmd(SPI1,SPI_I2S_DMAReq_Rx,ENABLE);DMA_Cmd(DMA2_Stream0, ENABLE);Clive, You very experienced programmer, can prompt where me to find usb audio example for F4 controller?2012-07-10 01:31 PM
Doesn't look unreasonable. Make sure connect the master/slave MOSI and MISO one-to-one, ie not crossed over.
A useful example might be \STM32F4xx_DSP_StdPeriph_Lib_V1.0.1\Project\STM32F4xx_StdPeriph_Examples\SPI\SPI_TwoBoards\DataExchangeInterrupt I downloaded my last USB library from here : It has a USB/AUDIO example here : STM32_USB-Host-Device_Lib_V2.1.0\Project\USB_Device_Examples\AUDIO\ I'd also recommend pulling down the DSP library, and other STM32F4 firmwares/libraries as there are quite a mix of releases and examples. Why this hasn't be done in a more cohesive way I don't know, I've learned to download and archive everything.2012-07-11 12:53 PM
Thanks for the info. I found a working example for F4discovery usb audio.
The sound did not meet my expectations. :(