DPS310 pressure sensor interfacing with RTOS

ujurmsde
Posts: 38
Joined: Tue Jan 19, 2021 6:37 am

DPS310 pressure sensor interfacing with RTOS

Postby ujurmsde » Fri Apr 09, 2021 1:14 pm

Hi,

I was trying to interface DPS310 sensor from Infineon with ESP8266 but it is not working as expected. The I2C interface is fetching correct data for the sensor ID but it fails to provide right data for temperature. I have already decided to not work with this sensor but still if someone could have an idea or in future want to use. Fell free to give your suggestions.

Code: Select all

static esp_err_t dps_read(i2c_port_t num, uint8_t reg, uint8_t *data, size_t len){

	int ret;
	i2c_cmd_handle_t cmd= i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, I2C_Address << 1 | WRITE_BIT,ACK_CHECK_EN);
	i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);

	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, I2C_Address << 1 | READ_BIT,ACK_CHECK_EN);
	i2c_master_read(cmd, data,len, ACK_CHECK_DA);

	i2c_master_stop(cmd);
	ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);

	return ret;
}

static esp_err_t dsp_write(i2c_port_t num, uint8_t reg, uint8_t *data){
	int ret;
	i2c_cmd_handle_t cmd= i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, I2C_Address << 1 | WRITE_BIT,ACK_CHECK_EN);
	i2c_master_write_byte(cmd, reg, ACK_CHECK_EN);
	i2c_master_write_byte(cmd, data, ACK_CHECK_EN);
	i2c_master_stop(cmd);
	ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
	i2c_cmd_link_delete(cmd);
	return ret;

}
static int32_t twosComplement(int32_t val, uint8_t bits) {
  if (val & ((uint32_t)1 << (bits - 1))) {
    val -= (uint32_t)1 << bits;
  }
  return val;
}

static void dsp_sens(void *arg){
	uint8_t ID;//=0x05;
	uint8_t Coff_values[18];
	uint8_t cmd_data;
	uint8_t source;
	uint16_t Co[9];
	uint8_t temp[2];
	uint32_t temprature, tcomp, Tc;

	master_init();
	while(1){

		vTaskDelay(100 / portTICK_RATE_MS);
		cmd_data = 0x09;
		dsp_write(i2c_num, 0x0C, &cmd_data);
		dps_read(i2c_num, DPS_PRODUCT_ID, &ID,1);
		//Read register coefficient source//
		dps_read(i2c_num, 0x28, &source,1);
		dps_read(i2c_num, COFF_START, &Coff_values, 18);
		cmd_data = 0x33;
		dsp_write(i2c_num, 0x06, &cmd_data);
		dsp_write(i2c_num, 0x07, &cmd_data);
		cmd_data = 0x0E;
		dsp_write(i2c_num, 0x09, &cmd_data);
		cmd_data = 0x02;
		dsp_write(i2c_num, 0x08, &cmd_data);
		ESP_LOGI(TAG,"WHO_AM_I \n");
		ESP_LOGI(TAG,"WHO_AM_I: 0x%02x\n", ID);

		ESP_LOGI(TAG,"Coefficient source");
		ESP_LOGI(TAG, "Source: 0x%02x\n", source);

		for(int i=0; i<18;i++){
			ESP_LOGI(TAG,"Coefficient values.\n");
			ESP_LOGI(TAG, "Source: 0x%02x\n", Co[i]);

		}

		Co[0] = (Coff_values[0]<< 8 | Coff_values[1]) >> 4;
		Co[1] = (Coff_values[1] & 0x0F)<<8 | Coff_values[2];

		Co[0] = twosComplement(Co[0], 12);
		Co[1] = twosComplement(Co[1], 12);

		dps_read(i2c_num, 0x03, &temp, 3);
		for(int i=0; i<3;i++){
			ESP_LOGI(TAG,"Temprature values \n");
			ESP_LOGI(TAG, "Source: 0x%02x\n", temp[i]);
			}
		temprature = ((temp[0]<<16) | (temp[1]<<8) | temp[2]);
		tcomp = (temprature/7864320);

		Tc = (0.5*Co[0])+(Co[1]*tcomp);
		ESP_LOGI(TAG,"T-comp \n");
		ESP_LOGI(TAG, "%u \n", temprature);
		ESP_LOGI(TAG,"Temprature in C \n");
		ESP_LOGI(TAG,"%u \n", Tc);
		vTaskDelay(1000);
	}

}

Who is online

Users browsing this forum: axellin, Baidu [Spider], ok-home and 96 guests