当前位置:网站首页>STM32 uses SPI mode to drive TFT-LCD optimization code of hx8347 scheme
STM32 uses SPI mode to drive TFT-LCD optimization code of hx8347 scheme
2022-06-26 00:52:00 【To, violet】
I need to use one when I am working on a small project recently LCD display , Because I don't usually use this kind of display screen and don't know the commonly used display screen driver IC So I chose this driver IC. After arrival, the code provided by the merchant is only some basic writing points 、 Fill and character display functions , And there is no optimization , In addition, the display screen adopts SPI The maximum speed of protocol affinity test cannot be higher than 36M/bit. Cause the display to write a full screen once 0.4s About time . This speed is almost unacceptable . So based on this IC Driven TFT-LCD The author has optimized some necessary functions . Mainly using SPI coordination STM32 Of DMA To speed up . The optimized speed can reach almost every second 20-30 Around the frame .
First of all SPI and DMA Initialization code part of
void SPI_init()
{
SPI_InitTypeDef SPI_InitStructure;
//SPI1 Mouth initialization
/* Configure SPI1 pins: SCK, MISO and MOSI */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //SPI1 Set to two-wire full duplex
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; // Set up SPI1 Main mode
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //SPI Send receive 8 Bit frame structure
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; // The serial clock is not operating , The clock is low
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // The first clock edge starts sampling data
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS The signal is controlled by software ( Use SSI position ) management
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; //SPI Baud rate prescaler value is 8
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; // Data transfer from MSB Bit start
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC The polynomial of the value calculation
SPI_Init(SPI1, &SPI_InitStructure); // according to SPI_InitStruct The parameter specified in SPI1 register
/* Enable SPI1 */
SPI_Cmd(SPI1, ENABLE); // Can make SPI1 peripherals
}
void SPI_DAM_init()
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4001300C; // Set up Receiving peripherals (0x4001300C) Address ( source address )
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)g_cSbuff; // Set up SRAM Storage address ( source address )
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // Transmission direction Memory - peripherals
DMA_InitStructure.DMA_BufferSize = DMA_Buff; // Set up SPI1 Receiving length
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // Peripheral address increment ( unchanged )
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // Memory address increment ( change )
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; // Peripheral transmission width ( byte )
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; // Memory transfer width ( byte )
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // transport , Stop after one transmission , Do not reload
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; // Interrupt mode - high ( Level three )
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // Memory to memory mode is prohibited
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, DISABLE); // Turn on DMA1_Channel3 Transmission complete interrupt
DMA_ITConfig(DMA1_Channel3, DMA_IT_TE, DISABLE); // Turn on DMA1_Channel3 Transmission error interrupt
/* Enable SPI1 DMA TX request */
SPI1->CR2 |= 1<<1; // Send buffer DMA Can make
DMA_Cmd(DMA1_Channel3, DISABLE); // Turn on DMA passageway DMA1_Channel3
}Then, the memory management method is used to dynamically give DMA Allocate memory , The following is the optimized filling function
/*******************************************************************************
* Function Name : SPI1_Send
* Description : SPI1 Of DMA Mode sending
* Input : SPI1_TX_Buff[SPI1_SendBufferSize]
* Output : None
* Return : None
* Attention : close DMA passageway 3 Must wait before TXE by 1, The waiting busy flag is 0
*******************************************************************************/
void SPI_DMA_TXD(u32 Num)
{
DMA1_Channel3->CPAR = 0x4001300C; // Peripheral address
DMA1_Channel3->CMAR = (u32) g_cSbuff; //mem Address
DMA1_Channel3->CNDTR = Num ; // Transmission length
DMA1_Channel3->CCR = (0 << 14) | // Non memory to memory mode
(2 << 12) | // Channel priority is high
(0 << 11) | // Memory data width 8bit
(0 << 10) | // Memory data width 8bit
(0 << 9) | // Peripheral data width 8bit
(0 << 8) | // Peripheral data width 8bit
(1 << 7) | // Memory address increment mode
(0 << 6) | // Peripheral address increment mode ( No increase )
(0 << 5) | // Acyclic mode
(1 << 4) | // Read from memory
// (1 << 3) | // Allow transmission error interrupts
// (0 << 2) | // Allow half transmission interruptions
// (1 << 1) | // Allow transmission completion interrupt
(1); // Channel open
while(DMA_GetFlagStatus(DMA1_FLAG_TC3 )==RESET);// Wait for the transfer to complete
DMA_ClearFlag(DMA1_FLAG_TC3);// Clear the transmission completion flag bit
DMA_Cmd(DMA1_Channel3, DISABLE);// Close channel
myfree(0,g_cSbuff);// Free memory
}
/**********************************************
Function name :Lcd Fill function
function : fill Lcd Rectangular area specified on
Be careful :xStart and yStart Changes as the screen rotates , The position is at the four corners of the rectangle
Entrance parameters :xStart x The starting point of the direction
ySrart y The end point of the direction
xLong To select a rectangle x Direction length
yLong To select a rectangle y Direction length
Color Color
Return value : nothing
***********************************************/
void Lcd_ColorBox(u16 xStart,u16 yStart,u16 xLong,u16 yLong,u16 Color)
{
u32 i,j;
i = xLong*yLong;// Number of points entered
j = DMA_Buff/2;// The maximum number of points
BlockWrite(xStart,xStart+xLong-1,yStart,yStart+yLong-1);
do
{
if(i>j)
{
SPI_WriteNumber(Color,j);
i-=j;
}
else
{
SPI_WriteNumber(Color,i);
break;
}
}
while(1);
}
void SPI_WriteNumber(u16 Color,u32 Num)// write in num A little bit
{
unsigned int i;
if(Num <= DMA_Buff)
{
Num<<=1;//Num*2
g_cSbuff = mymalloc(0,Num);// Application memory
for(i=0;i<Num;i++,i++)
{
*(g_cSbuff+i) = Color>>8;
*(g_cSbuff+i+1) = Color;// Writing data
}
SPI_CS(0);
LCD_RS(1);
SPI_DMA_TXD(Num);//Num*2
SPI_CS(1);
}
}
Specific test project download link :STM32 Use SPI Way driven HX8347 Of the plan TFT-LCD Optimize the code .-C Document resources -CSDN library
https://download.csdn.net/download/qq_24025329/81010005
Limited author , Please correct me if there is any mistake .
边栏推荐
- Compiler Telegram Desktop end (tdesktop) en utilisant vs2022
- 每日一问:线程和进程的区别
- Comprehensive introduction to Simulink solver
- Why do we need to make panels and edges in PCB production
- Solution to component stele in SMT chip processing
- “Method Not Allowed“,405问题分析及解决
- Unified gateway
- .net使用Access 2010数据库
- Atlas200dk刷机
- Run the test program using rknn-toolkit-lite2 for rk3568 development board
猜你喜欢

Middle order clue binary tree

Why is it best to use equals for integer comparisons

debezium

mtb13_ Perform extract_ blend_ Super{candidate (primaryalternate) \u unique (nullable filtering \foreign\index\granulati

Flink报错:Error: A JNI error has occurred, please check your installation and try again

leetcode. 14 --- longest public prefix

Analyze the five root causes of product development failure

使用VS2022編譯Telegram桌面端(tdesktop)

Preorder and middle order traversal of forest

CXF
随机推荐
统一网关Gateway
SVN
Login interceptor
Redis的安装及启动
经典面试题之老鼠试药与汉明码
The maze of God's perspective in robot vision
react + router 框架下的路由跳转后缓存页面存初始参数
mtb13_ Perform extract_ blend_ Super{candidate (primaryalternate) \u unique (nullable filtering \foreign\index\granulati
Permission design = function permission + Data permission
11.1.1 overview of Flink_ Flink overview
Flink reports error: a JNI error has occurred, please check your installation and try again
Display unassigned virtual address after easyconnect connection
Compiler Telegram Desktop end (tdesktop) en utilisant vs2022
Is camkiia the same as gcamp6f?
Msp430f5529lp official board (red) can not debug the problem
ciscn_2019_en_2
Establish a j-link GDB cross debugging environment for Px4
213. house raiding II
SQL to retain the maximum value sorted by a field
Summary of common terms and knowledge in SMT chip processing industry