2009-04-05 07:55 PM
Another question about SPI and DMA
2011-05-17 04:08 AM
I am trying to read a block of data from a flash memory device
into the STM32 using SPI and DMA. What I noticed on the o-scope is that when I write the command, 24-address, and dummy-byte there is a clock from the MCU (SPI master mode). After the last control byte (dummy) is sent, the read data is supposed to be clocked back into the STM32 but I don't see any clock pulses. I have the SPI device configured for DMA and the DMA engine configured for the number of bytes to read. I never see any data transferred though. Here is my config: /* SPI2 configuration */ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 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_2; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); DMA_DeInit(DMA_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&(SPI2->DR); DMA_InitStructure.DMA_MemoryBaseAddr = (u32)dma; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_BufferSize = 128; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA_Channel1, &DMA_InitStructure); // Enable DMA channel1 DMA_Cmd(DMA_Channel1, ENABLE); // tell the spi to use DMA SPI_DMACmd(SPI2, SPI_DMAReq_Rx, ENABLE); // enable spi device SPI_Cmd(SPI2, ENABLE); Any ideas how to get that clock to toggle? Victor2011-05-17 04:08 AM
DMA doesn't know that clock must be generated. It just waits for flag that received data arrived.
You must setup another channel for transmiting dummy data. Be careful with channel index (there is a table of available channels for SPI TX and SPI RX in reference manual) and enable sequence: enable RX first, then TX. [ This message was edited by: slawcus on 06-04-2009 08:31 ]