SPI (Serial Peripheral Interface) Part 2: Programming with Zephyr, nRF52840-DK and Bosch BME280

Поділитися
Вставка
  • Опубліковано 1 лип 2024
  • SPI (Serial Peripheral Interface) is a serial transmission protocol used for communication between microcontrollers and peripheral devices such as sensors, memories or displays. It is easy to implement and offers high transmission speed, making it a common choice for many embedded systems. In diesem Video programmieren wir SPI mit Zephyr. Wir benutzen als Hardware das Nordic nRF52840-DK und den Sensor Bosch BME280.
    You can support me at Patreon:
    / wsnandiot
    --Hardware-------
    nRF52840 DK:
    www.nordicsemi.com/Products/D...
    Adafruit BME280:
    www.adafruit.com/product/2652
    Sparkfun Logic Analyzer:
    www.sparkfun.com/products/18627
    --Software-------
    nRF Connect SDK:
    www.nordicsemi.com/Products/D...
    Logic Anlayzer PulseView:
    sigrok.org/wiki/PulseView
    00:00 Introduction
    01:50 Connect BME280 with nRF52840-DK
    06:00 Read out CHIP-ID
    15:44 Read out calibration register
    21:00 Set configuration register
    25:00 Read uncompensated sensor values
    27:40 Calculate compensated sensor values
    32:40 Using chip select from Zephyr device tree
    36:00 Outro
    #zephyr #bme280 #spi
  • Наука та технологія

КОМЕНТАРІ • 21

  • @xThirdOpsx
    @xThirdOpsx 3 місяці тому +1

    Thanks for putting this together.

  • @vigneshs6232
    @vigneshs6232 Рік тому +1

    Thankyou for your video....Really useful..do More Videos like these....

  • @winstonalf
    @winstonalf 10 місяців тому +1

    This was really helpful. Thank you very much !!!!

    • @wsniot
      @wsniot  10 місяців тому

      Thx for the positive feedback.

  • @mathicalee
    @mathicalee Рік тому +2

    Thanks a lot!! Going very deep, it's just what I always wanted!! 😆😆 I have some questions though.
    - The dummy address 0xff at the end, you had to use one which doesn't exist, right? Or doesn't it play a role because you don't read after 0xFF?.
    - You set once that you want to oversample 8x. Does the sensor measure the whole time even if you read the values only once per second? Or every minute? Or does the sensor sample data only every time you read? And if that so, does the sensor have enough time to measure things and sends back to the controller?
    - And I think the correction what you made with 0x7f was right what you said. Because the bitwise OR with 0x7f is setting the first bit to 0 and keeps every other bits.

    • @wsniot
      @wsniot  Рік тому +2

      1. Actually you can use any dummy value you want. But of course if it is a command what the peripheral understands like a register it will react. But since the CS line will be high again the communication ends. Mostly it is better sending just 0xFF or 0x00.
      2. In normal mode the sensor measures the hole time. It has a measurement cycle and the a standby time which can be maximum 1s, but if i see it right the default standby time is at 0.5ms (t_sb[2:0]). The maximmum measure with 8x oversampling is t_measure,max=58.175ms. So we get every 58,675ms a new measurement in the registers. For weather data 1x oversampling is actually enough. The measure time will be significantly smaller.
      3. Normaly you count a word in most significant bit order here (b_7 b_6 ... b_0). And then it is b_7 what you have to set to 0 and not b_0. Its always a question what is meant with the first bit.

  • @user-xp7pe7hv5z
    @user-xp7pe7hv5z 8 місяців тому

    Hi, thanks for this. One question, you don't set the read bit MSB of the register address. Is there a reason for this?

    • @wsniot
      @wsniot  8 місяців тому +1

      For a read instruction it is automatically set by the register macros. For write instructions I set the MSB of the register to zero with adding 0x7F(see 23:26).

  • @thanuha5059
    @thanuha5059 Рік тому

    We are trying to connect with lsm6dsl in our custom board which has nrf52840 through SPI. Can you point us to the right tutorial or video help resources since we are unable to communicate with the IC through the example code(is using i2c) and also unable to configure it to use SPI.

    • @wsniot
      @wsniot  Рік тому

      I would recomment you using for testing an Developerkit first. Try SPI with the BME280 like here and then try to implement the SPI-communication with your IMU. If this is working you adapt it with your custom board.

  • @dalangalit378
    @dalangalit378 Рік тому

    ❤️❤️

  • @jwalkerbg60
    @jwalkerbg60 10 місяців тому

    Hello, I did not realize, why did you not use spi_cfg.cs field? I saw that you toggle CS "manually". But why so, and not using the field .cs?

    • @wsniot
      @wsniot  10 місяців тому +2

      The explanation follows at about minute 31. This did not work with the BME280. After each command, the CS-Line was automatically set to disable again and the BME280 was deactivated before it could send the already prepared data.

    • @lukaspetrikas6320
      @lukaspetrikas6320 7 місяців тому

      @@wsniot I also have the same question. I have issues with the chip select when I am trying to use .cs
      Do I need to change anything in the device tree or project configuration if I want to use automatic chip select toggling instead of manual as it does not seem to work "out of the box" ?

  • @mayureshpitale2810
    @mayureshpitale2810 11 місяців тому

    we are trying to write and read data on EEPROM 93C46B using nrf52832 via SPI can you help me out with how I can send commands and data using the transrecieve function.

    • @wsniot
      @wsniot  11 місяців тому

      The spi_write and spi_read functions only call the spi_transceive function. With spi_write the rx_buffer is set to NULL and with spi_read the tx_buffer. With SPI, sending and receiving always take place simultaneously. If I want to receive and send at the same time, both buffers simply have to be defined.

    • @mayureshpitale2810
      @mayureshpitale2810 11 місяців тому

      @@wsniot which part of your video I should refer to so better understand this?

    • @wsniot
      @wsniot  11 місяців тому

      @@mayureshpitale2810 I dont get the point of your question? Do you have trouble understanding SPI or how to control the 93C46B ? You have to take a look in the datasheet from the 93C46B for the specific commands. SPI is not a 100% uniformly implemented standard. Always a good idea is also to test it with an arduino library first and using a logic analyzer for making the commands visible and then send the same commands with Zephyr.

    • @mayureshpitale2810
      @mayureshpitale2810 11 місяців тому

      @@wsniot I want to understand the part where we set the buffers for the spi_transceive function as I have trouble using that function. because I'm not able to set the values of the buffers as I want.

  • @user-yb9yr2wu8v
    @user-yb9yr2wu8v 3 місяці тому

    能不能配上中文字幕?

  • @user-yb9yr2wu8v
    @user-yb9yr2wu8v 14 днів тому

    没有中文字幕,看起来,太费劲了.