W806 SPI DMA数据不正确

发布于 2024-08-26 22:59:47

SPI驱动的屏幕,不使用DMA屏幕有内容;开启DMA后,屏幕没显示,采集的数据也不对
用的是SDK的相关代码

void spi_init(void)
{
    hspi.Instance = SPI;
    hspi.Init.Mode = SPI_MODE_MASTER;
    hspi.Init.CLKPolarity = SPI_POLARITY_LOW;
    hspi.Init.CLKPhase = SPI_PHASE_1EDGE;
    hspi.Init.NSS = SPI_NSS_SOFT;
    hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
    hspi.Init.FirstByte = SPI_LITTLEENDIAN;
    
    if (HAL_SPI_Init(&hspi) == HAL_OK)
    {
        
    }
}

void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
    __HAL_RCC_SPI_CLK_ENABLE();

     __HAL_AFIO_REMAP_SPI_CS(GPIOB, GPIO_PIN_4);
    __HAL_AFIO_REMAP_SPI_CLK(GPIOB, GPIO_PIN_2);
    __HAL_AFIO_REMAP_SPI_MISO(GPIOB, GPIO_PIN_3);
    __HAL_AFIO_REMAP_SPI_MOSI(GPIOB, GPIO_PIN_5);
    
    hdma_spi_tx.Instance = DMA_Channel0;
    hdma_spi_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
    hdma_spi_tx.Init.DestInc = DMA_DINC_DISABLE;
    hdma_spi_tx.Init.SrcInc = DMA_SINC_ENABLE;
    hdma_spi_tx.Init.DataAlignment = DMA_DATAALIGN_WORD;
    hdma_spi_tx.Init.Mode = DMA_MODE_NORMAL_SINGLE;
    hdma_spi_tx.Init.RequestSourceSel = DMA_REQUEST_SOURCE_SPI_TX;
    
    __HAL_LINKDMA(hspi, hdmatx, hdma_spi_tx);
    if (HAL_DMA_Init(&hdma_spi_tx) == HAL_OK)
    {
        
    }
    
    HAL_NVIC_SetPriority(SPI_LS_IRQn, 1);
    HAL_NVIC_EnableIRQ(SPI_LS_IRQn);
}
void dma_init(void)
{
    __HAL_RCC_DMA_CLK_ENABLE();
    
    HAL_NVIC_SetPriority(DMA_Channel0_IRQn, 0);
    HAL_NVIC_EnableIRQ(DMA_Channel0_IRQn);
}

{{0826.png(uploading...)}}

查看更多

关注者
0
被浏览
1.3k
1 个回答
zhihang9122
zhihang9122 2024-08-26
This guy hasn't written anything yet

0826.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览