i2c how to set register in ds3231

NIXIE_123
Posts: 3
Joined: Fri Aug 02, 2019 9:51 am

i2c how to set register in ds3231

Postby NIXIE_123 » Fri Aug 02, 2019 10:18 am

Hi everyone

I have read espressif's document about how to use i2c. I also read example and i know how to send one byte. But how can i send byte (slave address) then register address and finally value that i want to write into this register?

Slave address: 0xD0
Register address: 0x0E
Value: 0x0

I am using eclipse with esp-idf

mikemoy
Posts: 370
Joined: Fri Jan 12, 2018 9:10 pm

Re: i2c how to set register in ds3231

Postby mikemoy » Sun Aug 04, 2019 11:13 am

Have you looked at the examples for I2c?

Code: Select all


I2C_WriteByte(0xD0, 0x0E, 0x00);


esp_err_t I2C_WriteByte(uint8_t icAddress, uint8_t reg, uint8_t value)
{
	esp_err_t espRc;

	i2c_cmd_handle_t cmd = i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, (icAddress << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);  
	i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
	i2c_master_write_byte(cmd, value, ACK_CHECK_EN);
	i2c_master_stop(cmd);

	espRc = i2c_master_cmd_begin(I2C_NUM_1, cmd, 10 / portTICK_RATE_MS);
	i2c_cmd_link_delete(cmd);

	if (espRc == ESP_FAIL)
	{
		printf("WriteByte Fail\r\n");
	}
	
	return espRc;
}

NIXIE_123
Posts: 3
Joined: Fri Aug 02, 2019 9:51 am

Re: i2c how to set register in ds3231

Postby NIXIE_123 » Tue Aug 06, 2019 8:46 am

Yes, i have looked. Thank you very much, that's what i was looking for

Who is online

Users browsing this forum: No registered users and 15 guests