这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 活动中心 » 板卡试用 » 【EV76S68A试用】移植ST7735驱动

共1条 1/1 1 跳转至

【EV76S68A试用】移植ST7735驱动

工程师
2025-07-18 12:37:44     打赏

【前言】

我的测评计划是移植LVGL,那莫驱动LCD屏是首要的任务,这一篇将从如何配置SPI,以及对ST7735的数据、复位引脚的适配。

【MCC配置SPI】

1、根据开发板原理图,这次使用的SPI为SERCOM1为驱动ST7735的端口。

image.png

与ST7735的IO连接为:

PA16------SDA

PA17------SCK

PA18------CS

PA8-------RST

PA9--------DC

BL我这里直接接VCC

2、进入MCC添加SERCOM1到工程中:

image.png

配置中主要是配置为SPI Master模式,以及时钟相位,发送数据带宽等。

3、进行pinset,配置DC、RST如下:

image.png

配置spi如下:

image.png

配置好,生成工程。

【st7735代码移植】

1、添加st7735的驱动到工程中

image.png

2、修改数据发送命令如下:

void ST7735_Reset(void)
{
  RST_Clear();
  SYSTICK_DelayMs(100);
  RST_Set() ;
  SYSTICK_DelayMs(100);
}

void ST7735_WriteCommand(uint8_t cmd)
{
  uint8_t txBuffer[1];
  size_t txSize = 1;
  DC_Clear();
  txBuffer[0] = cmd;
 if(SERCOM1_SPI_Write(&txBuffer, txSize))
    {
     printf("Write falied\r\n");
    }
   while( SERCOM1_SPI_IsBusy());
}

void ST7735_WriteByte(uint8_t data)
{
  uint8_t txBuffer[1];
  size_t txSize = 1;
  DC_Set();
  txBuffer[0] = data;
 if(SERCOM1_SPI_Write(&txBuffer, txSize))
    {
     printf("Write falied\r\n");
    }
  while( SERCOM1_SPI_IsBusy());
}

void ST7735_WriteData(uint8_t *data, size_t data_size)
{

  DC_Set();
if(SERCOM1_SPI_Write(&data[0], data_size))
    {
     printf("Write falied\r\n");
    }
   while( SERCOM1_SPI_IsBusy());
}

3、修改初始化代码如下:

void ST7735_Init(void) {
    
  SERCOM1_SPI_Initialize();  
  setup_st7735.clockFrequency = 6000000;
  setup_st7735.clockPhase = SPI_CLOCK_PHASE_LEADING_EDGE;
  setup_st7735.clockPolarity = SPI_CLOCK_POLARITY_IDLE_LOW;
  setup_st7735.dataBits = SPI_DATA_BITS_8;

    if (SERCOM1_SPI_TransferSetup (&setup_st7735, 60000000) == false)
    {
        printf("setup st7735 failed");
        return;
    }
  // Initialize the display
  ST7735_Reset();
  ST7735_WriteCommand(ST7735_SLPOUT);
  SYSTICK_DelayMs(120);
  ST7735_WriteCommand(ST7735_FRMCTR1);
  ST7735_WriteByte(0x01);
  ST7735_WriteByte(0x2C);
  ST7735_WriteByte(0x2D);
  ST7735_WriteCommand(ST7735_FRMCTR2);
  ST7735_WriteByte(0x01);
  ST7735_WriteByte(0x2C);
  ST7735_WriteByte(0x2D);
  ST7735_WriteCommand(ST7735_FRMCTR3);
  ST7735_WriteByte(0x01);
  ST7735_WriteByte(0x2C);
  ST7735_WriteByte(0x2D);
  ST7735_WriteByte(0x01);
  ST7735_WriteByte(0x2C);
  ST7735_WriteByte(0x2D);
  ST7735_WriteCommand(ST7735_INVCTR);
  ST7735_WriteByte(0x07);
  ST7735_WriteCommand(ST7735_PWCTR1);
  ST7735_WriteByte(0xA2);
  ST7735_WriteByte(0x02);
  ST7735_WriteByte(0x84);
  ST7735_WriteCommand(ST7735_PWCTR2);
  ST7735_WriteByte(0xC5);
  ST7735_WriteCommand(ST7735_PWCTR3);
  ST7735_WriteByte(0x0A);
  ST7735_WriteByte(0x00);
  ST7735_WriteCommand(ST7735_PWCTR4);
  ST7735_WriteByte(0x8A);
  ST7735_WriteByte(0x2A);
  ST7735_WriteCommand(ST7735_PWCTR5);
  ST7735_WriteByte(0x8A);
  ST7735_WriteByte(0xEE);
  ST7735_WriteCommand(ST7735_VMCTR1);
  ST7735_WriteByte(0x0E);
  ST7735_WriteCommand(ST7735_INVERSE ? ST7735_INVON : ST7735_INVOFF);
  ST7735_WriteCommand(ST7735_COLMOD);
  ST7735_WriteByte(0x05);
  ST7735_WriteCommand(ST7735_CASET);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x7F);
  ST7735_WriteCommand(ST7735_RASET);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x9F);
  ST7735_WriteCommand(ST7735_GMCTRP1);
  ST7735_WriteByte(0x02);
  ST7735_WriteByte(0x1C);
  ST7735_WriteByte(0x07);
  ST7735_WriteByte(0x12);
  ST7735_WriteByte(0x37);
  ST7735_WriteByte(0x32);
  ST7735_WriteByte(0x29);
  ST7735_WriteByte(0x2D);
  ST7735_WriteByte(0x29);
  ST7735_WriteByte(0x25);
  ST7735_WriteByte(0x2B);
  ST7735_WriteByte(0x39);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x01);
  ST7735_WriteByte(0x03);
  ST7735_WriteByte(0x10);
  ST7735_WriteCommand(ST7735_GMCTRN1);
  ST7735_WriteByte(0x03);
  ST7735_WriteByte(0x1D);
  ST7735_WriteByte(0x07);
  ST7735_WriteByte(0x06);
  ST7735_WriteByte(0x2E);
  ST7735_WriteByte(0x2C);
  ST7735_WriteByte(0x29);
  ST7735_WriteByte(0x2D);
  ST7735_WriteByte(0x2E);
  ST7735_WriteByte(0x2E);
  ST7735_WriteByte(0x37);
  ST7735_WriteByte(0x3F);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x00);
  ST7735_WriteByte(0x02);
  ST7735_WriteByte(0x10);
  ST7735_WriteCommand(ST7735_NORON);
  SYSTICK_DelayMs(10);
  ST7735_WriteCommand(ST7735_DISPON);
  SYSTICK_DelayMs(10);

  ST7735_SetRotation(ST7735_ROTATION);
  ST7735_FillScreen(ST7735_BLACK);
}

到此代码移植完毕

【测试】

在main.c中,我们初始化st7735然后输入字符串到LCD屏中。

    ST7735_Init();
    ST7735_DrawString(0, 0, (const char *)("hello world"), ST7735_YELLOW, ST7735_BLACK, &Font_11x18);
    ST7735_DrawString(20,40, (const char *)("SAME51"), ST7735_YELLOW, ST7735_BLACK, &Font_11x18);
    ST7735_DrawString(20,80, (const char *)("eepw.com"), ST7735_BLUE, ST7735_BLACK, &Font_11x18);

下载到开发板看,效果如下:

image.png




关键词: EV76S68A     工程创建     MCC     SPI     ST7    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]