尊敬的先生,
I just want to init my OLED with SSD1306 driver , using the i2c demo in peripherals project, however it doesn't work, the i2c channel only send out 0x00 no matter what i change in the code. Please help.
代码:
void demo_i2c_init(void)
{
static const i2c_config cfg = {
.speed = hw_i2c_speed_standard,
.mode = hw_i2c_mode_master,
.ddr_mode = hw_i2c_addressing_7b,
};
hw_i2c_init(hw_i2c1,cfg);
srand(OS_GET_TICK_COUNT());
if(config_need){
呃;
i2c_device dev;
dev = ad_i2c_open(SSD1306);
err = SSD1306_power_on(dev);
如果(错误){
printf(换行符“错误ssd1306_power_on 0x%x”,错误);
}
ad_i2c_close(dev);
config_need = false;
}
}
int ssd1306_power_on(i2c_device dev)
{
//OS_ENTER_CRITICAL_SECTION();
ad_i2c_device_acquire(dev);
SSD1306._write_i(dev,0xAE);
SSD1306._write_i(dev,0x00);
SSD1306_WRITE_I(DEV,0x10);
SSD1306_WRITE_I(DEV,0x40);
ssd1306_write_i(dev,0xb0);
SSD1306_WRITE_I(DEV,0x81);
SSD1306_WRITE_I(DEV,0xAF);
SSD1306._write_i(dev,0xA1);
SSD1306_WRITE_I(DEV,0xA6);
SSD1306_WRITE_I(DEV,0xA8);
ssd1306_write_i(dev,0x0f);
SSD1306._write_i(dev,0xC8);
SSD1306_WRITE_I(DEV,0xD3);
SSD1306._write_i(dev,0x00);
SSD1306._write_i(dev,0xD5);
SSD1306_WRITE_I(DEV,0x80);
SSD1306._write_i(dev,0xD9);
SSD1306_WRITE_I(DEV,0x22);
SSD1306_WRITE_I(DEV,0xDA);
SSD1306_WRITE_I(DEV,0x02);
SSD1306._write_i(dev,0xdb);
SSD1306_WRITE_I(DEV,0x40);
SSD1306._write_i(dev,0x8d);
SSD1306_WRITE_I(DEV,0x10);
SSD1306_WRITE_I(0xAF);
ad_i2c_device_release(dev);
//OS_LEAVE_CRITICAL_SECTION();
返回真;
}
static int SSD1306_write_i(i2c_device dev,uint8_t val)
{
uint8_t op [2] = {0x12,val};
返回AD_I2C_WRITE(DEV,OP,SIZEOF(OP));
}
#if CFG_DEMO_OLED_SSD1306
/ *组合湿度和压力传感器* /
i2c_slave_device(i2c1,ssd1306,0x78,hw_i2c_addressing_7b,hw_i2c_speed_standard);
#万一
嗨肯冲,
我没有看到任何错误的代码,你粘贴的代码,你可以正确打开适配器,然后你开始与I2C的交互,Resource_aquire()函数不是必需品,因为AD_I2C_OPEN()函数调用Resource_Acquire()函数只要您将Config_i2c_exclusive_open设置为1.我想在custom_config_qspi.h文件中包含dg_configi2c_adapter和dg_config_use_hw_i2c,并且您还将相应的引脚配置为periph_setup()函数中的正确I2C功能?例如。
hw_gpio_set_pin_function(hw_gpio_port_1,hw_gpio_pin_6,hw_gpio_mode_output,hw_gpio_func_i2c_scl);
hw_gpio_set_pin_function(hw_gpio_port_1,hw_gpio_pin_7,hw_gpio_mode_input,hw_gpio_func_i2c_sda);
我也不从捕获,你得到任何线索have attached, i dont see anything that would indicate that an i2c transaction has started, i dont see the address that you have set to the device or anything that would indicate that an interaction has started.
谢谢mt_dialog.
当然,我们的设置如下,如果我将引脚修改为端口3_5(CLK)和1_2(SDA),则会出现任何问题吗?唯一的不同是我正在修改pxp_reporter项目,以在main.c上的函数“periph_init”中添加以下代码
#define dg_configuse_hw_i2c(1)
#define dg_configi2c_adapter(1)
#define cfg_demo_hw_i2c(1)
#if cfg_demo_hw_i2c ||cfg_ad_i2c_1.
/ * i2c1 * /
#define CFG_GPIO_I2C1_SCL_PORT (HW_GPIO_PORT_3)
#define cfg_gpio_i2c1_scl_pin(hw_gpio_pin_5)
#define CFG_GPIO_I2C1_SDA_PORT (HW_GPIO_PORT_1)
#define cfg_gpio_i2c1_sda_pin(hw_gpio_pin_2)
#万一
#if cfg_demo_hw_i2c.
/ * i2c * /
hw_gpio_set_pin_function(CFG_GPIO_I2C1_SCL_PORT,CFG_GPIO_I2C1_SCL_PIN,HW_GPIO_MODE_OUTPUT,HW_GPIO_FUNC_I2C_SCL);
hw_gpio_set_pin_function(cfg_gpio_i2c1_sda_port,cfg_gpio_i2c1_sda_pin,hw_gpio_mode_input,hw_gpio_func_i2c_sda);
hw_gpio_configure_pin(CFG_GPIO_TFT_RES_PORT, CFG_GPIO_TFT_RES_PIN, HW_GPIO_MODE_OUTPUT,HW_GPIO_FUNC_GPIO,1);
hw_gpio_configure_pin(cfg_gpio_tq_port,cfg_gpio_tq_pin,hw_gpio_mode_output,hw_gpio_func_gpio,1);
demo_i2c_init();
#万一
嗨肯冲,
如果您使用的是具有端口3的QFN包,则应确定。由于您使用的是BLE项目尝试执行以下操作,我想使用BLE_ADV【使用率更有效,因为这是一个更简单的示例:
ad_i2c_write(dev,&addr,1);//执行一个字节写入
ad_i2c_read(dev,地址,1);//执行一个字节读取
So please try the above with and without the I2C peripheral connected, and check if at least the 68x pushes the address of the device on the bus.
谢谢mt_dialog.
我正在使用de ssd1306
没有花哨的动画。
您可以为我提供一个针对DA1468x的运行lib吗?
会救我一些时间:)
With regards
Peter de Nijs.