Help with XMC4800 and DPS310 Sensor

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
User21513
Level 1
Level 1
First reply posted First question asked Welcome!
Hi can anyone help me with the DPS310 and XMC4800? Currently, there are no examples available. The examples available only use Arduino IDE and not DAVE.

From what I understand the program flow should be like this.

//**Initialize DPS310
//**Read Coefficients
//**Setup Register of Sensor (Pressure:0x06 Temperature:0x07)
//**Setup Configuration register (0x09)
//**Read Pressure measurement Registers (0x00, 0x01, 0x02) (23:16, 15:8, 7:0)
//**Calculate using Formula the Actual measurement (Pressure or Temperature)
//**** Calculate pressure in Pascals
PRESSURE_SCALE = dps310_pressure_reading / DPS310_SCALE_FACTOR;
TEMPERATURE_SCALE = dps310_temperature_reading / DPS310_SCALE_FACTOR;

Final_pressure_reading = dps310_c00 + PRESSURE_SCALE*(dps310_c10 + PRESSURE_SCALE *(dps310_c20+ PRESSURE_SCALE *dps310_c30)) + TEMPERATURE_SCALE *dps310_c01 + TEMPERATURE_SCALE *PRESSURE_SCALE *(dps310_c11+PRESSURE_SCALE*dps310_c21);

//**** Calculate Temperature in Celsius
Final_temperature_reading = dps310_c0*0.5 + dps310_c1*TEMPERATURE_SCALE


However, I am having a hard time integrating it and making it work.

Here is a part of my code. ATTACHED is the full code


/*
* main.c
*
*/

#include //Declarations from DAVE Code Generation (includes SFR declaration)

int main(void)
{
DAVE_STATUS_t status;

uint32_t Timer1_ID, timer_status;


status = DAVE_Init(); /* Initialization of DAVE APPs */

if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

/* Placeholder for user application code. The while loop below can be replaced with user application code. */

Timer1_ID = SYSTIMER_CreateTimer(MSEC_100, SYSTIMER_MODE_ONE_SHOT, (void*)Timer1_Timeout, NULL);
m_timer1_count=0;
timer_status = SYSTIMER_StartTimer(Timer1_ID);
while(m_timer1_count == 0);

Init_DPS310(); ///edit
DPS310_Read_Pressure();

while(1U)
//WAIT FOR dps310 FOR STARTUP
{

}
}

void Timer1_Timeout(void)
{
m_timer1_count++;
}//Timer1_Timeout

void DPS310_Interrupt_Handler(void)
{

}//BPS310_Interrupt_Handler


void DPS310_I2C_Write(uint8_t diw_register_address, uint8_t diw_write_command)
/*
* Purpose: Writes one byte of data into a DPS310 register
* Inputs: Register address and the data to write
* Outputs: None
*/
{
uint8_t diw_write_buffer[2];

//place register address and register contents in write buffer
diw_write_buffer[0] = diw_register_address;
diw_write_buffer[1] = diw_write_command;


I2C_MASTER_Transmit(&I2C_MASTER_DPS310, DPS310_SEND_START, DPS310_ADDRESS_SDO_NC, diw_write_buffer, 2U, DPS310_SEND_STOP);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_DPS310));

}//DSP310_Write


void DPS310_I2C_Read(uint8_t dir_start_register_address, uint8_t dir_read_byte_count, uint8_t *dir_data_read_buffer)
/*
* Purpose: Read one or more bytes of data from the DPS310 to the buffer specified
* Inputs: Address of the first register to read from, the number of data bytes to read and the address of the read buffer
* Outputs: None
*/
{
I2C_MASTER_Transmit(&I2C_MASTER_DPS310, DPS310_SEND_START, DPS310_ADDRESS_SDO_NC, &dir_start_register_address, 1U, DPS310_NO_STOP);
while(I2C_MASTER_IsTxBusy(&I2C_MASTER_DPS310));

I2C_MASTER_Receive(&I2C_MASTER_DPS310, DPS310_SEND_START, DPS310_ADDRESS_SDO_NC, dir_data_read_buffer, dir_read_byte_count, DPS310_SEND_STOP, DPS310_SEND_NACK);
while(I2C_MASTER_IsRxBusy(&I2C_MASTER_DPS310));

}//DPS310_Read


void DSP310_Read_MEAS_CFG_Reg(void)
/*
* Purpose: Read in the MEAS_CFG register and store it the DPS310_Mode_Sensor_register variable.
* Input:
* Output:
*
*/
{
DPS310_I2C_Read(DPS310_MEAS_CFG, 1U, &dsp310_meas_cfg_register);
}//DSP310_Read_MEAS_CFG_Reg


void Init_DPS310(void)
{
uint8_t dps310_tmp_coef_srce_flag;

//INITIALIZE SENSOR
do
{
DSP310_Read_MEAS_CFG_Reg();
} while (!(dsp310_meas_cfg_register & DPS310_MCR_SENSOR_RDY_FLAG));

//wait for coefficients to be available
do
{
DSP310_Read_MEAS_CFG_Reg();
} while (!(dsp310_meas_cfg_register & DPS310_MCR_COEFF_RDY_FLAG));

//REGISTERS 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21.... Total of 18 registers
DPS310_I2C_Read(DPS310_COEF_c0_B1, 18U, dps310_coefficients);

//Setup Pressure configuration register 0x06
DPS310_I2C_Write(DPS310_PRS_CFG, 0x00);
m_Delay_x_1msec(2);

//Read in the temperature coefficient source flag
DPS310_I2C_Read(DPS310_COEF_SRCE, 1U, &dps310_tmp_coef_srce_flag);
m_Delay_x_1msec(2);

//Setup Temperature configuration register
if (dps310_tmp_coef_srce_flag & 0x80)
{ //use external sensor
DPS310_I2C_Write(DPS310_TMP_CFG, 0x80);
}//if
else
{
DPS310_I2C_Write(DPS310_TMP_CFG, 0x00);
}//else
m_Delay_x_1msec(2);




//Setup interrupt and FIFO Configuration register
DPS310_I2C_Write(DPS310_CFG_REG, 0x00);
m_Delay_x_1msec(2);

// setup continous measurement (Config Register)
//dps310_write_data[0] = DPS310_MCR_CONT_PRS_TMP_MEAS;
//DPS310_I2C_Write(DPS310_CFG_REG, DPS310_MCR_CONT_PRS_TMP_MEAS);

//load coefficient values into variables
dps310_c00 = (dps310_coefficients[3] << 12) | (dps310_coefficients[4] << 4) | ((dps310_coefficients[5] >> 4) && 0x0f);
dps310_c10 = ((dps310_coefficients[5] & 0x0f) << 16) | (dps310_coefficients[6] << 😎 | dps310_coefficients[7];
dps310_c20 = (dps310_coefficients[12] << 😎 | dps310_coefficients[13];
dps310_c30 = (dps310_coefficients[16] << 😎 | dps310_coefficients[17];
dps310_c01 = (dps310_coefficients[8] << 😎 | dps310_coefficients[9];
dps310_c11 = (dps310_coefficients[10] << 😎 | dps310_coefficients[11];

dps310_c21 = (dps310_coefficients[14] << 😎 | dps310_coefficients[15];
dps310_c0 = (dps310_coefficients[0] << 4) | ((dps310_coefficients[1] & 0xf0) >> 4) ;
dps310_c1 = ((dps310_coefficients[1] & 0x0f) << 😎 | dps310_coefficients[2];
}

void DPS310_Read_Temperature(void)
{

DSP310_Read_MEAS_CFG_Reg();

//trigger a measurement if no background continuous temperature measurements
if ((dsp310_meas_cfg_register & DPS310_MCR_CONT_TMP_MEAS) != DPS310_MCR_CONT_TMP_MEAS)
{
//Trigger a temperature measurement
// dps310_write_data[0] = DPS310_MCR_TEMP_MEAS; //Command mode - temperature measurement
DPS310_I2C_Write(DPS310_MEAS_CFG, DPS310_MCR_TEMP_MEAS);
m_Delay_x_1msec(10);
DSP310_Read_MEAS_CFG_Reg();
}//if
m_Delay_x_1msec(2);

if (!(dsp310_meas_cfg_register & DPS310_MCR_TEMP_MEAS_RDY_FLAG))
{
//temperature measurement ready flag not set
m_Delay_x_1msec(3);
}

//Read in the three temperature measurement registers
DPS310_I2C_Read(DPS310_TMP_B2, 3U, dps310_temperature_reading);

//**** calculate temperature
TEMPERATURE_SCALE = *dps310_temperature_reading / DPS310_SCALE_FACTOR_1;
Final_temperature_reading = dps310_c0*0.5 + dps310_c1*TEMPERATURE_SCALE;

}//DPS310_Read_Temperature

void DPS310_Read_Pressure(void)
{
//Setup Configuration register for temperature measurement

DSP310_Read_MEAS_CFG_Reg();

//trigger a measurement if no background continuous pressure measurements
if (((dsp310_meas_cfg_register & 0x07) != DPS310_MCR_CONT_TMP_MEAS) &&
((dsp310_meas_cfg_register & 0x07) != DPS310_MCR_CONT_PRS_TMP_MEAS))
{
//Trigger a pressure measurement
DPS310_I2C_Write(DPS310_MEAS_CFG, DPS310_MCR_PRS_MEAS);
m_Delay_x_1msec(10);
DSP310_Read_MEAS_CFG_Reg();
}//if
m_Delay_x_1msec(2);

if (!(dsp310_meas_cfg_register & DPS310_MCR_PRESSURE_MEAS_RDY_FLAG))
{
m_Delay_x_1msec(3);
}

//Read Pressure measurement Registers (0x00, 0x01, 0x02) (23:16, 15:8, 7:0)
DPS310_I2C_Read(DPS310_PSB_B2, 3U, dps310_pressure_reading);

//**** calculate pressure in Pascals
PRESSURE_SCALE = *dps310_pressure_reading / DPS310_SCALE_FACTOR_1;
TEMPERATURE_SCALE = *dps310_temperature_reading / DPS310_SCALE_FACTOR_1;
Final_pressure_reading = dps310_c00 + PRESSURE_SCALE*(dps310_c10 + PRESSURE_SCALE *(dps310_c20+ PRESSURE_SCALE *dps310_c30)) + TEMPERATURE_SCALE *dps310_c01 + TEMPERATURE_SCALE *PRESSURE_SCALE *(dps310_c11+PRESSURE_SCALE*dps310_c21);

// TEMPERATURE
//Final_temperature_reading = dps310_c0*0.5 + dps310_c1*TEMPERATURE_SCALE


}//DPS310_Read_Pressure

void m_Delay_x_1msec(uint32_t delay_val)
{
uint32_t delay_cnt;

delay_cnt = delay_val * TIMER_DELAY_MUL_FACTOR;

TIMER_SetTimeInterval(&TIMER_0,delay_cnt);

TIMER_Start(&TIMER_0);

while(!TIMER_GetInterruptStatus(&TIMER_0));

TIMER_Stop(&TIMER_0);
}



Thank you and I hope you can help me.
0 Likes
0 Replies