標(biāo)題: STM32f407使用SPI+DMA用LVGL作為GUI庫刷屏發(fā)生碎屏數(shù)據(jù)錯(cuò)亂問題 [打印本頁]

作者: luffyxixi    時(shí)間: 2025-2-13 17:29
標(biāo)題: STM32f407使用SPI+DMA用LVGL作為GUI庫刷屏發(fā)生碎屏數(shù)據(jù)錯(cuò)亂問題
在使用SPI刷屏?xí)r能夠完美實(shí)現(xiàn)刷屏效果。但加入DMA后效果就如視頻鏈接所示,數(shù)據(jù)產(chǎn)生錯(cuò)位,但又能馬上恢復(fù)正常,以下是我的刷屏代碼,請(qǐng)求幫助.
  1. /**
  2. * @brief   指定區(qū)域進(jìn)行顏色填充
  3. * @param   xs:起始列地址
  4. * @param   ys:起始行地址
  5. * @param   xe:結(jié)束列地址
  6. * @param   ye:結(jié)束行地址
  7. * @param   color:需要填充的顏色
  8. * @retval  無
  9. */
  10. void LCD_ColorFill(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t *color)
  11. {
  12.     uint8_t count=0;    /* 定義傳輸次數(shù) */
  13.     uint16_t t = 1;
  14.     uint32_t num, num1;
  15.     num = (xe - xs+1) * (ye - ys+1);
  16.     LCD_AddressSet(xs, ys, xe, ye);             /* 設(shè)置顯示窗口 */
  17.     SPI_Cmd(BSP_SPI_PORT, DISABLE);                     /* 失能SPI */
  18.     SPI_DataSizeConfig(BSP_SPI_PORT, SPI_DataSize_16b); /* 設(shè)置SPI數(shù)據(jù)傳輸寬度:16bit */
  19.     BSP_SPI_CS_Clr();
  20.     SPI_Cmd(BSP_SPI_PORT, ENABLE); /* 使能SPI */
  21.     while (t)
  22.     {
  23.         if (num > 25600)
  24.         {
  25.             num -= 25600;
  26.             num1 = 25600;
  27.             count++;
  28.         }
  29.         else
  30.         {
  31.             t = 0;
  32.             num1 = num;
  33.             if(count!=0)
  34.             {
  35.                 color += (25600*count); /* 地址跟隨自增 */
  36.             }
  37.         }
  38.         BSP_DMA_ConfigC(BSP_DMA_Channel, (uint32_t)&BSP_SPI_PORT->DR, (uint32_t)color, num1);
  39.         SPI_I2S_DMACmd(BSP_SPI_PORT, SPI_I2S_DMAReq_Tx, ENABLE);
  40.         BSP_DMA_Enable();
  41.         while (1)
  42.         {
  43.             if (DMA_GetFlagStatus(BSP_DMAy_Streamx, BSP_SPI_DMA_TX_FLAG) != RESET) /* 等待通道傳輸完成 */
  44.             {
  45.                 DMA_ClearFlag(BSP_DMAy_Streamx, BSP_SPI_DMA_TX_FLAG); /* 清除通道傳輸完成標(biāo)志 */
  46.                 break;
  47.             }
  48.         }
  49.     }
  50.     while (SPI_I2S_GetFlagStatus(BSP_SPI_PORT, SPI_I2S_FLAG_BSY) == SET); /* 檢測(cè)發(fā)送完成SPI外設(shè)處于空閑狀態(tài) */
  51.     BSP_SPI_CS_Set();
  52.     SPI_Cmd(BSP_SPI_PORT, DISABLE);                    /* 失能SPI */
  53.     SPI_DataSizeConfig(BSP_SPI_PORT, SPI_DataSize_8b); /* 設(shè)置SPI數(shù)據(jù)傳輸寬度:8bit */
  54.     SPI_Cmd(BSP_SPI_PORT, ENABLE);                     /* 使能SPI */
  55. }
復(fù)制代碼

作者: 人工置頂員    時(shí)間: 2025-2-14 15:37
頂一下




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1