Dear Sir,
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.
Code:
void demo_i2c_init(void)
{
static 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);
Also i dont get any clue from the capture that you 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.
Thanks MT_dialog
Of course we have setup as 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 */
#定义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
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.
Thanks MT_dialog
I'm using de SSD1306 to
No fancy animations.
你能提供给我一个运行自由端口ed for the DA1468x?
Would save me some time :)
With regards
Peter de Nijs