打印

GD32F307点亮0.96OLED

[复制链接]
618|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
trucyw|  楼主 | 2020-12-19 12:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我们通过Datasheet了解到GD32F307 I2C0使用的IO为PB6/7
因此软件我们只需要使能I2C0即可
rcu_periph_clock_enable(RCU_I2C0);
接下来就是OLED的数据传输
OLED DRIVER DATASHEET 描述The D/C# bit determines the next data byte is acted as a command or a data. If the D/C# bit is
set to logic “0”, it defines the following data byte as a command. If the D/C# bit is set to
logic “1”, it defines the following data byte as a data which will be stored at the GDDRAM.
The GDDRAM column address pointer will be increased by one automatically after each
data write.
接下来该写command or data控制函数
void oled_byte_write(uint8_t write_address)
{
    while(i2c_flag_get(I2C0, I2C_FLAG_I2CBSY));
    i2c_start_on_bus(I2C0);
    while(!i2c_flag_get(I2C0, I2C_FLAG_SBSEND));
    i2c_master_addressing(I2C0, oled_address, I2C_TRANSMITTER);
    while(!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND));
    i2c_flag_clear(I2C0,I2C_FLAG_ADDSEND);
    while(SET != i2c_flag_get(I2C0, I2C_FLAG_TBE));
    i2c_data_transmit(I2C0, 0x00);//COMMAND
    while(!i2c_flag_get(I2C0, I2C_FLAG_BTC));
    i2c_data_transmit(I2C0, write_address);
    while(!i2c_flag_get(I2C0, I2C_FLAG_BTC));
    i2c_stop_on_bus(I2C0);
    while(I2C_CTL0(I2C0)&0x0200);
}

void oled_dat_write(uint8_t write_dat)
{
    while(i2c_flag_get(I2C0, I2C_FLAG_I2CBSY));
    i2c_start_on_bus(I2C0);
    while(!i2c_flag_get(I2C0, I2C_FLAG_SBSEND));
    i2c_master_addressing(I2C0, oled_address, I2C_TRANSMITTER);
    while(!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND));
    i2c_flag_clear(I2C0,I2C_FLAG_ADDSEND);
    while(SET != i2c_flag_get(I2C0, I2C_FLAG_TBE));
    i2c_data_transmit(I2C0, 0x40);//DATA
    while(!i2c_flag_get(I2C0, I2C_FLAG_BTC));
    i2c_data_transmit(I2C0, write_dat);
    while(!i2c_flag_get(I2C0, I2C_FLAG_BTC));
    i2c_stop_on_bus(I2C0);
    while(I2C_CTL0(I2C0)&0x0200);
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

37

主题

705

帖子

2

粉丝