Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

DPS310 pressure sensor driver - unit issue


Hello all,

For DPS310 pressure sensor, to convert pressure unit from pascal to hectopascal, the pressure value has to be divided by 10^2. For example, from driver side, if we send 932.34 hPa (after conversion), the application retrieves it as 93234 hPa (without decimal). If we send the pressure in Pa value divided by 10^5, only then the application retrieves it as 932.34 hPa (as expected). Can someone reach out to this?



  • Mark_RoddyMark_Roddy Member - All Emails Posts: 4,551
    via Email
    This is your driver and your application, right? So the problem is
    entirely internal to your implementation. How do you expect to get help

    Mark Roddy
  • MBond2MBond2 Member Posts: 466

    What data type are you using to communicate these values between your driver and application?


    @Mark_Roddy, @MBond2 :

    I used the application reference:

    From driver: Here the resultant pressure value is stored in m_CachedData. Its datatype is float.

        m_Pressure = ((UINT32)DataBuffer[0] << 16) | ((UINT32)DataBuffer[1] << 8) | (UINT32)DataBuffer[2];
        TraceInformation("m_Pressure value before 2's complement %x", m_Pressure);
        TwosComplement(&m_Pressure, 24);
        TraceInformation("m_Pressure value after 2's complement %x", m_Pressure);
        TraceInformation("m_Pressure value after 2's complement (in float) %f", m_Pressure);
        m_Pressuresc = (float)m_Pressure / SCALE_FACTOR;
        TraceInformation("m_Pressuresc value = %f",m_Pressuresc);
        m_Pressurecomp = m_c00 + m_Pressuresc * (m_c10 + m_Pressuresc * (m_c20 + m_Pressuresc * m_c30)) + m_tempsc * m_c01 + m_tempsc * 
        m_Pressuresc * (m_c11 + m_Pressuresc * m_c21);
        TraceInformation("m_Pressurecomp value = %f",m_Pressurecomp);
        //m_CachedData = m_Pressurecomp/100;                            // This is the actual conversion
        m_CachedData = m_Pressurecomp/100000;                        
        TraceError("Calculated pressure %f", m_CachedData);

    From application: BarometerReading is a class. Pressure value from driver is retrieved using its method GetCurrentReading().

    void Scenario2_Polling::ScenarioGetData(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    if (nullptr != sensor)
    BarometerReading^ reading = sensor->GetCurrentReading();
    if (nullptr != reading)
    ScenarioOutput_hPa->Text = reading->StationPressureInHectopascals.ToString();
    rootPage->NotifyUser("No barometer found", NotifyType::ErrorMessage);

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,348

    OK, but where is the spec that tells you what units you need to store in m_CachedData? Does the hardware deliver Pa?

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.


    DPS310 datasheet is referred.

  • MBond2MBond2 Member Posts: 466

    you clearly have some kind of data type or unit conversion problem. careful review of all declarations and interface contracts is how to find a problem like this. Code snips without the declarations and links to large documents don't help much. But on thing to consider is an expression like this

    m_Pressure = ((UINT32)DataBuffer[0] << 16) | ((UINT32)DataBuffer[1] << 8) | (UINT32)DataBuffer[2];

    I spend most of my time reviewing code written by others and this is the sort of thing that I routinely insist is rewritten. Not because it produces the wrong result necessarily, but because it requires a detailed analysis of the operator associativity and precedence of each part to determine exactly what it means. And an equivalent sequence that is unambiguous will produce the same machine code.

    please feel free to ignore my ranting on this point

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 12 September 2022 Live, Online
Internals & Software Drivers 23 October 2022 Live, Online
Kernel Debugging 14 November 2022 Live, Online
Developing Minifilters 5 December 2022 Live, Online