Menu

decimal point sums

2017-03-19
2019-07-18
<< < 1 2 3 4 5 > >> (Page 2 of 5)
  • Anobium

    Anobium - 2017-10-03

    Ping me on Google Chat. I have questions.... lots

     
  • Anobium

    Anobium - 2017-10-03

    Connected MCP2221 I2C/SMBus Terminal.

    Ran the 'Start scan' with Xpress Board attached for address range 0xe0 to 0xff

    > VID and PID reinitialized.
    VID: 0x4D8, PID: 0xDD
    > Bus scan started. 8 bit address used. Start address = 0xE0, End address = 0xFF
    Slave found. 8 bit address = 0xEC; 7 bit address = 0x76 Write
    Slave found. 8 bit address = 0xED; 7 bit address = 0x76 Read
    Bus scan finished
    

    Then, used to send write and read commands to device.
    Looks like the device it is working.

    > I2C Write, Address = EC, Data: AA Delay = 0
    OK
    > I2C Read, Address = ED, Read 32 bytes, Delay = 0
    OK
    < 00 00 33 00 00 C0 00 54 00 00 00 00 60 02 00 01 FF EF 1F 60 03 00 00 00 00 FF 00 00 00 00 00 00 
    

    Now, another day, over to Great Cow BASIC to initialise, read the temperature and the pressure.

     
    • Anobium

      Anobium - 2017-10-04

      Another day has started. Just grabbed the datasheet and the IDE.

      The device provided is a BME280 not a BMP280. How do I know this? I have created the start of a library and the ID register is returning 0x60. A BME280.

      I have also been able to display the T and P registers, as follows:

      Start BME280 Program
      dig_T = 28024,26488,50
      dig_P = 38653,54836,208,30,255,255,48,209,0
      Register 0xD0 'id': 0x60
      

      This is now just a slog to create a working library. This library needs to have methods according to the datasheet.

      BME280_GetTemperature
      BME280_GetHumidity
      BME280_GetPressure
      BME280_GetID
      BME280_SoftReset
      BME280_GetStatus
      BME280_ReadData
      BME280_ReadByte
      BME280_GetConfig
      BME280_GetCtrlMeasurement
      BME280_GetCtrlHumidity
      BME280_ReadCalibrationParams
      BME280_ReadMeasurements
      BME280_SetOversamplingPressure
      BME280_SetOversamplingTemperature
      BME280_SetOversamplingHumidity
      BME280_SetOversamplingMode
      BME280_SetFilterCoefficient
      BME280_SetStandbyTime
      BME280_IsMeasuring
      

      :-)

       

      Last edit: Anobium 2017-10-04
  • David Thompson

    David Thompson - 2017-10-11

    I'm struggling with the BME280 SPI. Needless to say it works faultlessly on the Arduino!!!
    I've tried all manner of permutations for SPI. I know it has clock leading edge descending and have set it accordingly. On the bright side I'm getting very good with GCB SPI :-)
    I'm going to put the data analyser onto it tomorrow so I can see what's happening.

     
  • stan cartwright

    stan cartwright - 2017-10-11

    My original post was really about converting arduino c code using float to GCB.
    David seems to be doing that, ie converting arduino code and like me finding it not easy.
    Not everyone can make sense of data sheets so get another hobby?
    Instead of Anobium researching devices, how about someone doing a help on converting arduino c to GCB ? With GCB's increasing support for AVR it would be handy IMO.
    No one thought my picaxe to gcb a good idea either :)

     
  • David Stephenson

    I soldered up a BMP280 several months ago, but when I looked through the datasheet I just gave up. The amount of calculation required to get a pressure reading is a problem (has anybody solved it?)
    I've gone back to using LPS22 pressure sensors their drawback is that they are extremely difficult to hand solder (at least for me), but the pressure calculation is easy.
    For humidity I have found the Si7006 works as good as any other and comes with a filter (it is very easy to contaminate the sensor).

     
  • Anobium

    Anobium - 2017-10-13

    See https://sourceforge.net/p/gcbasic/discussion/579125/thread/df78cd39/#8b7d/d5a1/ceed

    When I get time I will sort the library as shown in the post - the need for decimal is not a requirement as we can handle within the library.

     
  • stan cartwright

    stan cartwright - 2017-10-13

    Hi David, I got arduino code for VL53L0X time of flight IR laser distance measure device.
    I tried to convert it to GCB but gave up. Like a lot of interesting devices it's rocket science to set up :)
    I'm still learning how to get most out of GCB and finding ideas tricky to implement and not knowing c wonder if things that I think hard to imlement in GCB might be a feature/function in c that's not possible in GCB but I'm not qualified to say yet.
    Anyway..we confuse ourselves voluntarily.

     
  • David Thompson

    David Thompson - 2017-10-14

    I love my Logic Analyser :-) I've had it a while, nothing special a clone FX2 running Sigrok PulseView. I've not used it seriously until now so it's taken me a while to figure out what's happening. After many hours of fruitlessly searching code, I modified the Arduino Code so it just keeps repeating the request for an ID and initial configuration. Found it yahoo. The data is sent in 1 word blocks (16 bits) also Clk is normal. i.e. CPOL and CPHA both 0. Changing the clock modes doesn't seem to make any difference.
    Tried it on the 16F887 with GCB, even bigger YAHOO, I'm getting the ID back!!!!!!

    The structure of the data/conf in each word is (to me) a bit odd, to a seasoned programmer it may seem OK. Now I'm hopeful of getting somewhere now.
    Just checked the 16f887/GCB output, it's in bytes, but the structure is the same.
    i.e. 2 bytes joined are the same as 1 word

    The calculations do look a bit grim David S and Stan but that's for later and is also where I chipped into this thread about Precision Floating Point.

    Anobium reckons he can do that. "What! I never said that" lol. I'll have a go too when I get there.
    I can do math, I'm just not very keen.

    This chip is bugging me now so I'm determined to get it working. Like Anobium said somewhere, after trying to decipher Arduino code you sort of start to slowly learn C by beiing infused. I also have a compiler that supports SingleFP so if I can get that to work with the BME280 as well, I've got another experimentation tool.

    If I succeed I will post the finished code, hope you're not to old by then ;-)

     

    Last edit: David Thompson 2017-10-14
  • stan cartwright

    stan cartwright - 2017-10-14

    Anobium's optimistic opinion of users capabilities :)
    I can get devices to work by copy/paste arduino code but I couldn't write that code myself..in any programming language. Even arduino users have problems with some devices it seems.
    Floats are "easy to simulate,just scale everything up..and down" Yes, a doddle. Well...if you say so..not really.

     
  • David Thompson

    David Thompson - 2017-10-15

    Quite so Stan you just need to use the "right" numbers ;-) The left ones don't work, or is it the ones left.

    That's where I am with Arduino, once you get past the "Do everything for you" code, it's a bit of a monster. I can almost understand some of it. but write a program? Hahaha

     
  • David Thompson

    David Thompson - 2017-10-16

    Update. In one day I've gone from totally confused to fully enlightened.
    I can now configure, read configuration and read Pressure, Temp and Humidity.
    If I apply a little heat to the BME280, the Temp read out changes and the other two vary slightly.
    So it looks like I can extract data, now down to the math :-(

    Ah yes FYI the odd structure I mentioned above is simply the RX data being delayed by one byte.
    So RegAdd into TX buffer & out, data from RegAdd into RX buffer, not sent until the next Tx "pushes" the RX out. Hope that makes sense.

     
  • mmotte

    mmotte - 2017-10-16

    David,
    I had some time yesterday and worked on your project. Made a proto board with a plugin socket , voltage reg for 3.3v and voltage translators for clk,data.
    Had two BME280 s and they both got hot . Bad day in the Lab!

    Had a BMP280 which worked. This program reads 6 consecutive registers starting with F7

    The Atached program can be modified by adding two more registers and two more reads for the BME280. Only the last read should have the nack, which signals the end of the read.

    GL
    Mike

     
  • mmotte

    mmotte - 2017-10-16

    David,
    Here is how to convert the 3 bytes of Press and temperature to a long

    dim Temp , Press as long
    
    ' convert to one long from 3 bytes
             ' lowb = workvariable
              ' highb = workvariable_H
             'upperb = workvariable_U
              'lastb = workvariable_E
             Press   = P_xlsb
             Press_H = P_lsb
             Press_U = P_msb
    
             HSerprint "Press = "
             HSerPrint Press
             HSerPrintCRLF
    
             Temp   = t_xlsb
             Temp_H = t_lsb
             Temp_U = t_msb
    
             HSerPrint "Temp = "
             HSerPrint Temp
             HSerPrintCRLF
    

    EDIT'ed Actually this is wrong because xlsb is only 4 bits (7..4). This needs more work. Maybe shifted right 4?

    Sorry
    Mike

     

    Last edit: mmotte 2017-10-16
  • David Thompson

    David Thompson - 2017-10-16

    Interesting.
    The i2c BME I had died, so I switched to SPI. I've just got to about the same position as you.
    I hadn't noticed that .xlsb was reading bits 4-7 as 0-3, will need adjustment unless "Filter" is turned off then .xlsb for Temp and Press = 0 i.e.16 bit resolution not 20. If needed, as you say shift right or divide by 16.

    At the minute I have all data for temp, press and hum in 2 x Long (32 bit) and 1 x Word waiting for further processing.
    I had a hot 3.3v regulator again, my fault, I'd crossed 5V and Gnd on the breadB while changing between Arduino and 16F887.

    I've figured out what is mearnt by burst mode for SPI anyway, One SPI CS OFF followed by all the registers and variable names then one SPI CS ON. I'm using a Digital Analyser now so I can see what's happening, makes life much easier. This method doesn't work for the configuration.

    I've been looking at the stored calibration data format. It's either signed or unsigned integers and there are 16 bit and 8 bit ones. They are stored in 2s compliment, so I need to dust off the "how to convert from 2s Comp into real numbers program", I've done it before, so at least it's not new ground.

    What is your math like? If you want to make this a joint project, it might be an idea to split the calculations. I've been looking initially at Temp. I'm not overly bothered about Pressure so I would have done that last.
    Like most Data Sheets the more i read them the more they make sense. By the time it's well dog eared enlightenment should be with me ;-)

    Do you want to see my BME SPI code? It's on a different computer otherwise I'd just attach it now.

     

    Last edit: David Thompson 2017-10-16
    • Anobium

      Anobium - 2017-10-16

      For two complement - look at the DS18B20 code. Shows you how to do this.

      Attaching the library, see attached, I was developing with some example code show below - this exposes the following methods.. the rest is chip specific or serial setup.

      BMP280_GetID
      BMP280_GetStatus
      BMP280_GetCtrlMeasurement
      BMP280_GetCtrlHumidity
      BMP280_GetConfig

      ;----- Configuration
          'Chip Settings.
          #chip 16f18855,32
          #option explicit
          #config RSTOSC_HFINT32
      
      
          'Generated by PIC PPS Tool for Great Cow Basic
          'PPS Tool version: 0.0.5.2
          'PinManager data: 09/02/2017
          '
          'Template comment at the start of the config file
          '
          #startup InitPPS, 85
      
          Sub InitPPS
              UNLOCKPPS
      
                  'Module: EUSART
                  RC0PPS = 0x0010    'TX > RC0
                  TXPPS = 0x0008    'RC0 > TX (bi-directional)
                  'Module: MSSP1
                  SSP1DATPPS = 0x0013    'RC3 > SDA1
                  RC3PPS = 0x0015    'SDA1 > RC3 (bi-directional)
                  RC4PPS = 0x0014    'SCL1 > RC4
                  SSP1CLKPPS = 0x0014    'RC4 > SCL1 (bi-directional)
      
              LOCKPPS
          End Sub
          'Template comment at the end of the config file
      
          '' -------------------LATA-----------------
          '' Bit#:  -7---6---5---4---3---2---1---0---
          '' LED:   ---------------|D5 |D4 |D3 |D1 |-
          ''-----------------------------------------
          ''
          #define LEDD2 PORTA.0
          #define LEDD3 PORTA.1
          #define LEDD4 PORTA.2
          #define LEDD5 PORTA.3
      
      
          Dir     LEDD2 OUT
          Dir     LEDD3 OUT
          Dir     LEDD4 OUT
          Dir     LEDD5 OUT
      
          #define SWITCH_DOWN         0
          #define SWITCH_UP           1
      
          #define SWITCH      PORTA.5
      
      '***** Everything above here is chip and board specific *****
      
          'Define serial
          #define USART_BAUD_RATE 9600
          #define USART_TX_BLOCKING
          #define USART_DELAY 1 ms
      
      
          'Define BMP library Constants etc
          #include "BMP280.h"                           'include BMP library
          #define BMP280_I2C_ADDRESS  0xEC              'BMP085 device address
          #define BMP280_Debug                          'enable serial debug - to be removed
      
      ; ----- Define Hardware settings for hwi2c
          ' Define I2C settings
          #define HI2C_BAUD_RATE 400
          'I2C pins need to be input for SSP module
          #define HI2C_DATA PORTC.3
          #define HI2C_CLOCK PORTC.4
          Dir HI2C_DATA in
          Dir HI2C_CLOCK in
          HI2CMode Master
      
      ; ----- Main body of program commences here.
      
          wait 100 ms
      
          #ifdef BMP280_Debug
            hserprintcrlf
            hserprint "Start BME280 Program":hserprintcrlf
          #endif
      
          #ifdef  BMP280_Debug
            HSerSend 9: HSerPrint "Register 0xD0 'id'   : 0x"+hex(BMP280_GetID): HSerPrintCRLF
            HSerSend 9: HSerPrint "Device Status        : 0x"+hex(BMP280_GetStatus): HSerPrintCRLF
            HSerSend 9: HSerPrint "Get Control Measure  : 0b"+ ByteToBin(BMP280_GetCtrlMeasurement): HSerPrintCRLF
            HSerSend 9: HSerPrint "Get Control Humidity : 0b"+ ByteToBin(BMP280_GetCtrlHumidity): HSerPrintCRLF
            HSerSend 9: HSerPrint "Get Config           : 0b"+ ByteToBin(BMP280_GetConfig): HSerPrintCRLF
          #endif
      
          wait 100 ms
      
      end
      
       
  • David Thompson

    David Thompson - 2017-10-16

    Thanks Anobium, that's where I saw it before DS18B20.

    Attached is my code to date if anyone wants to see how it's progressing.

    I've tried to use the same variable names (or very similar) as in the DS, makes it easier to remember when scouring the DS for more info.

    Just looked at BMP280.h, I'm assuming this is an "include" type of file. Looks good but a bit too clever for me :-) In other words I don't understand how it works.

     

    Last edit: David Thompson 2017-10-16
  • mmotte

    mmotte - 2017-10-17

    David,

    I was looking at your code and your at about the same spot in developement just like you said.

    I think that you have your byte order of the long wrong.
    You have:

    HWSPITransfer 0xf7, xx 'Start reading data send 0xf7 + No rx
    HWSPITransfer 0xf8, press_H 'f8 out f7 in
    HWSPITransfer 0xf9, press  'f9 out f8 in
    HWSPITransfer 0xfa, press_U '0xfa out 0xf9 in xlsb = _U  Note press_xlsb is bits 4 to 7
    

    F7 -> Press_H
    F8 -> Press
    F9 -> Press_U

    It should be:

     ' convert to one long from 3 bytes
     '   this is how GCB defines a 32 bit long into bytes
             ' lowb = workvariable
              ' highb = workvariable_H
             'upperb = workvariable_U
              'lastb = workvariable_E
             Press   = P_xlsb
             Press_H = P_lsb
             Press_U = P_msb
    

    F7 -> Press_U .....msb
    F8 -> Press_H .....lsb
    F9 -> Press ....xlsb

    BR
    Mike

     
  • David Thompson

    David Thompson - 2017-10-17

    Arrgh the page has just crashed again for the 2nd time so here's the short version.
    Are you sure Mike? I can't see how xlsb would be the 1st byte and lsb/msb the 2nd and 3rd.
    Dim workvariable as word
    workvariable = 21845
    Dim lowb as byte
    Dim highb as byte
    Dim upperb as byte
    Dim lastb as byte

    I did not use an intermediate variable
    
    lowb = workvariable         = Press 1st byte @ F8      would be Press_lsb 
    highb = workvariable_H   = Press_H 2nd byte @ F7     would be Press_msb
    upperb = workvariable_U = Press_U 3rd byte @ F9      would be Press_xlsb
    lastb = workvariable_E     = Press_E but not used    would be Press_xmsb
    
    Update:
    I've now programmed collection all of the calibration data whichs seems to work fine.
    So now it's number crunching time.
    
    Before I start I have a question.
    

    The calibration data is in 2s compliment signed and unsigned mainly 12 bit Words. I assume the temp, pressure and humidiy is just binary. 16 and 20 bits
    Is it better to convert 2s C into standard binary then do the calculations or convert the Temp,Pres,Hum data into 2s C and then do the calculation before converting the answer into decimal?
    FYI
    A few times I've had zero return from the BME, looks like some sort of loading issue on MISO.
    If I disconnect MISO to the PIC, the digital analyser sees a MISO output. If I reconnect MISO to the PIC the analyser can still see the signal.

     

    Last edit: David Thompson 2017-10-17
  • mmotte

    mmotte - 2017-10-17

    David,
    I still think your F7,F8,F9 should be in that order in the "long" variable and then shifted right 4. Check out table 30 in section 5.4.8 and it describes the "xlsb" as bits 3:0.

    I also succeeded in reading the calibration data.

    Where in the .pdf does it say that the calibration data is in "2s compliment" ??. I haven't found it yet. I did see that the data is read as "little endian" with the lsb first and then the msb second.

    Today is a busy day and I won't have time till late afternoon to look at it again.

    GL
    Mike

     
  • David Stephenson

    I've managed to get a temperature reading out of a BMP280.
    I made a few assumptions about the signs of the calibration values (as mine seem almost the same as those in the datasheet). The value is stored in the variable TEMP as temperature*100.

     
  • David Thompson

    David Thompson - 2017-10-17

    Hi
    I'll respond to David S first. Thanks for your code, I've just had a lookl, why does everyone code differently to me? ;-) I can't understand how you read the Temperature data in Reg FA,FB,FC. Could you give me some pointers please? Which variables did you use for these? Also wrt Mike's comment above, how did you assign F7,F8 and F9? Or if you only did temperature 0xFA, 0xFB & 0xFC

    F7 F8 F9
    Mike, I haven't got a problem with being wrong on this, I just can't see your rational. If the Filter is set to OFF (16 bit) it loses 4 bits, if F9 was the lowest byte, the resolution range would only be
    0x000FFFFF vs 0x00FFFFF0

    If bits 7:4 were the start of the WORD i.e. to 3:0, there would be a gap in bits 7:4 so why show it as 3:0?
    F9 at the top gives 20 bits as 0x000FFFFF and 16 bits as 0x0000FFFF difference 000F0000
    F9 at the bottom 20 bits as 0x00FFFFF0 and 16 bits as 0x00FFFF00 difference 000000F0
    When resolution is changed it's the hi bits that come off.
    Table 29 & 30 states F9 & FC xlsb depend on resolution, not so the other 2

    I agree that showing bits 3:0 being at location 7:4 is odd but ......
    Did you notice that calib addr 0XE5 is split into 2? When I addressed it twice to retrieve data, I got 2 different values, so the BME handles it as 2 x 1 nibble addresses. Both are shown as being 3:0

    2s Compliment
    OK I'll swap 2s compliment for little endian :-) 2s compliment is mentioned in 4.2.2, 1st para, 3rd line.

    Strewth, no wonder Bosch reccommend using their API, I can't see where I can fit one to a PIC/AVR though, but in fairness their intended market is Mobile Phones.

     
  • David Stephenson

    Stan, yes they can be very accurate. I believe for weather forcasts the relevant thing is the amount of change in the last 3 hours (falling slowly and all that stuff). As for altitude the accuracy is such that on a good day they can detect less than a metre change in height. I too got mine from RS, but loose (849-6187) the LPS22 is cheaper and easier to code (111-6455). I have attached a picture of it on my homemade board.
    David T, I made a few compromises to cut down on the RAM. I only used 16-bits for the temperture (it is more than enough - ignore the xlsb and don't oversample the temperature). I am currently working on the pressure reading. There is some confusion in the datasheet - the pressure reading come out first. I also read the T calbration values to use in the equations 27075,26423,-1000.
    My coding is a bit erratic I have been doing it for a long time I started out with Fortran (on punched cards)

     
  • stan cartwright

    stan cartwright - 2017-10-17

    on a good day they can detect less than a metre change in height.

     
<< < 1 2 3 4 5 > >> (Page 2 of 5)

Log in to post a comment.