⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
6 posts / 0 new
Last post
Ken Chong
Offline
Last seen:2 years 9 months ago
加入:2016-10-15 05:40
i2c driver for SSD1306

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));
}

Attachment:
Device:
Ken Chong
Offline
Last seen:2 years 9 months ago
加入:2016-10-15 05:40
#if CFG_DEMO_OLED_SSD1306

#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

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi Ken Chong,

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);

我也不从捕获,你得到任何线索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

Ken Chong
Offline
Last seen:2 years 9 months ago
加入:2016-10-15 05:40
Of course we have setup as

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 */
#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

MT_dialog
Offline
Last seen:2 months 3 weeks ago
Staff
加入:2015-06-08 11:34
Hi Ken Chong,

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:

  • Configure the pins as i ve mentioned above (just invoke the hw_gpio_set_pin_function() with the desired pins and functionallities).
  • The demo_i2c_init() isn't a necessity since the configuration will be applied by the adapter during bus aquirement (since you have use the I2C_SLAVE_DEVICE macro).
  • Before the loop of the BLE task (ble_adv_demo_task in my case) you can apply the below code:
  • dev = ad_i2c_open(SSD1306); //open the I2C device
    ad_i2c_write(dev, &addr, 1); //perform one byte write
    ad_i2c_read(dev, &address, 1); //perform one byte read
  • Even if there is no communication with the peripheral, on the I2C bus the device address that you have set for your peripheral should appear even if the device is not on the other side of the bus.

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

peter.de.nijs@loqed
Offline
Last seen:3 years 2 months ago
加入:2017-10-20 14:32
I'm using de SSD1306 to

I'm using de SSD1306 to
No fancy animations.
你能提供给我一个运行自由端口ed for the DA1468x?

Would save me some time :)

With regards
Peter de Nijs