lugl4313820 发表于 2022-2-13 15:58

【国民技术N32G457评测】SPI_ST7735 基于RT—Thread Studio

<p>今天买的LCD屏到货了,芯片是ST7735。9.9元买的。。</p>

<p>前面SPI驱动花了好多时间,今天在前面的基础上驱动SPI显示屏,同时也是巩固rt-thread studio的spi使用熟练度。</p>

<p>1、由于没有st7735的库,买的屏的例程是Luaos驱动,所以花了一点时间去网上找驱动。这里要感谢Hei51的这位网友提供的驱动。STM32- ST7735 1.8寸TFT-LCD程序 - STM32/8</p>

<p>2、这个驱动是基于stm32f103C8的,我下载下来接上线,屏点亮成功,说明屏是好的。</p>

<p>3、例程所写的这模拟spi驱动的,我看了一下,只需要配置把接口全部配置为输出就OK了。</p>

<pre>
<code>//功能描述   :N32G45 st7735
//            说明:
//            ----------------------------------------------------------------
//            GND   电源地
//            VCC   3.3v电源
//            SCL   PA5(SCLK)
//            SDA   PA7(MOSI)
//            RES   PC4   33
//            DC    PC5   34
//            CS    PA4
//            BLK   PB0   35
//            ----------------------------------------------------------------

#define RES_PIN33//PC4   
#define DC_PIN   34//PC5   
#define BLK_PIN35//PB0   
#define SCK_PIN30//PA5
#define MOSI_PIN 32//PA7
#define CS_PIN   29//PA4

rt_pin_mode(RES_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(DC_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(BLK_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(SCK_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(MOSI_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(CS_PIN, PIN_MODE_OUTPUT);</code></pre>

<p>然后更新宏定义:</p>

<pre>
<code>#define LCD_SCLK_Clr() rt_pin_write(SCK_PIN, PIN_LOW)//SCL=SCLK
#define LCD_SCLK_Set() rt_pin_write(SCK_PIN, PIN_HIGH)

#define LCD_MOSI_Clr() rt_pin_write(MOSI_PIN, PIN_LOW)//SDA=MOSI
#define LCD_MOSI_Set() rt_pin_write(MOSI_PIN, PIN_HIGH)

#define LCD_CS_Clr()   rt_pin_write(CS_PIN, PIN_LOW)//CS
#define LCD_CS_Set()   rt_pin_write(CS_PIN, PIN_HIGH)

#define LCD_RES_Clr()rt_pin_write(RES_PIN, PIN_LOW)//RES
#define LCD_RES_Set()rt_pin_write(RES_PIN, PIN_HIGH)

#define LCD_DC_Clr()   rt_pin_write(DC_PIN, PIN_LOW)//DC
#define LCD_DC_Set()   rt_pin_write(DC_PIN, PIN_HIGH)

#define LCD_BLK_Clr()rt_pin_write(BLK_PIN, PIN_LOW)//BLK
#define LCD_BLK_Set()rt_pin_write(BLK_PIN, PIN_HIGH)</code></pre>

<p>同时把u6、u16、u32等替换成uint8_t,uint16_t,uint32_t。更新man.c,下载就成功点亮。一切还算顺利。</p>

<pre>
<code>#include &lt;stdint.h&gt;
#include &lt;rtthread.h&gt;
#include &lt;rtdevice.h&gt;
#include "lcd_init.h"
#include "lcd.h"
#include "pic.h"

/* defined the LED1 pin: PB5 */
#define LED1_PIN    91


int main(void)
{
    uint32_t Speed = 200;
    float t=0;
    /* set LED1 pin mode to output */
    rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
    LCD_Init();//LCD初始化
    LCD_Fill(0,0,LCD_W,LCD_H,WHITE);
    LCD_ShowString(0,0,"RTTDEMO",BLUE,WHITE,32,0);
    LCD_ShowString(24,36,"N32G45XVL",RED,WHITE,16,0);
    LCD_ShowString(24,60,"LCD-W:", BROWN ,WHITE,16,0);
    LCD_ShowIntNum(72,60,LCD_W,3, BROWN ,WHITE,16);
    LCD_ShowString(24,80,"LCD_H:",RED,WHITE,16,0);
    LCD_ShowIntNum(72,80,LCD_H,3,RED,WHITE,16);
    LCD_ShowPicture(65,110,40,40,gImage_1);
    while (1)
    {
      LCD_ShowFloatNum1(20,110,t,4,BLACK,WHITE,16);
      t+=0.11;
      rt_pin_write(LED1_PIN, PIN_LOW);
      rt_thread_mdelay(Speed);
      rt_pin_write(LED1_PIN, PIN_HIGH);
      rt_thread_mdelay(Speed);
    }
}</code></pre>

<p>模拟spi是速度好象不是很快,刷新的速度好慢。下面准备更新为硬件spi。</p>

<p>我看了一下spi输出函数,主要就是把void LCD_Writ_Bus(uint8_t dat) 更改为spi的rt_spi_send函数就行了。</p>

<p>于是在lcdinit.c下面增加spi初始化函数:int rt_hw_spi_config(void)</p>

<pre>
<code>struct n32_hw_spi_cs
{
    GPIO_Module* GPIOx;
    uint32_t GPIO_Pin;
};

struct rt_spi_device *st7753_spi_dev;

int rt_hw_spi_config(void)
{
    static struct n32_hw_spi_csspi_cs1;
    static struct rt_spi_device spi_dev_1 ;
    rt_err_t res;
    spi_cs1.GPIO_Pin = GPIO_PIN_4;
    spi_cs1.GPIOx = GPIOA;
    rt_pin_mode(CS_PIN, PIN_MODE_OUTPUT);
    res = rt_spi_bus_attach_device(&amp;spi_dev_1, SPI1__DEVICE_NAME, SPI1_BUS_NAME, (void*)&amp;spi_cs1);
    if (res != RT_EOK)
    {
      rt_kprintf("rt_spi_bus_attach_device!\r\n");
      return res;
    }
    spi_dev_1.bus-&gt;owner = &amp;spi_dev_1;
    {
      struct rt_spi_configuration cfg;
      cfg.data_width = 8;
      cfg.mode =   RT_SPI_MODE_3 | RT_SPI_MSB ;
      cfg.max_hz = 40*1000 *1000; /* 40M,SPI max 42MHz, 3-wire spi */
      if(spi_dev_1.bus-&gt;owner==RT_NULL)
      {
            rt_kprintf("RT_OK\r\n");
      }
      rt_kprintf("owner= %d\r\n",*spi_dev_1.bus-&gt;owner);
      res = rt_spi_configure(&amp;spi_dev_1, &amp;(cfg));
      if(res != RT_EOK)
      {
            rt_kprintf("configure spi1 ERR!\r\n");
      }

    }
    st7753_spi_dev = (struct rt_spi_device *)rt_device_find(SPI1__DEVICE_NAME);
      if(!&amp;st7753_spi_dev)
      {
            rt_kprintf("spi1 test run failed! can't find %s device!\n", SPI1__DEVICE_NAME);
      }
    return RT_EOK;
}

INIT_DEVICE_EXPORT(rt_hw_spi_config);</code></pre>

<p>这里需要注意的是st7735的模式要配置成RT_SPI_MODE_3&nbsp; /* CPOL = 1, CPHA = 1 */ 。我前面配置为1-2时,数据是有输出但是屏死活不亮,后面找了数据手册才知道要配置成这个模式才能点亮。</p>

<p><iframe allowfullscreen="true" frameborder="0" height="510" src="https://training.eeworld.com.cn/shareOpenCourseAPI?isauto=true&amp;lessonid=32515" style="background:#eee;margin-bottom:10px;" width="700"></iframe><br />
&nbsp;</p>

fly007008009 发表于 2022-3-7 19:06

<p>请问,为什么在rt-thread中就只显示个白屏;(模拟io)</p>

<p>一样代码在keil5中,可以正常显示呢;</p>

fly007008009 发表于 2022-3-7 19:07

<p>能够共享一下,参考参考呢,非常感谢<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/handshake.gif" width="48" /></p>

lugl4313820 发表于 2022-3-7 19:46

fly007008009 发表于 2022-3-7 19:07
能够共享一下,参考参考呢,非常感谢

<p>可以的呀,你加我好友,或者提供邮箱都可以。</p>

fly007008009 发表于 2022-3-8 12:38

本帖最后由 fly007008009 于 2022-3-8 23:26 编辑

<div class="quote">
<blockquote><font size="2"><a href="forum.php?mod=redirect&amp;goto=findpost&amp;pid=3126069&amp;ptid=1193797" target="_blank"><font color="#999999">lugl4313820 发表于 2022-3-7 19:46</font></a></font> 可以的呀,你加我好友,或者提供邮箱都可以。</blockquote>
</div>

<p>发送这个邮箱吧 flyhawk007gm@gmail.com;<br />
多谢了</p>

<p><br />
&nbsp;</p>

freebsder 发表于 2022-3-8 23:14

<p>spi屏的初始化看着就特别骚</p>

fly007008009 发表于 2022-3-8 23:31

freebsder 发表于 2022-3-8 23:14
spi屏的初始化看着就特别骚

<p>还行吧; 感觉都一个流程哈哈(俺是菜鸟,正在学习中)<br />
cs片选拉低电平,上升沿发送8位数据,发送完成cs拉高;</p>

<p>&nbsp;</p>

<p>现在遇到的就是keil使用使用完全正常,放到rt-thread死活不刷新就是个白屏;<br />
非常奇怪,这位仁兄有没有遇到呢,如果可以的话,请多指教指教</p>

<p>&nbsp;</p>

fly007008009 发表于 2022-3-9 00:13

lugl4313820 发表于 2022-3-7 19:46
可以的呀,你加我好友,或者提供邮箱都可以。

<p>附件这个是我依据 提供的工程移植到rt-thread,但奈何只是白屏;<br />
不显示数据,能劳烦瞅瞅不,实在搞不懂了</p>

<p>&nbsp;</p>

lugl4313820 发表于 2022-3-9 07:08

fly007008009 发表于 2022-3-9 00:13
附件这个是我依据 提供的工程移植到rt-thread,但奈何只是白屏;
不显示数据,能劳烦瞅瞅不,实在搞不懂 ...

<p>好的,有空给你看看,就是有点折腾,最近评测好几片版子。最好是远程给你看。难拆装杜绑线呀。</p>

lugl4313820 发表于 2022-3-9 07:10

fly007008009 发表于 2022-3-7 19:06
请问,为什么在rt-thread中就只显示个白屏;(模拟io)

一样代码在keil5中,可以正常显示呢;

<p>我的是RT_Thread Studio,应该跟你差不多的,白屏的话是没有驱动起来,先看看线接对了没有,还有就是如果手头上有逻辑分析仪,看看时序、数据对不对。</p>

fly007008009 发表于 2022-3-9 10:04

<div class="quote">
<blockquote><font size="2"><a href="forum.php?mod=redirect&amp;goto=findpost&amp;pid=3126397&amp;ptid=1193797" target="_blank"><font color="#999999">lugl4313820 发表于 2022-3-9 07:10</font></a></font> 我的是RT_Thread Studio,应该跟你差不多的,白屏的话是没有驱动起来,先看看线接对了没有,还有就是如果 ...</blockquote>
</div>

<p>数据线应该没有问题;<br />
一样的插线使用这个【STM32- ST7735 1.8寸TFT-LCD程序 - STM32/8 】就可以正确驱动起来;</p>

fly007008009 发表于 2022-3-9 10:06

lugl4313820 发表于 2022-3-9 07:10
我的是RT_Thread Studio,应该跟你差不多的,白屏的话是没有驱动起来,先看看线接对了没有,还有就是如果 ...

<p>手头没有专业设备&#128514;</p>

fly007008009 发表于 2022-3-9 10:09

<div class="quote">
<blockquote><font size="2"><a href="forum.php?mod=redirect&amp;goto=findpost&amp;pid=3126397&amp;ptid=1193797" target="_blank"><font color="#999999">lugl4313820 发表于 2022-3-9 07:10</font></a></font> 我的是RT_Thread Studio,应该跟你差不多的,白屏的话是没有驱动起来,先看看线接对了没有,还有就是如果 ...</blockquote>
</div>

<p>参考代码能共享一下不【邮箱: flyhawk007gm@gmail.com;】,使用beyond compare比较下哪部分不一样导致出错了;<br />
lcd驱动部分都是参考【STM32- ST7735 1.8寸TFT-LCD程序 - STM32/8 】的;<br />
为啥不行呢,比较奇怪</p>

lugl4313820 发表于 2022-3-9 21:16

fly007008009 发表于 2022-3-9 10:09
lugl4313820 发表于 2022-3-9 07:10 我的是RT_Thread Studio,应该跟你差不多的,白屏的话是没有驱动起来 ...

<p>你有没有分析一下你的时序呀?一定要有时序才行的。</p>

lugl4313820 发表于 2022-3-9 21:19

fly007008009 发表于 2022-3-9 10:09
lugl4313820 发表于 2022-3-9 07:10 我的是RT_Thread Studio,应该跟你差不多的,白屏的话是没有驱动起来 ...

<p>已经发你QQ了,最好还是自己用逻辑分析,看时序,自己找到原因,这样成长比较快。</p>

lugl4313820 发表于 2022-3-9 21:22

fly007008009 发表于 2022-3-9 10:06
手头没有专业设备&#128514;

<p>你给的邮箱是错的flyhawk007gm@gmail.com,被退回来了。。。。</p>

fly007008009 发表于 2022-3-9 21:26

lugl4313820 发表于 2022-3-9 21:22
你给的邮箱是错的flyhawk007gm@gmail.com,被退回来了。。。。

<p>多谢多谢,发送 flyhawk007hm@hotmail.com 用微软的邮箱吧<br />
没有使用QQ邮箱,以前单独设置密码后来就进不去了。。。</p>

fly007008009 发表于 2022-3-9 21:27

lugl4313820 发表于 2022-3-9 21:19
已经发你QQ了,最好还是自己用逻辑分析,看时序,自己找到原因,这样成长比较快。

<p>嗯嗯,您说的对,过段时间弄个逻辑分析仪,研究研究;</p>

fly007008009 发表于 2022-3-17 22:25

fly007008009 发表于 2022-3-9 10:09
lugl4313820 发表于 2022-3-9 07:10 我的是RT_Thread Studio,应该跟你差不多的,白屏的话是没有驱动起来 ...

<p>&nbsp;已经自己搞定;<br />
此人不可信,言而无信;不想发就直接说&nbsp; 【不想发送】<br />
我都没有QQ邮箱,哪里发送我邮箱了!!!<br />
谷歌邮箱不行,hotmail邮箱难道也被墙了,请一开始说【不想给大家共享】<br />
&nbsp;</p>

lugl4313820 发表于 2022-3-18 11:34

本帖最后由 lugl4313820 于 2022-3-18 11:35 编辑

<div class="quote">
<blockquote><font size="2"><a href="forum.php?mod=redirect&amp;goto=findpost&amp;pid=3128593&amp;ptid=1193797" target="_blank"><font color="#999999">fly007008009 发表于 2022-3-17 22:25</font></a></font> &nbsp;已经自己搞定; 此人不可信,言而无信;不想发就直接说&nbsp; 【不想发送】 我都没有QQ邮箱,哪 ...</blockquote>
</div>

<p>&nbsp;给你发了邮箱被退回来,后面工作忙没有发给你,同时我也给你留言,让你加我好友。朋友,你到处攻击我,本来不想回答。管理员在@我,到这里跟你说一声,大家在网站上交流学习,帮与不帮,也要看看什么情况。还有,最好不要来个道德绑架。我年纪大了,什么事都遇到过,不与你计较,也希望你好自为之。最后,提升一下自己的人品,才有资格去评论别人的人品。</p>
页: [1] 2
查看完整版本: 【国民技术N32G457评测】SPI_ST7735 基于RT—Thread Studio