7 Replies Latest reply on Sep 11, 2015 1:05 AM by llynch

    Setting up I2C to talk to pressure sensor on the BCM20737s



      I am looking to set my pressure sensor up which talks over I2C with a BCM20737S. Hardware wise i am ok.


      I am not familiar with the M0 libraries. How would you go about initializing the I2C? I need to set my SCL clock speed to 400KHz. My slave address is 0x21h. I do not need to write to the pressure sensor, only read. What is the best way to read incoming data?


      Any examples that could help?




        • 1. Re: Setting up I2C to talk to pressure sensor on the BCM20737s

          Have you taken a look at the I2C Temp Sensor example within the SDK: /WICED-Smart-SDK/Apps/i2c_temperature_sensor


          I will also ask jakewtorres to respond as he has alot of expertise working with the peripherals.

          • 2. Re: Setting up I2C to talk to pressure sensor on the BCM20737s

            I've attached example code to run the pressure sensor on the WICED sense kit. This is code taken out of the wiced_sense.c firmware and put into a readable format. Run traces on the firmware to see a print out of the atmospheric pressure, and temperature every one second.


            ***Please note that the address may need to be shifted. If you are having problems accessing the pressure sensor with this code, please toggle the SEVENTH bit of the 8 bit address listed in the .h file of the driver.



            • 3. Re: Setting up I2C to talk to pressure sensor on the BCM20737s

              Hello Jake,


              The pressure sensor I will be using is: http://www.meas-spec.com/downloads/MS4525DO.pdf and the link to the datasheet on the I2C: http://meas-spec.com/downloads/Interfacing_to_MEAS_Digital_Pressure_Modules.pdf


              Do you think it is just the cause of wiring the my pressure sensor up to the bcm92073x_le_kit, changing the slave address?




              • 4. Re: Setting up I2C to talk to pressure sensor on the BCM20737s

                I took a look at your datasheet and the code sample from Jake.  I don't think his comment about toggling the bit applies to your device.

                Your device is activated by a write command to device ID x28 with no additional address information and no data to send.

                Add one for a read (ID = x29).  When the device is ready to read it will raise a signal on the GPIO port.

                You can configure this port as an interrupt and write a simple interrupt handler to read the data,

                or if your device is quick, you can poll I a loop until the 'data ready' signal is observed on the port configured as a standard GPIO input.

                The interrupt method is preferred, but you can also poll on the fine timer if the device is slow.

                When the data is ready just do a i2c read (ID=x29) for the number of bytes (2, 3, or 4) you device will be providing.  Again address is zero and address bytes are zero (the device is not a memory chip which is where the address arguments are used).


                So something like this should work.

                #include "i2cm.h"


                i2cm_setSpeed( 60 ); // (24MHz / 60 = 400K)



                configure GPIO port for data ready signal


                // start the i2c device with a write

                UINT8 status;

                in a loop:

                    status = i2cm_write(dataAddr=0, dataSize=0, 0x28 );  // start device

                    exit when status is I2C_SUCCESS

                end loop


                Now poll for data ready or begin interrupt handler (depending on your design)

                #define dataLength = 4;

                UINT8 data[ dataLength ];

                in a loop:

                    status = i2cm_read(UINT8* data, dataLength, 0x28 + 1 );

                    exit when status = I2C_SUCCESS


                ble_trace1( 'i2c status = %d', status );


                Give it a try and see what happens.

                • 5. Re: Setting up I2C to talk to pressure sensor on the BCM20737s

                  My apologies, I was assuming that you were using a wiced sense kit. With a different pressure sensor, you will need a different driver entirely. You need to study the datasheet of the sensor you're using to know how to initialize the sensor and how to then poll data from that sensor. The initialization will be done by writing to control registers, and the polling of data will be done by reading from data registers.


                  See the driver of the app I attached in my last response. Copy the read and write functions at the top into your new driver. *change the slave address to match the new sensor and define i2c_read and i2c_write as is done in the old driver. Then import cfa.h.


                  These two function will be the basis of the entire driver. Now, if your initialization requires writing  the value 0x01 to control register 0xff then you can call the following function:


                       data = 0x01;

                       LPS25H_WriteReg(0xff, 1, &data);


                  Then if the data register of the sensor is 0xaa, then you can poll the data following initialization by calling this function:

                       UINT8 polled_data;

                       LPS25H_ReadReg(0xaa, 1, &polled_data);




                  • 6. Re: Setting up I2C to talk to pressure sensor on the BCM20737s

                    Note that if you are open to using SPI vs. I2C for this application, we include a sample App which uses the Measurement Specialties MS5525DSO pressure sensor.


                    * SPI Pressure Sensor Sample


                    * This application provides the sample code interfacing the MS5525DSO

                    * pressure sensor (http://www.meas-spec.com/product/pressure/MS5525DSO.aspx)

                    * over the SPI interface.  The application initializes the second SPI interface

                    * to communicate with the sensor to get calibration data then read the pressure

                    * and temperature which is displayed on the debug UART.  See application note

                    * http://www.amsys.de/sheets/amsys.de.an520_e.pdf on the calculation details.


                    * Features demonstrated

                    *  - Use of the SPI driver interface

                    *  - Reading data from MS5525DSO pressure sensor


                    * To demonstrate the app, work through the following steps.

                    * 1. Connect MS5525DSO pressure sensor to SPI interface

                    *    (Use P24 for CLK, P4 for MOSI and P25 for MISO)

                    * 2. Plug the WICED eval board into your computer

                    * 3. Build and download the application (to the WICED board)

                    * 4. Application reads pressure and temperature information from MS5525DSO

                    *    every second and prints it out to the debug output.

                    • 7. Re: Setting up I2C to talk to pressure sensor on the BCM20737s

                      Yes I had seen this, unfortunately the MOQ for this sensor is bigger then my requirement.