Dear Sir,
我只想用SSD1306驱动程序incored我的OLED,在外围设备中使用I2C演示,但它不起作用,无论我在代码中更改了什么,I2C通道都只发送0x00。请帮忙。
Code:
void demo_i2c_init(void)
{
静态const i2c_config cfg = {
。speed = HW_I2C_SPEED_STANDARD,
。mode = HW_I2C_MODE_MASTER,
。addr_mode = HW_I2C_ADDRESSING_7B,
};
hw_i2c_init(HW_I2C1, &cfg);
srand(os_get_tick_count());
if (config_need) {
int err;
i2c_device dev;
dev = ad_i2c_open(SSD1306);
err = ssd1306_power_on(dev);
if (err) {
printf(NEWLINE "Error SSD1306_power_on 0x%X", err);
}
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();
return true;
}
static int ssd1306_write_i(i2c_device dev,uint8_t val)
{
uint8_t op[2] = { 0x12,val };
return ad_i2c_write(dev, op, sizeof(op));
}
#if cfg_demo_oled_ssd1306.
/* Combined humidity and pressure sensor */
I2C_SLAVE_DEVICE(I2C1, SSD1306, 0x78, HW_I2C_ADDRESSING_7B, HW_I2C_SPEED_STANDARD);
#endif
Hi Ken Chong,
I dont see anything wrong with the code that you ve pasted, you properly open the adapter and then you start interaction with the i2c, the resource_aquire() function isn't a necessity since the ad_i2c_open() function invokes the resource_acquire() function as long as you have the CONFIG_I2C_EXCLUSIVE_OPEN set to 1. I suppose that you have included the dg_configI2C_ADAPTER and the dg_config_USE_HW_I2C in the custom_config_qspi.h file and you also have configured the the corresponding pins to the proper i2c functionallity in the periph_setup() function ? For example.
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);
此外,我也没有从捕获附加的捕获中得到任何线索,我没有看到任何意味着I2C事务已启动的任何东西,我没有看到您已设置给设备或任何将指示交互已启动的地址的地址。
Thanks MT_dialog
当然我们有设置为below, would i got any problem if i revise the pin to port 3_5(CLK) and 1_2(SDA)? The only different is i am modify pxp_reporter project to add below code in function "periph_init" on main.c
#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)
#endif
#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();
#endif
Hi Ken Chong,
If you are using a QFN package which has a PORT 3 you should be ok. Since you are using a BLE project try to do the following, i suppose that using the ble_adv example would be more efficient since this is a simpler example:
ad_i2c_write(dev, &addr, 1); //perform one byte write
ad_i2c_read(dev, &address, 1); //perform one byte read
所以请尝试上面有和没有I2C外设连接的,并检查至少68x是否会在总线上推送设备的地址。
Thanks MT_dialog
I'm using de SSD1306 to
No fancy animations.
你能提供给我一个运行自由端口ed for the DA1468x?
Would save me some time :)
带着敬意
Peter de Nijs