【国民技术N32WB031_STB开发板评测】SPI驱动墨水屏
<ol><li><a href="https://bbs.eeworld.com.cn/thread-1241062-1-1.html">【新提醒】N32WB03x系列蓝牙芯片 产品简介 </a></li>
<li><a href="https://bbs.eeworld.com.cn/thread-1241020-1-1.html">【新提醒】N32WB031 API函数使用说明 </a></li>
<li><a href="https://bbs.eeworld.com.cn/thread-1241013-1-1.html">【新提醒】【国民技术N32WB031_STB开发板评测】资源的下载 </a></li>
<li><a href="https://bbs.eeworld.com.cn/thread-1241678-1-1.html">【国民技术N32WB031_STB开发板评测】创建MDK模版 </a></li>
<li><a href="https://bbs.eeworld.com.cn/thread-1241679-1-1.html">【国民技术N32WB031_STB开发板评测】GPIO之按键与LED灯 </a></li>
<li><a href="https://bbs.eeworld.com.cn/thread-1241731-1-1.html">【新提醒】【国民技术N32WB031_STB开发板评测】串口+LOG分级打印</a></li>
<li><a href="https://bbs.eeworld.com.cn/thread-1241815-1-1.html">【国民技术N32WB031_STB开发板评测】OLED驱动 </a></li>
</ol>
<p>这款芯片主打蓝牙低功耗,而墨水屏也是以低功耗而生。结合起来,那肯定是完美:</p>
<p>【实现步骤】</p>
<ol>
<li>拷贝模版工程,添加bsp/lcd工程:</li>
</ol>
<p><span id="cke_bm_5099C" style="display: none;"> </span></p>
<p> </p>
<p><span id="cke_bm_5325C" style="display: none;"> </span> 2. 添加spi端口定义:</p>
<pre>
<code>/* *** 墨水屏IO定义 *****************
* MOSI PA2
* SCK PA1
* CS PA3
* DC PA4
* RST PA5
* BUSY PA6
********** 定义结束 ***********************/
#define EP_MOSI_GPIO_Port GPIOA
#define EP_SCK_GPIO_Port GPIOA
#define EPD_W21_CS_Port GPIOA
#define EPD_W21_DC_Port GPIOA
#define EPD_W21_RST_Port GPIOA
#define EP_BUSY_GPIO_Port GPIOA
#define EP_MOSI_Pin GPIO_PIN_2
#define EP_SCK_Pin GPIO_PIN_1
#define EP_CS_Pin GPIO_PIN_3
#define EP_DC_Pin GPIO_PIN_4
#define EP_REST_Pin GPIO_PIN_5
#define EP_BUSY_Pin GPIO_PIN_6
#define EPD_W21_MOSI_0 EP_MOSI_GPIO_Port->PBC = (uint32_t)EP_MOSI_Pin
#define EPD_W21_MOSI_1 EP_MOSI_GPIO_Port->PBSC = (uint32_t)EP_MOSI_Pin
#define EPD_W21_CLK_0 EP_SCK_GPIO_Port->PBC = (uint32_t)EP_SCK_Pin
#define EPD_W21_CLK_1 EP_SCK_GPIO_Port->PBSC = (uint32_t)EP_SCK_Pin
#define EPD_W21_CS_0 EPD_W21_CS_Port->PBC = (uint32_t)EP_CS_Pin
#define EPD_W21_CS_1 EPD_W21_CS_Port->PBSC = (uint32_t)EP_CS_Pin
#define EPD_W21_DC_0 EPD_W21_DC_Port->PBC = (uint32_t)EP_DC_Pin
#define EPD_W21_DC_1 EPD_W21_DC_Port->PBSC = (uint32_t)EP_DC_Pin
#define EPD_W21_RST_0 EPD_W21_RST_Port->PBC = (uint32_t)EP_REST_Pin
#define EPD_W21_RST_1 EPD_W21_RST_Port->PBSC = (uint32_t)EP_REST_Pin
#define isEPD_W21_BUSY GPIO_ReadInputDataBit(EP_BUSY_GPIO_Port, EP_BUSY_Pin) // for solomen solutions</code></pre>
<p> 3、声明spi IO驱动初始化</p>
<pre>
<code>void EPD_GPIO_Init(void)
{
GPIO_InitType GPIO_InitStructure;
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
/* Configure the GPIO pin */
GPIO_InitStruct(&GPIO_InitStructure);
GPIO_InitStructure.Pin = EP_MOSI_Pin | EP_SCK_Pin | EP_CS_Pin | EP_DC_Pin | EP_REST_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitPeripheral(EP_MOSI_GPIO_Port, &GPIO_InitStructure);
GPIO_InitStructure.Pin = EP_BUSY_Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
GPIO_InitPeripheral(EP_BUSY_GPIO_Port, &GPIO_InitStructure);
}</code></pre>
<p>4、写代码:</p>
<p> </p>
<pre>
<code>void SPI_Write(unsigned char value)
{
unsigned char i;
for(i=0; i<8; i++)
{
EPD_W21_CLK_0;
if(value & 0x80)
EPD_W21_MOSI_1;
else
EPD_W21_MOSI_0;
value = (value << 1);
EPD_W21_CLK_1;
}
}
void EPD_W21_WriteCMD(unsigned char command)
{
EPD_W21_CS_0;
EPD_W21_DC_0; // command write
SPI_Write(command);
EPD_W21_CS_1;
}
void EPD_W21_WriteDATA(unsigned char data)
{
EPD_W21_CS_0;
EPD_W21_DC_1; // data write
SPI_Write(data);
EPD_W21_CS_1;
}
</code></pre>
<p>其余main.c:</p>
<p> </p>
<pre>
<code>#include "fonts.h"
#include "GUI_Paint.h"
#include "Ap_29demo.h"
#include "Display_EPD_w21.h"
unsigned char BlackImage;//Define canvas space
int main(void)
{
unsigned char fen_L,fen_H,miao_L,miao_H;
log_init();
LedInit(LED1_PORT, LED1_PIN);
LedInit(LED2_PORT, LED2_PIN);
LedOn(LED1_PORT, LED1_PIN);
LedOn(LED2_PORT, LED2_PIN);
KeyInputExtiInit(KEY_INPUT_PORT, KEY_INPUT_PIN);
EPD_GPIO_Init(); //EPD GPIOinitialization
Paint_NewImage(BlackImage, 128, 296, 270, WHITE); //Set screen size and display orientation
Paint_SelectImage(BlackImage);//Set the virtual canvas data storage location
while (1)
{
log_debug("debug\r\n");
LedBlink(LED1_PORT, LED1_PIN);
Delay(0x28FFFF);
log_info("LED FLASH\r\n");
//////////////////////Partial refresh time demo/////////////////////////////////////
EPD_HW_Init(); //Electronic paper initialization
EPD_SetRAMValue_BaseMap(gImage_basemap); //Partial refresh background color
for(fen_H=0;fen_H<6;fen_H++)
{
for(fen_L=0;fen_L<10;fen_L++)
{
for(miao_H=0;miao_H<6;miao_H++)
{
for(miao_L=0;miao_L<10;miao_L++)
{
EPD_Dis_Part_myself(48,90,(unsigned char *)&Num, //x-A,y-A,DATA-A
48,122,(unsigned char *)&Num, //x-B,y-B,DATA-B
48,162,(unsigned char *)gImage_numdot, //x-C,y-C,DATA-C
48,204,(unsigned char *)&Num, //x-D,y-D,DATA-D
48,236,(unsigned char *)&Num,32,64); //x-E,y-E,DATA-E,Resolution 32*64
if((fen_L==5)&&(miao_H==0)&&(miao_L==9))
goto Clear;
}
}
}
}
//Clear screen
Clear:
EPD_HW_Init(); //Electronic paper initialization
EPD_WhiteScreen_White(); //Show all white
EPD_DeepSleep(); //Enter deep sleep,Sleep instruction is necessary, please do not delete!!!
}
}</code></pre>
<p> 【效果】见视频:6d564ccd89658321fb05fe50a3fc19a3</p>
<p> </p>
<p> </p>
<div aria-label="代码段 小部件" contenteditable="false" role="region" tabindex="-1"><span id="cke_bm_4912C" style="display: none;"> </span><img src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==" /></div>
<p> </p>
<p>看起来电子墨水屏刷新速度不会太慢</p><br/> xutong 发表于 2023-4-30 08:23
看起来电子墨水屏刷新速度不会太慢
<p>还好吧,还是没有掌握好。</p>
<p>五一大家都没有出去啊 </p>
秦天qintian0303 发表于 2023-5-1 17:03
五一大家都没有出去啊
<p>在家里写报告,今天完成三篇。开心开心呀!</p>
lugl4313820 发表于 2023-5-1 18:12
在家里写报告,今天完成三篇。开心开心呀!
<p>优秀,我在家只能每天玩游戏,出去都是人 </p>
页:
[1]