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.
  1. printf("\r\nStarting command sequence\r\n");
  2.     i2c_cmd_handle_t cmd = i2c_cmd_link_create();
  3.     //begin building command sequence
  4.     i2c_master_start(cmd);
  5.     i2c_master_write_byte(cmd, (99 << 1) | I2C_MASTER_WRITE, true);
  6.     //
  7.     for(int num_of_char_in_cmd_str = 0; num_of_char_in_cmd_str < count;num_of_char_in_cmd_str++ ){
  8.         i2c_master_write(cmd,&input_characters[num_of_char_in_cmd_str], 1,false);
  9.         printf("\r\nThe value of input is: %c\r\n",(char)input_characters[num_of_char_in_cmd_str]);
  10.     }
  11.    
  12.    //Now we switch to read mode and build instructions for receiving
  13.     i2c_master_write_byte(cmd, (99 << 1)| I2C_MASTER_READ,1);
  14.     for(int i=0; i<20;i++){
  15.         i2c_master_read_byte(cmd, &data_byte[i], I2C_MASTER_ACK);
  16.     }
  17.     i2c_master_stop(cmd);
  18.    
  19.     //Send command set to device
  20.     esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_1, cmd, 1000 / portTICK_RATE_MS);
  21.    
  22.     if(ret == ESP_OK){
  23.         printf( "i2c succes during read: %s", esp_err_to_name(ret));
  24.         printf("\r\n-> Data read from EZO pH Probe\r\n");
  25.         for(int i = 0; i < 20; i++){
  26.             printf("\r\n Bytes received %u\r\n",data_byte[i]);
  27.         }
  28.     }
  29.     if(ret != ESP_OK){
  30.         printf( "i2c error during read: %s", esp_err_to_name(ret));
  31.     }
  32.     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: Google [Bot] and 60 guests