stm32F103VB使用uGfx驱动sh1106

IAR7.4+STM32CUBEMX调试通过。

显示部分,作为麦知智能小车的一部分。显示屏是OLED 1.3寸,控制器是sh1106,但像素是128*64,价格达到惊人的45元/片。


只提供代码,而不同时说明硬件电路图,是导致情景不能复现的主要原因。


这个是委托方提供的原理图和硬件,他每条线都有上拉电阻,显然是打算用模拟SPI。


我在代码里,将cs,dc,res配置为开漏输出,或者推挽输出,都可以正常显示图像。

不知道cs,dc,res在推挽模式下,会不会有问题,所以使用cube配置为OD,低速,而SCLK,SDA默认为PP(配置SPI的默认设置)


与ugfx接口的底层驱动:

</pre><p><pre name="code" class="cpp">/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 * file: board_SSD1306.h
 * author: yu
 * date: 2015.12.14
 * site: www.mazclub.com
*/

/**
 * @file    boards/addons/gdisp/board_SSD1306_spi.h
 * @brief   GDISP Graphic Driver subsystem board interface for the SSD1306 display.
 *
 * @note	This file contains a mix of hardware specific and operating system specific
 *			code. You will need to change it for your CPU and/or operating system.
 */

#ifndef _GDISP_LLD_BOARD_H
#define _GDISP_LLD_BOARD_H
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"
// The command byte to put on the front of each page line
//#define SSD1306_PAGE_PREFIX		0x40			 		// Co = 0, D/C = 1

// For a multiple display configuration we would put all this in a structure and then
//	set g->board to that structure.

#define OLED_DC_Port  (GPIOC)
#define OLED_DC_Pin  (GPIO_PIN_15)
#define OLED_CS_Port  (GPIOA)
#define OLED_CS_Pin  (GPIO_PIN_8)
#define OLED_RES_Port  (GPIOC)
#define OLED_RES_Pin  (GPIO_PIN_14)

#define OLED_RES(a) if (a) \
                      HAL_GPIO_WritePin(OLED_RES_Port,OLED_RES_Pin, GPIO_PIN_SET);\
                      else \
                      HAL_GPIO_WritePin(OLED_RES_Port,OLED_RES_Pin, GPIO_PIN_RESET)

#define OLED_DC(a) if (a) \
                      HAL_GPIO_WritePin(OLED_DC_Port,OLED_DC_Pin, GPIO_PIN_SET);\
                      else \
                      HAL_GPIO_WritePin(OLED_DC_Port,OLED_DC_Pin, GPIO_PIN_RESET)
                                          
#define OLED_CS(a) if (a) \
                      HAL_GPIO_WritePin(OLED_CS_Port,OLED_CS_Pin, GPIO_PIN_SET);\
                      else \
                      HAL_GPIO_WritePin(OLED_CS_Port,OLED_CS_Pin, GPIO_PIN_RESET)

#define SET_RST HAL_GPIO_WritePin(OLED_RES_Port, OLED_RES_Pin, GPIO_PIN_SET);
#define CLR_RST HAL_GPIO_WritePin(OLED_RES_Port, OLED_RES_Pin, GPIO_PIN_RESET);

extern SPI_HandleTypeDef hspi1;

static void init_board(GDisplay *g) {
	// As we are not using multiple displays we set g->board to NULL as we don't use it.
	g->board = 0;
}

static void post_init_board(GDisplay *g) {
	(void) g;
}

static void setpin_reset(GDisplay *g, bool_t state) {
	(void) g;
	if(state)
		CLR_RST
	else
		SET_RST
}

static void acquire_bus(GDisplay *g) {
	(void) g;
}

static void release_bus(GDisplay *g) {
	(void) g;
}

static void write_cmd(GDisplay *g, uint8_t cmd) {
	(void)	g;
        OLED_DC(0);
        OLED_CS(0);
        
        HAL_SPI_Transmit(&hspi1, &cmd, 1, 1);  

        OLED_CS(1);
}

static void write_data(GDisplay *g, uint8_t* data, uint16_t length) {
	(void) g;
        OLED_DC(1);
        OLED_CS(0);
        
        HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi1, data, length, 20);
        
        if (status != HAL_OK) {
          HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_SET);
          HAL_Delay(200);
          HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET);
          
        }
        OLED_CS(1);

}

ugfx默认支持chibios,是其一部分,使用IAR编译,会有警告,只能忽略,还没看到什么不良影响。


外设初始化代码,由CUBE生成,在此不需列出。


使用demo里面的代码,画一个矩形。



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

容沁风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值