How to add delay into I2C read frame

praetorz
Posts: 1
Joined: Mon Feb 18, 2019 10:15 am

How to add delay into I2C read frame

Postby praetorz » Mon Feb 18, 2019 6:02 pm

Hi,

I've been playing with an Atlas scientific EZO pH probe attached to my esp32 by I2C. The device works fully using the Arduino wire command. However using the esp-idf I have only been successful at getting commands to be received by the device. I believe the problem to be with the processing delay required by the EZO device of 300ms but I'm unclear as to how to add in a read delay into my I2C command sequence.

Code: Untitled.c Select all

printf("\r\nStarting command sequence\r\n");
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
//begin building command sequence
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (99 << 1) | I2C_MASTER_WRITE, true);
//
for(int num_of_char_in_cmd_str = 0; num_of_char_in_cmd_str < count;num_of_char_in_cmd_str++ ){
i2c_master_write(cmd,&input_characters[num_of_char_in_cmd_str], 1,false);
printf("\r\nThe value of input is: %c\r\n",(char)input_characters[num_of_char_in_cmd_str]);
}

//Now we switch to read mode and build instructions for receiving
i2c_master_write_byte(cmd, (99 << 1)| I2C_MASTER_READ,1);
for(int i=0; i<20;i++){
i2c_master_read_byte(cmd, &data_byte[i], I2C_MASTER_ACK);
}
i2c_master_stop(cmd);

//Send command set to device
esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_1, cmd, 1000 / portTICK_RATE_MS);

if(ret == ESP_OK){
printf( "i2c succes during read: %s", esp_err_to_name(ret));
printf("\r\n-> Data read from EZO pH Probe\r\n");
for(int i = 0; i < 20; i++){
printf("\r\n Bytes received %u\r\n",data_byte[i]);
}
}
if(ret != ESP_OK){
printf( "i2c error during read: %s", esp_err_to_name(ret));
}
i2c_cmd_link_delete(cmd);

cnlohr
Posts: 65
Joined: Sat Dec 03, 2016 5:39 am

Re: How to add delay into I2C read frame

Postby cnlohr » Sun Aug 04, 2019 2:37 am

Just FYI - I ran into this recently. And I'm still having trouble, I have a device which also requires time between the I2C read and actually reading the data back. It seems you can issue i2c_master_cmd_begin, link_delete and a link_create in the middle of your i2c transaction, then finish it as another command and issue i2c_master_cmd_begin again and finish up.

Who is online

Users browsing this forum: Bing [Bot], Bytespider and 1 guest