2009-03-19 05:04 AM
Receiving blocks of data using SPI and DMA
2011-05-17 04:07 AM
I want to receive 48bit blocks of data using the STM32 as a SPI slave. The following code works fine:
(SPI2_DR_Address=SPI data register,SPI_RxBuffer_size=6 [...] DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)SPI2_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)g_SPI_RxBuffer.list; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = SPI_RxBuffer_size; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel4, &DMA_InitStructure); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; SPI_Init(SPI2, &SPI_InitStructure); [...] But I think it's rather inefficient as there are six bus accesses. I tried to change it to the the following: [...] DMA_InitStructure.DMA_BufferSize = 3; [...] DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; [...] SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; [...] Should only need three accesses, but instead of the real data, I only received zeroes... Any reasons or ideas for that strange behaviour?