Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMP280 SPI on ATMEGA 645A reading bad data

    Highlighted
    New Poster

    BMP280 SPI on ATMEGA 645A reading bad data

    I am using version 3.3.4 of bmp280.h, bmp280.c, and bmp280_defs.h

    I am able to read my BMP280 chip ID, and also read out the calibration parameters, so I know that I am generally communicating with the BMP correctly.  My problem starts when trying to read bmp280_get_uncomp_data.  Taking the temperature portion for example,  when I try to sprint ucomp_data.uncomp_temp I get what appears to be a lot of zeros and random readings:

    0
    0
    524288
    313603
    792199
    606717
    458767
    812801
    0
    816

    ...etc.

    About half of the readings are zeros.  I have read out the t_fine value that is stored on the device just to make sure that I am reading a 32-bit number correctly.  t_fine always returns the same value of 57035.

    I don't know if the problem is that I am not reading MSB first, or if somehow I am reading the wrong location for  temperature data.  Any suggestions would be most welcome.  I have attached my main.c  for reference.  Please pardon all the commented-out code in main.c as I have been trying lots of things.

    Disclaimer: I do not write code for a living, so my apologies if I botched something obvious.

     

    2 REPLIES 2
    Highlighted
    New Poster

    Re: BMP280 SPI on ATMEGA 645A reading bad data

    Hi,

    Thanks for your inquiry.

    I checked and referenced your code to modify my code based on the same api and spi communication, it was working on my STM32 platform and could get correct ucomp_data.uncomp_temp.

    Please see the below log:

    [30]Enter BMP280 Task Loop!
    [33]Sensor ucomp_data.uncomp_temp: 524288
    [38]Temperature UT: 524288, T32: 2528, T: 25.284077
    [94]Sensor ucomp_data.uncomp_temp: 525536
    [98]Temperature UT: 525536, T32: 2568, T: 25.677198
    [154]Sensor ucomp_data.uncomp_temp: 525536
    [158]Temperature UT: 525536, T32: 2568, T: 25.677198
    [214]Sensor ucomp_data.uncomp_temp: 525536
    [218]Temperature UT: 525536, T32: 2568, T: 25.677198
    [274]Sensor ucomp_data.uncomp_temp: 525536
    [278]Temperature UT: 525536, T32: 2568, T: 25.677198
    [334]Sensor ucomp_data.uncomp_temp: 525536
    [338]Temperature UT: 525536, T32: 2568, T: 25.677198
    [394]Sensor ucomp_data.uncomp_temp: 525536
    [398]Temperature UT: 525536, T32: 2568, T: 25.677198
    [454]Sensor ucomp_data.uncomp_temp: 525536
    [458]Temperature UT: 525536, T32: 2568, T: 25.677198
    [514]Sensor ucomp_data.uncomp_temp: 525536
    [518]Temperature UT: 525536, T32: 2568, T: 25.677198
    [574]Sensor ucomp_data.uncomp_temp: 525520
    [578]Temperature UT: 525520, T32: 2567, T: 25.672158
    [634]Sensor ucomp_data.uncomp_temp: 525520
    [638]Temperature UT: 525520, T32: 2567, T: 25.672158

    Attachement is my sourcode based on STM32 platform.

    Based on your current code, I suggest that you check your spi communication , simplify your code and add some log to check whether to success initialization.

    if possible,  contact our local FAE, you will get more help.

    Thanks.

     

     

    Highlighted
    New Poster

    Re: BMP280 SPI on ATMEGA 645A reading bad data

    My problem was actually that I was using the wrong Chip Select line in hardware (connecting to a different pin on the processor).  The pin that I connected to the CS line of the BMP280 was always low.What threw me off is that I was able to get the chip ID back from calling bmp280_init(dev), since that is the first SPI comminication that takes place.  But because the CS line never went high again, all following communications to the chip were garbage.  

    Something to think about when troubleshooting.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist