问答

汇集网友智慧,解决技术难题

21ic问答首页 - MM32SPIN系列使用dma spi clk始终8位之间有一个时间间隔

DMA spi ni ST IO struct

MM32SPIN系列使用dma spi clk始终8位之间有一个时间间隔

Aemaeth25012021-07-12
我使用MM32SPIN27PF 使用dma与硬件spi进行开发 初始化代码如下:    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);   //SPI2 clk enable
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

    //SPI_NSS
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_0);
    //SPI_SCK
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_0);
    //SPI_MISO
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_0);
    //SPI_MOSI
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_0);

    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_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
    SPI_InitStructure.SPI_DataWidth = SPI_DataWidth_8b;
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
    //        SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
    SPI_InitStructure.SPI_BaudRatePrescaler = spi_baud_div;
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
    SPI_Init(SPIx, &SPI_InitStructure);

    SPI_Cmd(SPIx, ENABLE);
    SPIM_TXEn(SPIx);
    SPIM_RXEn(SPIx);


  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);  //ʹÄÜDMA´«Êä

       
        //spi1 rx channel 2
    DMA_DeInit(DMA1_Channel2);   //½«DMAµÄͨµÀ2¼Ä´æÆ÷ÖØÉèΪȱʡֵ
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (SPI1->RXREG);  //DMAÍâÉèADC»ùµØÖ·
    DMA_InitStructure.DMA_MemoryBaseAddr = rx;  //DMAÄÚ´æ»ùµØÖ·
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC        ;  //Êý¾Ý´«Êä·½Ïò£¬´ÓÄÚ´æ¶ÁÈ¡·¢Ë͵½ÍâÉè
    DMA_InitStructure.DMA_BufferSize = rxbuffSize;  //DMAͨµÀµÄDMA»º´æµÄ´óС
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;  //ÍâÉèµØÖ·¼Ä´æÆ÷²»±ä
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;  //ÄÚ´æµØÖ·¼Ä´æÆ÷µÝÔö
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;  //Êý¾Ý¿í¶ÈΪ8λDMA_PeripheralDataSize_Byte
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; //Êý¾Ý¿í¶ÈΪ8λDMA_MemoryDataSize_Byte
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;  //¹¤×÷ÔÚÕý³£»º´æģʽ
    DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; //DMAͨµÀ xÓµÓÐÖÐÓÅÏȼ¶
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;  //DMAͨµÀxûÓÐÉèÖÃΪÄÚ´æµ½ÄÚ´æ´«Êä
    DMA_Init(DMA1_Channel2, &DMA_InitStructure);  //¸ù¾ÝDMA_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯DMAµÄͨµÀUSART1_Tx_DMA_ChannelËù±êʶµÄ¼Ä´æÆ÷

       
        //spi1 tx channel 3
                DMA_DeInit(DMA1_Channel3); //spi1 tx channel 3
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) & (SPI1->TXREG); //UART2_DMA_TX????J???
    DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)tx;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//?????memory??????
                DMA_InitStructure.DMA_BufferSize = txbuffSize;//SPI1_DMA_TX???????
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
    DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_Init(DMA1_Channel3, &DMA_InitStructure);//SPI1 tX?DMA???3       
               
        SPI_DMACmd(SPI1,SPI_DMAReq_EN,ENABLE);

请问有人遇到过这种情况吗? 请问这是芯片设计导致的正常情况吗?
回答 +关注 15
3069人浏览 0人回答问题 分享 举报
0 个回答

您需要登录后才可以回复 登录 | 注册