I have an issue with the i2c_master_cmd_begin() function.
I want to read the 14 data registers of an mpu_6050 (Acc_x, Acc_y, Acc_z, Temp, G_x, G_y, G_z).
So I make the following command :
Code: Select all
esp_err_t ret ;
/// Buffer où mettre les 14 octets lus depuis le mpu
uint8_t p_buff_raw_data[14];
/// Préparation d'une commande lecture de 14 octets à partir de <ACCEL_XOUT_H_ADDR>
/// Création d'un variable (handler) <cmd_read_14_AccX> grâce auquel on va construire */
i2c_cmd_handle_t cmd_read_14_AccX = i2c_cmd_link_create();
/// Signal <START> (voir description I2C)
i2c_master_start(cmd_read_14_AccX);
/// Adresse du périphérique (écriture)
i2c_master_write_byte(cmd_read_14_AccX, 0x68 << 1, ACK_CHECK_EN);
/// Adresse du premier registre
i2c_master_write_byte(cmd_read_14_AccX, 0x3B, ACK_CHECK_EN);
/// Nouveau signal <START>
i2c_master_start(cmd_read_14_AccX);
/// Adresse du périphérique (lecture)
i2c_master_write_byte(cmd_read_14_AccX, (0x68 << 1)|I2C_MASTER_READ, ACK_CHECK_EN);
/// Lecture de 13 octets avec un signal <ACK> en retour
i2c_master_read(cmd_read_14_AccX, p_buff_raw_data, 13, ACK_VAL);
/// Lecture du 14-èmè avec un signal <NACK> en retour
i2c_master_read_byte(cmd_read_14_AccX, p_buff_raw_data+13, NACK_VAL);
/// Signal <STOP>
i2c_master_stop(cmd_read_14_AccX);vTaskDelay(100);
Code: Select all
ret = i2c_master_cmd_begin(0, cmd_read_14_AccX , 1000 / portTICK_RATE_MS);
printf("*** (1) * err retour = %i \r\n",ret);
Since I want to read these registers again and again, I tought that I could use the same cmd_read_14_AccX without deleting and rebuildind it. But If i execute twice i2c_master_cmd_begin() with the same cmd_read_14_AccX :
Code: Select all
ret = i2c_master_cmd_begin(0, cmd_read_14_AccX , 1000 / portTICK_RATE_MS);
printf("*** (1) * err retour = %i \r\n",ret);
vTaskDelay(100);
ret = i2c_master_cmd_begin(0, cmd_read_14_AccX , 1000 / portTICK_RATE_MS);
printf("*** (2) * err retour = %i \r\n",ret);
Moreover the I2C seems blocked and I have to unplug the device before getting another correct read.
Any hint ?
Thanks in advance.
I am working with : esp-idf v4.1-dev-2020-ga7bbc74a2-dirty