i2cOLED接上去不显示
时间: 2023-08-04 13:04:54 浏览: 70
您好!很抱歉听到您遇到了问题。要解决i2c OLED不显示的问题,您可以尝试以下几个步骤:
1. 确保接线正确:检查一下您的i2c OLED模块是否正确连接到主控制器上。确保SDA(数据线)和SCL(时钟线)正确连接。
2. 确认地址设置:某些i2c OLED模块具有可调节的i2c地址。请确保您的主控制器和OLED模块使用相同的i2c地址。如果不确定,可以查看模块的规格说明书。
3. 检查电源供应:确保您的i2c OLED模块有足够的电源供应。有些OLED模块可能需要外部电源。
4. 检查代码:请检查您的代码是否正确初始化了i2c总线和OLED模块。确保您的代码没有错误,并且使用了正确的库和函数。
5. 调整对比度:尝试调整OLED模块的对比度设置。有些模块可能需要手动调整对比度才能正确显示。
如果您尝试了以上步骤后问题仍然存在,可能是硬件故障或其他问题导致的。您可以尝试更换一个新的OLED模块或者检查其他可能影响显示的因素。希望这些提示能帮到您!如果您有任何其他问题,请随时提问。
相关问题
在stm32f103c8t6上使用的的0.96寸i2coled显示屏代码
以下是使用STM32F103C8T6控制0.96寸I2C OLED显示屏的代码,需要注意的是,你需要将i2c.h和i2c.c文件添加到你的工程中,并根据你的硬件连接修改i2c.h文件中的宏定义。
```c
#include "stm32f10x.h"
#include "i2c.h"
#define OLED_ADDRESS 0x78
#define OLED_CMD 0x00
#define OLED_DATA 0x40
void OLED_Init(void);
void OLED_WriteCmd(uint8_t cmd);
void OLED_WriteData(uint8_t data);
void OLED_SetPos(uint8_t x, uint8_t y);
void OLED_Fill(uint8_t fill_Data);
void OLED_ShowChar(uint8_t x, uint8_t y, uint8_t chr);
void OLED_ShowString(uint8_t x, uint8_t y, uint8_t *str);
int main(void)
{
SystemInit();
I2C_Init();
OLED_Init();
while (1)
{
OLED_Fill(0xFF);
OLED_ShowString(0, 0, "Hello World!");
}
}
void OLED_Init(void)
{
OLED_WriteCmd(0xAE);//display off
OLED_WriteCmd(0x20);//Set Memory Addressing Mode
OLED_WriteCmd(0x10);//00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
OLED_WriteCmd(0xb0);//Set Page Start Address for Page Addressing Mode,0-7
OLED_WriteCmd(0xc8);//Set COM Output Scan Direction
OLED_WriteCmd(0x00);//---set low column address
OLED_WriteCmd(0x10);//---set high column address
OLED_WriteCmd(0x40);//--set start line address
OLED_WriteCmd(0x81);//--set contrast control register
OLED_WriteCmd(0xff);
OLED_WriteCmd(0xa1);//--set segment re-map 0 to 127
OLED_WriteCmd(0xa6);//--set normal display
OLED_WriteCmd(0xa8);//--set multiplex ratio(1 to 64)
OLED_WriteCmd(0x3F);//--1/64 duty
OLED_WriteCmd(0xa4);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content
OLED_WriteCmd(0xd3);//-set display offset
OLED_WriteCmd(0x00);//-not offset
OLED_WriteCmd(0xd5);//--set display clock divide ratio/oscillator frequency
OLED_WriteCmd(0xf0);//--set divide ratio
OLED_WriteCmd(0xd9);//--set pre-charge period
OLED_WriteCmd(0x22); //
OLED_WriteCmd(0xda);//--set com pins hardware configuration
OLED_WriteCmd(0x12);
OLED_WriteCmd(0xdb);//--set vcomh
OLED_WriteCmd(0x20);//0x20,0.77xVcc
OLED_WriteCmd(0x8d);//--set DC-DC enable
OLED_WriteCmd(0x14);//
OLED_WriteCmd(0xaf);//--turn on oled panel
}
void OLED_WriteCmd(uint8_t cmd)
{
I2C_Start();
I2C_SendByte(OLED_ADDRESS);
I2C_SendByte(OLED_CMD);
I2C_SendByte(cmd);
I2C_Stop();
}
void OLED_WriteData(uint8_t data)
{
I2C_Start();
I2C_SendByte(OLED_ADDRESS);
I2C_SendByte(OLED_DATA);
I2C_SendByte(data);
I2C_Stop();
}
void OLED_SetPos(uint8_t x, uint8_t y)
{
OLED_WriteCmd(0xb0 + y);
OLED_WriteCmd(((x & 0xf0) >> 4) | 0x10);
OLED_WriteCmd(x & 0x0f);
}
void OLED_Fill(uint8_t fill_Data)
{
uint8_t m, n;
for (m = 0; m < 8; m++)
{
OLED_WriteCmd(0xb0 + m); //page0-page1
OLED_WriteCmd(0x00); //low column start address
OLED_WriteCmd(0x10); //high column start address
for (n = 0; n < 128; n++)
{
OLED_WriteData(fill_Data);
}
}
}
void OLED_ShowChar(uint8_t x, uint8_t y, uint8_t chr)
{
uint8_t c = 0, i = 0;
c = chr - ' '; //得到偏移后的值
if (x > 120)
{
x = 0;
y++;
}
OLED_SetPos(x, y);
for (i = 0; i < 6; i++)
{
OLED_WriteData(F6x8[c][i]);
}
}
void OLED_ShowString(uint8_t x, uint8_t y, uint8_t *str)
{
uint8_t j = 0;
while (str[j] != '\0')
{
OLED_ShowChar(x, y, str[j]);
x += 6;
if (x > 126)
{
x = 0;
y++;
}
j++;
}
}
```
以上代码中的i2c.h和i2c.c文件可以在网上找到,也可以自己编写。另外,需要注意的是,本代码使用的是6x8点阵字体,如果需要使用其他字体,需要修改OLED_ShowChar函数中的字体数组。
stm32f103c8t6 I2COLED
好的,以下是在STM32F103C8T6上使用I2C OLED的步骤:
1. 首先,您需要在STM32CubeMX中打开您的项目,并在“Pinout”选项卡中配置I2C和OLED引脚。选中SCL和SDA引脚,将其配置为I2C模式,并设置GPIO的输入/输出模式和速度。同时,您需要根据您的OLED型号选择正确的引脚并将其配置为输出模式。
2. 然后,在“Clock Configuration”选项卡中,启用I2C时钟,并设置I2C时钟的频率。
3. 接下来,在“Configuration”选项卡中,选择I2C外设,并根据您的需求进行配置。例如,您可以设置I2C的工作模式、地址长度、时钟占空比等。同时,您需要在代码中配置OLED的I2C地址和屏幕大小等参数。
4. 在代码中,您需要使用HAL库或其他库来初始化I2C外设,并设置I2C和OLED的参数。例如,您可以使用以下代码初始化I2C1和OLED:
```
I2C_HandleTypeDef hi2c1;
void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000;
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
}
#define OLED_I2C_ADDR 0x78
#define OLED_WIDTH 128
#define OLED_HEIGHT 64
void OLED_Init(void)
{
HAL_Delay(100);
OLED_WR_Byte(0xAE, OLED_CMD); //关闭显示
OLED_WR_Byte(0xD5, OLED_CMD); //设置时钟分频因子,震荡频率
OLED_WR_Byte(0x80, OLED_CMD); //[3:0],分频因子;[7:4],震荡频率
OLED_WR_Byte(0xA8, OLED_CMD); //设置驱动路数
OLED_WR_Byte(0X3F, OLED_CMD); //默认0X3F(1/64)
OLED_WR_Byte(0xD3, OLED_CMD); //设置显示偏移
OLED_WR_Byte(0X00, OLED_CMD); //默认为0
OLED_WR_Byte(0x40, OLED_CMD); //设置显示开始行 [5:0],行数.
OLED_WR_Byte(0x8D, OLED_CMD); //电荷泵设置
OLED_WR_Byte(0x14, OLED_CMD); //bit2,开启/关闭
OLED_WR_Byte(0x20, OLED_CMD); //设置内存地址模式
OLED_WR_Byte(0x02, OLED_CMD); //[1:0],00,列地址模式;01,行地址模式;10,页地址模式;默认10;
OLED_WR_Byte(0xA1, OLED_CMD); //段重定向设置
OLED_WR_Byte(0xC0, OLED_CMD); //设置COM扫描方向;默认为逆向
OLED_WR_Byte(0xDA, OLED_CMD); //设置COM硬件引脚配置
OLED_WR_Byte(0x12, OLED_CMD); //[5:4]配置
OLED_WR_Byte(0x81, OLED_CMD); //对比度设置
OLED_WR_Byte(0xEF, OLED_CMD); //1~255;默认0X7F (亮度设置,越大越亮)
OLED_WR_Byte(0xD9, OLED_CMD); //设置预充电周期
OLED_WR_Byte(0xf1, OLED_CMD); //[3:0],PHASE 1;[7:4],PHASE 2;
OLED_WR_Byte(0xDB, OLED_CMD); //设置VCOMH 电压倍率
OLED_WR_Byte(0x40, OLED_CMD); //设置VCOMH 电压倍率
OLED_WR_Byte(0xA4, OLED_CMD); //全局显示开启;bit0:1,开启;0,关闭;(白屏/黑屏)
OLED_WR_Byte(0xA6, OLED_CMD); //设置显示方式;bit0:1,反相显示;0,正常显示
OLED_WR_Byte(0xAF, OLED_CMD); //开启显示
}
```
5. 接下来,您可以使用HAL库或其他库中提供的函数来向OLED写入数据。例如,您可以使用以下代码向OLED写入一个字节的数据:
```
HAL_I2C_Mem_Write(&hi2c1, OLED_I2C_ADDR, OLED_CMD, 1, &data, 1, 10);
```
6. 最后,不要忘记在使用I2C和OLED外设后及时释放总线,以便其他设备可以访问它。例如,您可以使用以下代码释放I2C总线:
```
HAL_I2C_ReleaseBus(&hi2c1);
```
希望这些步骤可以帮助您在STM32F103C8T6上使用I2C OLED。
阅读全文
相关推荐
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)