【AT-START-F425测评】 八、软件I2C驱动OLED屏幕评测
<p>雅特力AT32F425评测有了一段时间了,总体感觉非常不错,接下来评测OLED屏幕了,由于手头的OLED是128*128的,驱动是SSD1327,一直都用的微雪,这次也是一样进行移植。</p><p>SPI方面的评测前面做过了,就用I2C来驱动,为方便移植,首先进行软件模拟I2C的方式进行。</p>
<p>主要的驱动部分代码如下:</p>
<pre>
<code>
/*******************************************************************************
function:
Write register address and data
*******************************************************************************/
void OLED_SendData(uint8_t data)
{
uint8_t i = 0;
OLED_SCL_0;
for(i = 0;i < 8;i++)
{
OLED_SCL_0;
if (data & 0x80)
{
OLED_SDA_1;
}
else
{
OLED_SDA_0;
}
OLED_SCL_1;
data <<= 1;
}
}
void OLED_WriteReg(uint8_t addr)
{
//SCK_0();
//OLED_CS_0;
OLED_DC_0; //当DC = 0时写命令
OLED_SendData(addr);
//OLED_CS_1;
OLED_DC_1;
}
void OLED_WriteData(uint8_t data)
{
//OLED_CS_0;
OLED_DC_1; //当DC = 1时写数据
OLED_SendData(data);
//OLED_CS_1;
OLED_DC_0;
}</code></pre>
<p>其中,对于各引脚的定义如下</p>
<pre>
<code>#define OLED_PORT_CLK CRM_GPIOA_PERIPH_CLOCK
#define OLED_CS_PORT GPIOA
#define OLED_CS_PIN GPIO_PINS_5
#define OLED_RST_PORT GPIOA
#define OLED_RST_PIN GPIO_PINS_3
#define OLED_DC_PORT GPIOA
#define OLED_DC_PIN GPIO_PINS_4
#define I2C1_PORT_CLK CRM_GPIOA_PERIPH_CLOCK
#define I2C1_SCL_Pin GPIO_PINS_1
#define I2C1_SCL_GPIO_Port GPIOA
#define I2C1_SDA_Pin GPIO_PINS_2
#define I2C1_SDA_GPIO_Port GPIOA</code></pre>
<p>OLED屏幕是7针引脚,电源除外,还有SCL、SDA、RST、DC#、RS#。</p>
<p>main函数比较简单</p>
<pre>
<code>int main(void)
{
/* initial system clock */
system_clock_config();
/* config nvic priority group */
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
/* at board initial */
at32_board_init();
uart_print_init(115200);
//hi2cx.i2cx = I2Cx_PORT;
gpio_config();
/* i2c config */
//i2c_config(&hi2cx);
OLED_1in5_test();
while(1)
{
}
}</code></pre>
<p>主要的测试函数是OLED_1in5_test()</p>
<p>有5个测试页面</p>
<pre>
<code>printf("Drawing:page 1\r\n");
Paint_DrawPoint(20, 10, WHITE, DOT_PIXEL_1X1, DOT_STYLE_DFT);
Paint_DrawPoint(30, 10, WHITE, DOT_PIXEL_2X2, DOT_STYLE_DFT);
Paint_DrawPoint(40, 10, WHITE, DOT_PIXEL_3X3, DOT_STYLE_DFT);
Paint_DrawLine(10, 10, 10, 20, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
Paint_DrawLine(20, 20, 20, 30, WHITE, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
Paint_DrawLine(30, 30, 30, 40, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
Paint_DrawLine(40, 40, 40, 50, WHITE, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
Paint_DrawCircle(60, 30, 15, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
Paint_DrawCircle(100, 40, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
Paint_DrawRectangle(50, 30, 60, 40, WHITE, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
Paint_DrawRectangle(90, 30, 110, 50, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
// 3.Show image on page1
OLED_1in5_Display(BlackImage);
Driver_Delay_ms(1000);
Paint_Clear(BLACK);
// Drawing on the image
printf("Drawing:page 2\r\n");
for(UBYTE i=0; i<16; i++){
Paint_DrawRectangle(0, 8*i, 127, 8*(i+1), i, DOT_PIXEL_1X1, DRAW_FILL_FULL);
}
// Show image on page2
OLED_1in5_Display(BlackImage);
Driver_Delay_ms(1000);
Paint_Clear(BLACK);
// Drawing on the image
printf("Drawing:page 3\r\n");
Paint_DrawString_EN(10, 0, "AT32F425", &Font16, 0x1, 0xb);
Paint_DrawString_EN(10, 20, "hello EEWorld", &Font12, 0x2, 0xc);
Paint_DrawNum(10, 40, 123.456789, &Font8, 4, 0x3, 0xd);
Paint_DrawNum(10, 58, 987654, &Font12, 5, 0x4, 0xe);
Paint_DrawString_EN(10, 80, "By Kit7828", &Font12, 0x1, 0xb);
// Show image on page2
OLED_1in5_Display(BlackImage);
Driver_Delay_ms(1000);
Paint_Clear(BLACK);
// Drawing on the image
printf("Drawing:page 4\r\n");
Paint_DrawString_CN(10, 0,"你好Abc", &Font12CN, WHITE, WHITE);
Paint_DrawString_CN(0, 20, "微软雅黑", &Font24CN, WHITE, WHITE);
// Show image on page3
OLED_1in5_Display(BlackImage);
Driver_Delay_ms(1000);
Paint_Clear(BLACK);
// show the array image
printf("Drawing:page 5\r\n");
OLED_1in5_Display(gImage_1in5);
Driver_Delay_ms(1000);
Paint_Clear(BLACK); </code></pre>
<p>整体来说,比较顺利,唯一有点阻碍的是没想过F425的空间,在编译的时候遇到空间不够的情况,</p>
<p>Error: L6406E: No space in execution regions with .ANY selector matching use_no_semi.o(.text).</p>
<p>默认的0级优化下会出现空间不足</p>
<p> 后面调整成默认的就可以通过了,不知道哪位网友能不能解解惑?</p>
<p>具体的连线</p>
<p> </p>
<p>运行后的视频如下</p>
<p>b268901b3ee5085fd33b874967ca42f0<br />
工程文件<br />
</p>
666,其实还想玩一下墨水屏,不知道效果如何。 <p>这种情况下F425的空间,在编译的时候遇到空间不够回出现什么状况</p>
lugl4313820 发表于 2022-5-27 07:48
666,其实还想玩一下墨水屏,不知道效果如何。
<p>手头有1.54的屏,但是驱动板还没做好</p>
Jacktang 发表于 2022-5-27 07:48
这种情况下F425的空间,在编译的时候遇到空间不够回出现什么状况
<p>会提示错误 Error: L6406E: No space in execution regions with .ANY selector matching use_no_semi.o(.text).</p>
<p>没法编译生成hex文件</p>
<p>解决的办法是更改优化等级,Optimization至1级或者2级</p>
页:
[1]