This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Tips on making a UART sensor driver for nRF9160

Hi.

I'm developing a sensor driver for the Spec Sensors DGS-O3 968-042 UART gas sensor for the nRF9160 (Thingy:91 to be precise)

The general gist of it is that I need to send a character command to the sensor, and get a sensor value in return with some additional information (I'm guessing around 1024 bits) through UART.

After looking around a bit online, I'm seeing a lot of different ways of going about this. I have a sense of some of the API commands that I can use through the Zephyr UART library, but there are some details that are unclear to me. Maybe some of you could help me out?

Some questions I have:

1. To what extent do I need to implement threading to maintain a relative low amount of power? Should I thread RX, TX or both?

2. What are the advantages of making it interrupt based vs. asyncronous? (I guess this is where polling comes in)

3. My sensor has a specific baudrate and UART settings. Should I use the uart_configure command to set up my sensor?

There are also some examples of how to implement UART for both Zephyr and the nRF9160, but I felt that none of them really made it clear what I should do:

Low Power UART: https://github.com/nrfconnect/sdk-nrf/tree/master/samples/peripheral/lpuart

UART RX sample: https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/uart/src/main.c

Old example for the pms7003: https://elixir.bootlin.com/zephyr/v1.11.0-rc1/source/drivers/sensor/pms7003/pms7003.c

If I get some clarity in how to best implement this, then I'll throw up some generic samples on my Github ;)

  • Hi, Patric!

    Thanks for reaching out!
    1. Power consumption is mostly tied to CPU activity, so whether you use threading or callbacks should not matter as long as you are well aware of what happens in your thread/callback. However, note that the standard serial implementation of Zephyr use an average of about 600uA. If that's to high I suggest using the Low-Power UART implementation. 
    2. They are very similar, but from what I know the asynchronous API is newer and more straightforward to use compared to the interrupt driven UART. 
    3. In Zephyr peripheral settings, like baudrate and TX/RX pins for UART, are configured before compilation. This is done through Device Tree overlay files, like the ones you can find in the board folder of the Low Power UART sample.

    I hope this answers some of your questions! For more examples of using UART in context you can also check out the central_uart and peripheral_uart bluetooth samples. While they aren't made for the nRF9160 I believe they give a good demonstration of how the UART can be used.


    Apologies for the delayed answer and thank you for your patience! 

    Best regards,
    Carl Richard

Related