標(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)求幫助.
/**
* @brief 指定區(qū)域進(jìn)行顏色填充
* @param xs:起始列地址
* @param ys:起始行地址
* @param xe:結(jié)束列地址
* @param ye:結(jié)束行地址
* @param color:需要填充的顏色
* @retval 無
*/
void LCD_ColorFill(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t *color)
{
uint8_t count=0; /* 定義傳輸次數(shù) */
uint16_t t = 1;
uint32_t num, num1;
num = (xe - xs+1) * (ye - ys+1);
LCD_AddressSet(xs, ys, xe, ye); /* 設(shè)置顯示窗口 */
SPI_Cmd(BSP_SPI_PORT, DISABLE); /* 失能SPI */
SPI_DataSizeConfig(BSP_SPI_PORT, SPI_DataSize_16b); /* 設(shè)置SPI數(shù)據(jù)傳輸寬度:16bit */
BSP_SPI_CS_Clr();
SPI_Cmd(BSP_SPI_PORT, ENABLE); /* 使能SPI */
while (t)
{
if (num > 25600)
{
num -= 25600;
num1 = 25600;
count++;
}
else
{
t = 0;
num1 = num;
if(count!=0)
{
color += (25600*count); /* 地址跟隨自增 */
}
}
BSP_DMA_ConfigC(BSP_DMA_Channel, (uint32_t)&BSP_SPI_PORT->DR, (uint32_t)color, num1);
SPI_I2S_DMACmd(BSP_SPI_PORT, SPI_I2S_DMAReq_Tx, ENABLE);
BSP_DMA_Enable();
while (1)
{
if (DMA_GetFlagStatus(BSP_DMAy_Streamx, BSP_SPI_DMA_TX_FLAG) != RESET) /* 等待通道傳輸完成 */
{
DMA_ClearFlag(BSP_DMAy_Streamx, BSP_SPI_DMA_TX_FLAG); /* 清除通道傳輸完成標(biāo)志 */
break;
}
}
}
while (SPI_I2S_GetFlagStatus(BSP_SPI_PORT, SPI_I2S_FLAG_BSY) == SET); /* 檢測(cè)發(fā)送完成SPI外設(shè)處于空閑狀態(tài) */
BSP_SPI_CS_Set();
SPI_Cmd(BSP_SPI_PORT, DISABLE); /* 失能SPI */
SPI_DataSizeConfig(BSP_SPI_PORT, SPI_DataSize_8b); /* 設(shè)置SPI數(shù)據(jù)傳輸寬度:8bit */
SPI_Cmd(BSP_SPI_PORT, ENABLE); /* 使能SPI */
}
復(fù)制代碼
作者:
人工置頂員
時(shí)間:
2025-2-14 15:37
頂一下
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1