[MCU] 【ACM32G103RCT6开发板测评】+ SPI方式驱动LCD显示屏测试

TL-LED   2024-1-20 18:23 楼主

测试下SPI方式驱动LCD显示屏。

 

一、硬件部分

 

1.1、电路板SPI1部分电路、

001.png

 

1.2、显示部分接口

002.png

 

二、程序部分

 

2.1、SPI硬件初始化部分代码

SP初始化代码在acm32g103_hal_msp.c

需要将SPI1修改为硬件对应的接口

void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
{
    /* 
      NOTE : This function should be modified by the user.
    */
    
    /* For Example */
    GPIO_InitTypeDef GPIO_Handle = {0}; 
    
    /* SPI1 */
    if (hspi->Instance == SPI1)
    {
        /* Enable Clock */
        __HAL_RCC_SPI1_CLK_ENABLE();
        __HAL_RCC_GPIOA_CLK_ENABLE();
        
        /*  PA4    CS        AF0 
            PA5    SCK       AF0       
            PA12   MOSI      AF0
            PA11   MISO      AF0
            PA7    IO2(WP)   AF3
            PA6    IO3(HOLD) AF3
        */
        
        GPIO_Handle.Pin = GPIO_PIN_4 | GPIO_PIN_5;
        GPIO_Handle.Mode = GPIO_MODE_AF_PP;
        GPIO_Handle.Pull = GPIO_PULLUP;
        GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
        GPIO_Handle.Alternate = GPIO_FUNCTION_0;
        HAL_GPIO_Init(GPIOA, &GPIO_Handle);
        
        //GPIO_Handle.Pin = GPIO_PIN_11 | GPIO_PIN_12 ;
				GPIO_Handle.Pin = GPIO_PIN_6 | GPIO_PIN_7 ;
        GPIO_Handle.Mode = GPIO_MODE_AF_PP;
        GPIO_Handle.Pull = GPIO_PULLUP;
        GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
        GPIO_Handle.Alternate = GPIO_FUNCTION_0;
        HAL_GPIO_Init(GPIOA, &GPIO_Handle);
        
        printfS("SPI1 PINs selected:\r\n");
        printfS("SPI1 CS  :PA4\r\n");
        printfS("SPI1 SCK :PA5\r\n");
        printfS("SPI1 MOSI:PA12\r\n");
        printfS("SPI1 MISO:PA11\r\n");
        
        if (hspi->Init.X_Mode == SPI_4X_MODE) 
        {
            GPIO_Handle.Pin = GPIO_PIN_6 | GPIO_PIN_7;
            GPIO_Handle.Mode = GPIO_MODE_AF_PP;
            GPIO_Handle.Pull = GPIO_PULLUP;
            GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
            GPIO_Handle.Alternate = GPIO_FUNCTION_3;
            
            HAL_GPIO_Init(GPIOA, &GPIO_Handle);
            printfS("SPI1 WP  :PA7\r\n");
            printfS("SPI1 HOLD:PA6\r\n");
        }
        
        /* Clear Pending Interrupt */
        NVIC_ClearPendingIRQ(SPI1_IRQn);
        
        /* Enable External Interrupt */
        NVIC_EnableIRQ(SPI1_IRQn);
    }
    /* SPI2 */
    else if (hspi->Instance == SPI2) 
    {
       /* Enable Clock */
        __HAL_RCC_SPI2_CLK_ENABLE();
        __HAL_RCC_GPIOB_CLK_ENABLE();
        __HAL_RCC_GPIOC_CLK_ENABLE();
        
        /*  PB9    CS        AF3 
            PB8    SCK       AF3       
            PB7    MOSI      AF3
            PB6    MISO      AF3
            PC7    IO2(WP)   AF1
            PC6    IO3(HOLD) AF1
        */
        
        GPIO_Handle.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 ;
        GPIO_Handle.Mode = GPIO_MODE_AF_PP;
        GPIO_Handle.Pull = GPIO_PULLUP;
        GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
        GPIO_Handle.Alternate = GPIO_FUNCTION_3;
        HAL_GPIO_Init(GPIOB, &GPIO_Handle);
        
        printfS("SPI2 PINs selected:\r\n");
        printfS("SPI2 CS  :PB9\r\n");
        printfS("SPI2 SCK :PB8\r\n");
        printfS("SPI2 MOSI:PB7\r\n");
        printfS("SPI2 MISO:PB6\r\n");
        
        if (hspi->Init.X_Mode == SPI_4X_MODE) 
        {
            GPIO_Handle.Pin = GPIO_PIN_6 | GPIO_PIN_7;
            GPIO_Handle.Mode = GPIO_MODE_AF_PP;
            GPIO_Handle.Pull = GPIO_PULLUP;
            GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
            GPIO_Handle.Alternate = GPIO_FUNCTION_1;
            HAL_GPIO_Init(GPIOC, &GPIO_Handle);
            printfS("SPI2 WP  :PC7\r\n");
            printfS("SPI2 HOLD:PC6\r\n");
        }
        
        /* Clear Pending Interrupt */
        NVIC_ClearPendingIRQ(SPI2_IRQn);
        
        /* Enable External Interrupt */
        NVIC_EnableIRQ(SPI2_IRQn);
    }
    /* SPI3 */
    else if (hspi->Instance == SPI3)
    {
        /* Enable Clock */
        __HAL_RCC_SPI3_CLK_ENABLE();
        __HAL_RCC_GPIOA_CLK_ENABLE();
        __HAL_RCC_GPIOC_CLK_ENABLE();
        
        /*  PA15   CS        AF4 
            PC10   SCK       AF2       
            PC12   MOSI      AF2
            PC11   MISO      AF2
            PC9    IO2(WP)   AF2
            PC8    IO3(HOLD) AF2
        */
        
        GPIO_Handle.Pin = GPIO_PIN_15 ;
        GPIO_Handle.Mode = GPIO_MODE_AF_PP;
        GPIO_Handle.Pull = GPIO_PULLUP;
        GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
        GPIO_Handle.Alternate = GPIO_FUNCTION_4;
        HAL_GPIO_Init(GPIOA, &GPIO_Handle);
        
        GPIO_Handle.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 ;
        GPIO_Handle.Mode = GPIO_MODE_AF_PP;
        GPIO_Handle.Pull = GPIO_PULLUP;
        GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
        GPIO_Handle.Alternate = GPIO_FUNCTION_2;
        HAL_GPIO_Init(GPIOC, &GPIO_Handle);
        
        printfS("SPI3 PINs selected:\r\n");
        printfS("SPI3 CS  :PA15\r\n");
        printfS("SPI3 SCK :PC10\r\n");
        printfS("SPI3 MOSI:PC12\r\n");
        printfS("SPI3 MISO:PC11\r\n");
        
        if (hspi->Init.X_Mode == SPI_4X_MODE) 
        {
            GPIO_Handle.Pin = GPIO_PIN_8 | GPIO_PIN_9;
            GPIO_Handle.Mode = GPIO_MODE_AF_PP;
            GPIO_Handle.Pull = GPIO_PULLUP;
            GPIO_Handle.Drive = GPIO_DRIVE_LEVEL3;
            GPIO_Handle.Alternate = GPIO_FUNCTION_2;
            HAL_GPIO_Init(GPIOC, &GPIO_Handle);
            printfS("SPI3 WP  :PC9\r\n");
            printfS("SPI3 HOLD:PC8\r\n");
        }
        
        /* Clear Pending Interrupt */
        NVIC_ClearPendingIRQ(SPI3_IRQn);
        
        /* Enable External Interrupt */
        NVIC_EnableIRQ(SPI3_IRQn);
    }
    
    printfS("Modify HAL_SPI_MspInit() if you select other SPI PINs\r\n\r\n");
}

 

2.2、SPI驱动程序代码

spi.c

使用SPI的DMA方式驱动

#include "main.h"

SPI_HandleTypeDef SPI_Handle;


void init_spi(void)
{
	SPI_Handle.Instance                 = SPI1;
	SPI_Handle.Init.SPI_Mode            = SPI_MODE_MASTER;
	SPI_Handle.Init.SPI_Work_Mode       = SPI_WORK_MODE_0;
	SPI_Handle.Init.X_Mode              = SPI_1X_MODE;
	SPI_Handle.Init.First_Bit           = SPI_FIRSTBIT_MSB;
	SPI_Handle.Init.BaudRate_Prescaler  = SPI_BAUDRATE_PRESCALER_4;//SPI_BAUDRATE_PRESCALER_64;

	HAL_SPI_Init(&SPI_Handle);
}


//void spi_send(uint8_t *pData, uint32_t Size)
//{
//	HAL_SPI_Transmit(&SPI_Handle, pData, Size, 0); 
//}

//DMA
DMA_HandleTypeDef DMA_SPIR_Handle;
DMA_HandleTypeDef DMA_SPIT_Handle;
void DMA_SPITransmit_Init(void)
{
	__HAL_RCC_DMA2_CLK_ENABLE();
	
	DMA_SPIT_Handle.Instance            = DMA2_Channel1;
	DMA_SPIT_Handle.Init.DataFlow       = DMA_DATAFLOW_M2P;
	DMA_SPIT_Handle.Init.ReqID          = DMA2_REQ1_SPI1_SEND;//DMA2_REQ47_SPI3_SEND;
	DMA_SPIT_Handle.Init.SrcInc         = DMA_SRCINC_ENABLE;
	DMA_SPIT_Handle.Init.DestInc        = DMA_DESTINC_DISABLE;
	DMA_SPIT_Handle.Init.SrcWidth       = DMA_SRCWIDTH_BYTE;
	DMA_SPIT_Handle.Init.DestWidth      = DMA_DESTWIDTH_BYTE;

	/*-----------------------------------------------------------------------------------*/
	/* Note:If user dons not apply interrupt, Set DMA_ITC_Callback?¢DMA_IE_Callback NULL */
	/*-----------------------------------------------------------------------------------*/
	DMA_SPIT_Handle.XferCpltCallback = NULL;
	DMA_SPIT_Handle.XferErrorCallback  = NULL;

	HAL_DMA_Init(&DMA_SPIT_Handle);
	
	SPI_Handle.HDMA_Tx = &DMA_SPIT_Handle;
}

void DMA_SPIReceive_Init(void)
{
    __HAL_RCC_DMA2_CLK_ENABLE();
    
    DMA_SPIR_Handle.Instance            = DMA2_Channel2;
    DMA_SPIR_Handle.Init.DataFlow       = DMA_DATAFLOW_P2M;
    DMA_SPIR_Handle.Init.ReqID          = DMA2_REQ2_SPI1_RECV;//DMA2_REQ48_SPI3_RECV;
    DMA_SPIR_Handle.Init.SrcInc         = DMA_SRCINC_DISABLE;
    DMA_SPIR_Handle.Init.DestInc        = DMA_DESTINC_ENABLE;
    DMA_SPIR_Handle.Init.SrcWidth       = DMA_SRCWIDTH_BYTE;
    DMA_SPIR_Handle.Init.DestWidth      = DMA_DESTWIDTH_BYTE;

    /*-----------------------------------------------------------------------------------*/
    /* Note:If user dons not apply interrupt, Set DMA_ITC_Callback, DMA_IE_Callback NULL */
    /*-----------------------------------------------------------------------------------*/
    DMA_SPIR_Handle.XferCpltCallback = NULL;
    DMA_SPIR_Handle.XferErrorCallback  = NULL;

    HAL_DMA_Init(&DMA_SPIR_Handle);
    
    SPI_Handle.HDMA_Rx = &DMA_SPIR_Handle;
}

void init_spi_dma(void)
{
	init_spi();
	DMA_SPITransmit_Init();
	DMA_SPIReceive_Init();
}


void spi_send(uint8_t *pData, uint32_t Size)
{
	//HAL_SPI_Transmit(&SPI_Handle, pData, Size, 0);
	HAL_SPI_Transmit_DMA(&SPI_Handle, pData, Size);
	while (HAL_SPI_GetTxState(&SPI_Handle) == SPI_TX_STATE_SENDING);	
}

 

2.3、LCD驱动程序代码

#include "main.h"

_lcd_dev lcddev;

void init_lcd_port(void)
{
	
	GPIO_InitTypeDef  GPIO_InitStruct;
	
	ILI_9341_DC_GPIO_CLK_ENABLE();
	ILI_9341_RES_GPIO_CLK_ENABLE();
	ILI_9341_CS_GPIO_CLK_ENABLE();

	GPIO_InitStruct.Pin       = ILI_9341_DC_PIN;
	GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;  
	GPIO_InitStruct.Pull      = GPIO_PULLUP;
	GPIO_InitStruct.Drive     = GPIO_DRIVE_LEVEL0;
	GPIO_InitStruct.Alternate = GPIO_FUNCTION_0;
	HAL_GPIO_Init(ILI_9341_DC_GPIO_PORT, &GPIO_InitStruct);
	
	GPIO_InitStruct.Pin       = ILI_9341_RES_PIN;
	GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;  
	GPIO_InitStruct.Pull      = GPIO_PULLUP;
	GPIO_InitStruct.Drive     = GPIO_DRIVE_LEVEL0;
	GPIO_InitStruct.Alternate = GPIO_FUNCTION_0;
	HAL_GPIO_Init(ILI_9341_RES_GPIO_PORT, &GPIO_InitStruct);
	
	GPIO_InitStruct.Pin       = ILI_9341_BLK_PIN;
	GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;  
	GPIO_InitStruct.Pull      = GPIO_PULLUP;
	GPIO_InitStruct.Drive     = GPIO_DRIVE_LEVEL0;
	GPIO_InitStruct.Alternate = GPIO_FUNCTION_0;
	HAL_GPIO_Init(ILI_9341_BLK_GPIO_PORT, &GPIO_InitStruct);	

	GPIO_InitStruct.Pin       = ILI_9341_CS_PIN;
	GPIO_InitStruct.Mode      = GPIO_MODE_OUTPUT_PP;  
	GPIO_InitStruct.Pull      = GPIO_PULLUP;
	GPIO_InitStruct.Drive     = GPIO_DRIVE_LEVEL0;
	GPIO_InitStruct.Alternate = GPIO_FUNCTION_0;
	HAL_GPIO_Init(ILI_9341_CS_GPIO_PORT, &GPIO_InitStruct);
}

static void LCD_RESET(void)
{
    LCD_RES_CLR;
    DELAY(100);
    LCD_RES_SET;
    DELAY(100);
}

static void LCD_WR_REG(uint8_t reg)
{
    LCD_DC_CLR;
	
		LCD_CS_CLR;
		spi_send(&reg, 1);
		LCD_CS_SET;
	
    LCD_DC_SET;
}

static void LCD_WR_DATA(uint8_t data)
{
    LCD_DC_SET;
	
		LCD_CS_CLR;
		spi_send(&data, 1);
		LCD_CS_SET;
}

static void LCD_WriteReg(uint8_t reg, uint16_t regdata)
{
    LCD_WR_REG(reg);
    LCD_WR_DATA(regdata);
}

static void LCD_WriteRAM_Prepare(void)
{
    LCD_WR_REG(lcddev.wramcmd);
}

static void LCD_WriteData_16Bit(uint16_t Data)
{
    uint8_t buf[2];
	
		buf[0] = Data >> 8;
    buf[1] = Data & 0xff;
	
    LCD_DC_SET;
		LCD_CS_CLR;
		spi_send(buf, 2);
		LCD_CS_SET;
}

void LCD_direction(uint8_t direction)
{
    lcddev.setxcmd = 0x2A;
    lcddev.setycmd = 0x2B;
    lcddev.wramcmd = 0x2C;
    switch (direction)
    {
    case 0:
        lcddev.width = LCD_W;
        lcddev.height = LCD_H;
        LCD_WriteReg(0x36, (1 << 3) | (0 << 6) | (0 << 7)); /* BGR==1,MY==0,MX==0,MV==0 */
        break;
    case 1:
        lcddev.width = LCD_H;
        lcddev.height = LCD_W;
        LCD_WriteReg(0x36, (1 << 3) | (0 << 7) | (1 << 6) | (1 << 5)); /* BGR==1,MY==1,MX==0,MV==1 */
        break;
    case 2:
        lcddev.width = LCD_W;
        lcddev.height = LCD_H;
        LCD_WriteReg(0x36, (1 << 3) | (1 << 6) | (1 << 7)); /* BGR==1,MY==0,MX==0,MV==0 */
        break;
    case 3:
        lcddev.width = LCD_H;
        lcddev.height = LCD_W;
        LCD_WriteReg(0x36, (1 << 3) | (1 << 7) | (1 << 5)); /* BGR==1,MY==1,MX==0,MV==1 */
        break;
    default:
        break;
    }
}

void LCD_SetWindows(uint16_t xStar, uint16_t yStar, uint16_t xEnd, uint16_t yEnd)
{
    LCD_WR_REG(lcddev.setxcmd);
    LCD_WR_DATA(xStar >> 8);
    LCD_WR_DATA(0x00FF & xStar);
    LCD_WR_DATA(xEnd >> 8);
    LCD_WR_DATA(0x00FF & xEnd);

    LCD_WR_REG(lcddev.setycmd);
    LCD_WR_DATA(yStar >> 8);
    LCD_WR_DATA(0x00FF & yStar);
    LCD_WR_DATA(yEnd >> 8);
    LCD_WR_DATA(0x00FF & yEnd);

    LCD_WriteRAM_Prepare();
}

void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
{
    LCD_SetWindows(Xpos, Ypos, Xpos, Ypos);
}

void LCD_Clear(uint16_t Color)
{
    unsigned int i, m;
    uint8_t buf[80];

    for (i = 0; i < 40; i++)
    {
        buf[2 * i] = Color >> 8;
        buf[2 * i + 1] = Color & 0xff;
    }

    LCD_SetWindows(0, 0, lcddev.width - 1, lcddev.height - 1);

    for (i = 0; i < lcddev.height; i++)
    {
        for (m = 0; m < lcddev.width;)
        {
            m += 40;
						LCD_CS_CLR;
            spi_send(buf, 80);
						LCD_CS_SET;
        }
    }
}

void LCD_Fill(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color)
{
    uint16_t i, j;
    LCD_SetWindows(xsta, ysta, xend - 1, yend - 1);
		LCD_DC_SET;
    for (i = ysta; i < yend; i++)
    {
        for (j = xsta; j < xend; j++)
        {
            LCD_WriteData_16Bit(color);
        }
    }
}

void lcd_fill_array_spi(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend, void *Image)
{
    uint32_t size = 0;

    size = (Xend - Xstart + 1) * (Yend - Ystart + 1) * 2;/*16bit*/
    LCD_SetWindows(Xstart, Ystart, Xend, Yend);
    LCD_DC_SET;
		LCD_CS_CLR;
    spi_send(Image, size);
		LCD_CS_SET;
}

static void _ili9341_init(void)
{
    LCD_WR_REG(0xCF);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0X83);
    LCD_WR_DATA(0X30);

    LCD_WR_REG(0xED);
    LCD_WR_DATA(0x64);
    LCD_WR_DATA(0x03);
    LCD_WR_DATA(0X12);
    LCD_WR_DATA(0X81);

    LCD_WR_REG(0xE8);
    LCD_WR_DATA(0x85);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x79);

    LCD_WR_REG(0xCB);
    LCD_WR_DATA(0x39);
    LCD_WR_DATA(0x2C);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x34);
    LCD_WR_DATA(0x02);

    LCD_WR_REG(0xF7);
    LCD_WR_DATA(0x20);

    LCD_WR_REG(0xEA);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x00);

    LCD_WR_REG(0xC0);   /* Power control */
    LCD_WR_DATA(0x26);  /* VRH[5:0] */

    LCD_WR_REG(0xC1);   /* Power control */
    LCD_WR_DATA(0x11);  /* SAP[2:0];BT[3:0] */

    LCD_WR_REG(0xC5);   /* VCM control */
    LCD_WR_DATA(0x35);
    LCD_WR_DATA(0x3E);

    LCD_WR_REG(0xC7);   /* VCM control2 */
    LCD_WR_DATA(0XBE);

    LCD_WR_REG(0x36);   /* Memory Access Control */
    LCD_WR_DATA(0x28);

    LCD_WR_REG(0x3A);
    LCD_WR_DATA(0x55);

    LCD_WR_REG(0xB1);
    LCD_WR_DATA(0x00);
    LCD_WR_DATA(0x1B);

    LCD_WR_REG(0xB6);   /* Display Function Control */
    LCD_WR_DATA(0x0A);
    LCD_WR_DATA(0xA2);

    LCD_WR_REG(0xF2);   /* 3Gamma Function Disable */
    LCD_WR_DATA(0x08);

    LCD_WR_REG(0x26);   /* Gamma curve selected */
    LCD_WR_DATA(0x01);

    LCD_WR_REG(0xE0);   /* set Gamma */
    LCD_WR_DATA(0X1F);
    LCD_WR_DATA(0X1A);
    LCD_WR_DATA(0X18);
    LCD_WR_DATA(0X0A);
    LCD_WR_DATA(0X0F);
    LCD_WR_DATA(0X06);
    LCD_WR_DATA(0X45);
    LCD_WR_DATA(0X87);
    LCD_WR_DATA(0X32);
    LCD_WR_DATA(0X0A);
    LCD_WR_DATA(0X07);
    LCD_WR_DATA(0X02);
    LCD_WR_DATA(0X07);
    LCD_WR_DATA(0X05);
    LCD_WR_DATA(0X00);

    LCD_WR_REG(0xE1);   /* set Gamma */
    LCD_WR_DATA(0X00);
    LCD_WR_DATA(0X25);
    LCD_WR_DATA(0X27);
    LCD_WR_DATA(0X05);
    LCD_WR_DATA(0X10);
    LCD_WR_DATA(0X09);
    LCD_WR_DATA(0X3A);
    LCD_WR_DATA(0X78);
    LCD_WR_DATA(0X4D);
    LCD_WR_DATA(0X05);
    LCD_WR_DATA(0X18);
    LCD_WR_DATA(0X0D);
    LCD_WR_DATA(0X38);
    LCD_WR_DATA(0X3A);
    LCD_WR_DATA(0X2F);

    LCD_WR_REG(0x29);
}

static uint16_t color_array[] =
{
    WHITE, BLACK, BLUE, BRED,
    GRED, GBLUE, RED, YELLOW
};

void lcd_spi_test(void)
{
	uint8_t index = 0;
	for (index = 0; index < sizeof(color_array) / sizeof(color_array[0]); index++)
	{
			LCD_Clear(color_array[index]);
			DELAY(200);
	}
}

void lcd_draw_point(uint16_t x, uint16_t y, uint32_t color)
{
		LCD_SetCursor(x, y); 
		LCD_WriteRAM_Prepare();
		LCD_WriteData_16Bit(color);
}

void init_lcd(void)
{
    init_lcd_port();

    LCD_RESET();        /* LCD Hardware Reset */
    LCD_WR_REG(0x11);   /* Sleep out */
    DELAY(120);         /* Delay 120ms */
    _ili9341_init();    /* IlI9341 init */
    LCD_BLK_CLR;        /* Open Backlight */
    LCD_direction(USE_DIRECTION);
}

 

2.4、main.c

#include "main.h" 
uint8_t led_sta=0;

int main(void)
{
	uint8_t js=0;
	uint8_t dst=0;
	uint8_t can_txbuf[10];
	uint8_t can_rxbuf[10];
	HAL_Init();  
	SystemClock_Config();    
	usart_init(115200);
	printf("\r\n\r\n====== ACM32G103 MCU is runing ======\r\nSysCoreClk: %dHz, HCLK:%dHz\r\nPCLK1:%dHz, PCLK2:%dHz\r\n\r\n",g_SystemCoreClock, HAL_RCC_GetHCLKFreq(),HAL_RCC_GetPCLK1Freq(),HAL_RCC_GetPCLK2Freq());  
   
	init_led();
	init_tim2();
	init_key();
	//I2C_Init();
	//adc_test();
	//eeprom_test();
	//oled_test();
	
	//init_rtc();
	//init_can();
	//init_spi();
	init_spi_dma();
	
	init_lcd();
	
	//OLED_Init();
	//OLED_Fill(0x00);
	lcd_spi_test();
	g_point_color = RED;
	lcd_show_string(10, 40, 240, 32, 32, "ACM32G103", RED);
	lcd_show_string(10, 80, 240, 24, 24, "LCD TEST", RED);
	lcd_show_string(10, 110, 240, 16, 16, "http://bbs.eeworld.com.cn/", RED);
	while(1)
	{
		HAL_Delay(100);
		led1_tog();
		//printf("http://bbs.eeworld.com.cn/\r\n");
	}
}

 

三、运行结果

 

运行的视频

spi-lcd

字符显示使用描点的方式,写入速度较慢;


 

 

回复评论 (5)

值得学习

点赞  2024-1-20 23:03

 HAL_SPI_Transmit_DMA(&SPI_Handle, pData, Size);
while (HAL_SPI_GetTxState(&SPI_Handle) == SPI_TX_STATE_SENDING);

我启用dma后,他卡在获取状态这里了,大佬可以发你的工程我学习一下吗?

点赞  2024-1-23 14:55
引用: lugl4313820 发表于 2024-1-23 14:55  HAL_SPI_Transmit_DMA(&SPI_Handle, pData, Size); while (HAL_SPI_GetTxState(&SPI_Handle) == ...
acm32g103_prj.7z (1.34 MB)
(下载次数: 7, 2024-1-25 08:05 上传)
点赞  2024-1-25 08:05

非常感谢大佬,我下载下来学习一下,多谢多谢!

点赞  2024-1-25 08:53
引用: lugl4313820 发表于 2024-1-25 08:53 非常感谢大佬,我下载下来学习一下,多谢多谢!

不谢,共同学习!

点赞  2024-1-25 10:32
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复