From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8B16C433B4 for ; Wed, 21 Apr 2021 23:08:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BABBF61404 for ; Wed, 21 Apr 2021 23:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343624AbhDUXJU (ORCPT ); Wed, 21 Apr 2021 19:09:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234826AbhDUXJT (ORCPT ); Wed, 21 Apr 2021 19:09:19 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777D5C06174A for ; Wed, 21 Apr 2021 16:08:45 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id x19so38827367lfa.2 for ; Wed, 21 Apr 2021 16:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ihwBbr0wDU/pkGia8qTBJOVfFxizBeK/hnkFTc8CCWU=; b=IZ3haLM5tJgi14Jfg0jJ1v5/78eVhgD8eIYJUrR9Izelrt74oysMKCUZZLkwfJo5oF TV3VkBNz1mJ/1bePKD+xFSmIUYZP4B/qVg/n4GSkyARswtHbOWvFkiqg5WRNl1Pq5rnT gd0sHo1zYzyORfqIbFghSzcX7RqDUNmKaErsomEZ1aUxcC2+CQ20SeA5IYQ1jmt2sICi D/3//l0flWRzR7DdvSbmYWTZO8xfO5dPSbTiU0YQjCpqtkAkSuBKWz/Z7Nnq1Guws7ik w9fVyVM456cSTZVssMxCnDz3sRxLlsObrr3w0nGRNyIC5JkJBM1Y5ZqnvaT+MONX8S+I Kc1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ihwBbr0wDU/pkGia8qTBJOVfFxizBeK/hnkFTc8CCWU=; b=joZzhsmWVfDqYkmT4QWgZ7AOEbCaKV0Zf5R3f5Rh/ORWHPHjkWpxfsZLjAOo9Wzfjo saDF2YPQINdkaBLeE6JPwXNgUkVuxpOuMG/mrXcPr9UEx3r5FRdLUuF61PFp+uZTd6tX jIn3gjNJ43U+c5qaYtWwKCbD+hYys2l1XJ1W1Y0Gv+dP6iF0pPyxtHdvtMdnCKOlvJ7i 51Pj0uibhS8Jq0iHKBhO50nEnTQCuAg2gdPGLc2HZL3/6x4h7YB80cOpXSuPo5p0F5RA ZnAJ5zO1Qe9SpLhMEnxS9CfmmF1B3mVVDiITz51VJ0AwdGrLRU6dbKOumXdKBZsLAe9P b67w== X-Gm-Message-State: AOAM530Mjy11pXvWGvQKn/szUUpFESRot5/r4Ad8xpXeANqIyL48v/Qw /Q0SEXmRS0JYmQodhqW3b9Z1Pwu3QrP/AG0sUSxqe5R0B90= X-Google-Smtp-Source: ABdhPJw6QtkcxmWSpbyIuuNgpDxk4vNzZQHC4Ez36jv/K20KJUzmzZ9d+mZdRDzjwhY8fJLVEZFGhEIo+t3auUc5w+A= X-Received: by 2002:a05:6512:3a85:: with SMTP id q5mr347706lfu.465.1619046151567; Wed, 21 Apr 2021 16:02:31 -0700 (PDT) MIME-Version: 1.0 References: <483ac17b-705a-38c3-54ee-7f0089262c03@gmail.com> In-Reply-To: From: Linus Walleij Date: Thu, 22 Apr 2021 01:02:20 +0200 Message-ID: Subject: Re: BUG: iio: mpu3050: Wrong temperature scale To: Lars-Peter Clausen Cc: Andy Shevchenko , Dmitry Osipenko , Jonathan Cameron , "linux-iio@vger.kernel.org" , Linux Kernel Mailing List , Svyatoslav Ryhel , Nathan Royer , Jean-Baptiste Maneyrol Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 21, 2021 at 10:00 PM Lars-Peter Clausen wrote= : > On 4/21/21 9:41 PM, Andy Shevchenko wrote: > > On Wed, Apr 21, 2021 at 10:05 PM Andy Shevchenko > > wrote: > >> On Wed, Apr 21, 2021 at 1:14 PM Linus Walleij wrote: > >>> On Tue, Apr 20, 2021 at 11:26 PM Dmitry Osipenko w= rote: > >>> > >>>> I found a non-kernel example > >>>> which uses a similar equation [1], but in a different form. The main > >>>> difference is that the Arduino code interprets a raw temperature val= ue > >>>> as a signed integer, while upstream assumes it's unsigned. > >>>> > >>>> [1] > >>>> https://github.com/blaisejarrett/Arduino-Lib.MPU3050/blob/master/MPU= 3050lib.cpp#L111 > >>> Oh that's nice. Room temperature as mentioned is 20 deg C > >>> I think? > >>> > >>> The divide by 280 part seems coherent in all examples. > >>> > >>>> Still, even if assume that the raw temperature is a signed s16 value= , it > >>>> gives us ~35C in a result, which should be off by ~10C. > >> Actually here [1] it says in chapter 3.1 that room temperature is 35= =C2=B0C. > >> > >> Range: -30=C2=B0C .. +85=C2=B0C > >> Sensitivity: 280 LSB/=C2=B0C > >> Room temperature offset: 35=C2=B0C =3D -13200 LSB > >> > >> [1]: https://www.cdiweb.com/datasheets/invensense/mpu-3000a.pdf Oh nice find! > > So, if I'm reading this and the register description right the value > > is in the range > > -32768..32767. > > -13200 defines 35=C2=B0C > > > > 50000 as mentioned by Dmitry is actually -15536. So, it means that the > > more negative a value is the higher temperature is shown. > > > > Since it's linearized scale, now we can see that > > > > (13200 -15536)/280 + 35 gives us 26.66. > > > > Does it make sense? > (13200 + x)/280 + 35 =3D (23000 + x)/280, which is what is in the driver. > So the only bit missing is the cast to s16. Yup there is the bug. (I am guilty.) Dmitry will you test & send a patch? Yours, Linus Walleij