/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / SPI read data via DMA fail~

Username:     
Password:     
             

Forum

# 1   2011-12-06 11:55:40 SPI read data via DMA fail~

WillWu
New member
Registered: 2011-05-11
Posts: 7

SPI read data via DMA fail~

Hi~
I want to use SPI read data from device via DMA to decrease SPI wait time.
But I have no idea what wrong with these settings!
There have no SPI wave on the scope.
Please kindly to tell me what wrong I did, many thanks.

void API_SPI_DMA_Read_Bytes(u16 *pu16Buffer, u16 u16Len)
{   
    SPI_InitTypeDef  SPI_InitStructure;
    DMA_InitTypeDef DMA_InitStructure;   
   
    DMA_Cmd(SPI_DMA_CHANNEL, DISABLE);
    //DMA_DeInit(SPI_DMA_CHANNEL);
    DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&SPI1->DR;//SPI1_DR_Base;
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)pu16Buffer;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
    DMA_InitStructure.DMA_BufferSize = (u32)u16Len/2;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_HalfWord;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
    DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_Init(SPI_DMA_CHANNEL, &DMA_InitStructure);

    SPI_InitStructure->SPI_Direction = SPI_Direction_2Lines_RxOnly;//SPI_Direction_1Line_Rx;

    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_NSS_Hard;
    SPI_InitStructure->SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
    SPI_InitStructure->SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStructure->SPI_CRCPolynomial = 7;
    SPI_Init(SPI1, &SPI_InitStructure);

    SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Rx, ENABLE);

    /* Enable SPI1  */
    SPI_Cmd(SPI1, ENABLE);

    // SPI_DMA_CHANNEL = DMA1_Channel2
    DMA_Cmd(SPI_DMA_CHANNEL, ENABLE);

    /* Chip Select low */
    SPI_CS_LOW();
    while (u16Len>0)
    {
        //while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
        //SPI_I2S_ReceiveData(SPI1);
        API_SPI_SendByte(0);
        u16Len -= 2;
    }
    // SPI_DMA_RX_FLAG = DMA1_FLAG_TC2
    while(!DMA_GetFlagStatus(SPI_DMA_RX_FLAG));

    /* Chip Select high */
    SPI_CS_HIGH();
}

Offline

 

# 2   2011-12-06 11:57:26 SPI read data via DMA fail~

WillWu
New member
Registered: 2011-05-11
Posts: 7

Re: SPI read data via DMA fail~

BTW, I use platform is STM32F103ZE

Offline

 

# 3   2011-12-06 12:03:07 SPI read data via DMA fail~

WillWu
New member
Registered: 2011-05-11
Posts: 7

Re: SPI read data via DMA fail~

The normal SPI method is work if no use DMA.
I want to optimize SPI speed now.
Idealy, SPI clk = 6Mbps transmit 4kB data waste 5.3ms
But now, I check the waveform is taked 12~13ms

Offline

 

Board footer