u8g2lib驱动SSD1322屏幕刷新慢的解决方法
在构造器中优先选择带HW的
class U8G2_SSD1322_NHD_256X64_F_2ND_4W_HW_SPI : public U8G2 { public: U8G2_SSD1322_NHD_256X64_F_2ND_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { u8g2_Setup_ssd1322_nhd_256x64_f(&u8g2, rotation, u8x8_byte_arduino_2nd_hw_spi, u8x8_gpio_and_delay_arduino); u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); } };
其实和SPI还有WIRE库的关系不大
#include <Arduino.h> #include <U8g2lib.h> #include <SPI.h> #include <Wire.h> #define SCREEN_WIDTH 256 #define SCREEN_HEIGHT 64 //U8G2_SSD1322_NHD_256X64_F_4W_SW_SPI display(U8G2_R0, /* clock=*/ 18, /* data=*/ 19, /* cs=*/ 17, /* dc=*/ 15, /* reset=*/ 14); U8G2_SSD1322_NHD_256X64_F_4W_HW_SPI display(U8G2_R0, /* cs=*/ 17, /* dc=*/ 15, /* reset=*/ 14); //U8G2_SSD1322_NHD_256X64_F_2ND_4W_HW_SPI display(U8G2_R0, /* clock=*/ 18, /* data=*/ 19, /* cs=*/ 17, /* dc=*/ 15, /* reset=*/ 14); // 'logo', 256x64px //logo区域 看着眼晕
SetBusClock应该在begin之前
void setup(void) { display.setBusClock(150000000); display.begin(); //display.setPowerSave(0); }
构造器的规则。
构造器的名字包括以下几方面:
| No | Description | Example |
|---|---|---|
| 1 | Prefix | U8G2 |
| 2 | Display Controller | SSD1306 |
| 3 | Display Name | 128X64_NONAME |
| 4 | Buffer Size | 1, 2 or F (full frame buffer) |
| 5 | Communication | 4W_SW_SPI |
它们之间使用"_"连接起来。其中:
- BufferSize,缓存大小
| BufferSize | Description |
|---|---|
| 1 | 保持一页的缓冲区,用于firstPage/nextPage的PageMode. |
| 2 | 保持两页的缓冲区,用于firstPage/nextPage的PageMode.. |
| F | 获取整个屏幕的缓冲区,ram消耗大,一般用在ram空间比较大的arduino板子. |
- Communication,通信协议
| Communication | Description |
|---|---|
| 4W_SW_SPI | 4-wire (clock, data, cs and dc) software emulated SPI |
| 4W_HW_SPI | 4-wire (clock, data, cs and dc) hardware SPI (based on Arduino SPI library) |
| 2ND_4W_HW_SPI | If supported, second 4-wire hardware SPI (based on Arduino SPI library) |
| 3W_SW_SPI | 3-wire (clock, data and cs) software emulated SPI |
| SW_I2C | Software emulated I2C/TWI |
| HW_I2C | Hardware I2C based on the Arduino Wire library |
| 2ND_HW_I2C | If supported, use second hardware I2C (Arduino Wire lib) |
| 6800 | 8-bit parallel interface, 6800 protocol |
| 8080 | 8-bit parallel interface, 8080 protocol |
- Rotation (软件模拟总线前提下的构造器的第一个参数)
| Rotation/Mirror | Description |
|---|---|
| U8G2_R0 | No rotation, landscape |
| U8G2_R1 | 90 degree clockwise rotation |
| U8G2_R2 | 180 degree clockwise rotation |
| U8G2_R3 | 270 degree clockwise rotation |
| U8G2_MIRROR | No rotation, landscape, display content is mirrored (v2.6.x) |
浙公网安备 33010602011771号