Evaluating I2C to connect Sensirion SHT31 to nRF5340DK no output to console (monitor)

Hi could you provide any insight on the following issue:

Source code in main.c

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <stdio.h>

#define SLEEP_TIME_MS 1000

int main(void)
{
        while(1)
        {
                printf("Hello World!\n");
                k_msleep(SLEEP_TIME_MS);
        }
        return 0;
}
If this code is built and flashed to the nRF5340DK the output is visible in the console (monitor) when the prj.conf file is blank.
If prj.conf is edited to include CONFIG_I2C=y following a pristine build and flash no output is visible in the console.
I am using V2.6.1 toolchain and have tried it in both Windows 11 and Debian Linux using nrf Connect.
This is the first time I have submitted a query and I hope I have provided sufficient information.
My intention is to use the samples/sensor/sht3xd example but without output to the console I am unable to make progress.
Thanks
Parents Reply Children
  • Hi Edvin

    Thanks for your prompt response. 

    I made no changes to dts files for the board, no changes in menuconfig and I have no overlay file in my hello_world project. I will .zip the folder as requested but can you clarify if you just need the files that I created or do you require the build folder included in the zip as this will obviously make it quite large.

    I have succeeded in getting a modified version of the sample sht3xd working for an nrf5340dk board with an sht31 sensor attached to the default I2C pins (SCL to P1.03 SDA to P1.02) and including an nrf5340dk_nrf5340_cpuapp.overaly file in the boards folder (file content below). 

    For 'add build configuration' I selected the nrf5340dk_nrf5340_cpuapp.

    The temp and humidity readings appear in the console.

    I also included an nrf5340dk_nrf5340_cpuapp_dk file in the boards folder with exactly the same code. When I remove the build configuration and create a new one using nrf5340dk_nrf5340_cpuapp_dk it builds OK but when flashed to the board nothing appears in the console.

    nrf5340dk_nrf5340_cpuapp.overaly

    &i2c1 {
    sht31: sht3xd@44 {
    compatible = "sensirion,sht3xd";
    reg = <0x44>;
    label = "SHT31";
    };
    };

    I notice that in the sht3xd sample none of the boards in the boards folder include an NS version. Is this a clue?

    Many thanks for you help.

    Seán

     

  • You can read about the difference between nrf5340dk_nrf5340_cpuapp and nrf5340dk_nrf5340_cpuapp_ns here. The main difference is that there are security features enabled when you are building for the *_ns. This means that if you want to use a particular peripheral from there, you need to assign it for that partition. 

    The main feature here is to make the device more secure. By splitting your application into two, you can have one part handling most of your application logic, and one part handling the important peripherals. 

    One example would be if you had an application controlling an elevator (or a set of elevators). Then you could have the main part of the application handling buttons, and controlling lights and doors, and communication between the elevators, but then you could have the secure partition being in charge of motor control. This means that if an attacker would be able to hack your device, he could push the buttons, close the doors and turn off the light, but he will not be able to tell it to crash into the basement.

    But if this is not something you are using, you should build for the board that does not end with _ns. This is the part that by default has access to all the peripherals.

    Best regards,

    Edvin

  • Hi Edwin,

    I had briefly read the documentation regarding security. I will study it in more detail in light of what you say. However I was influenced to use the *_ns version in light of the warning message that appears in the Add Build Configuration when a non ns buard is selected vis:-

    "You are going to build without Cortex-M Security extensions. Consider selecting the _ns board target ......"

    Based on this message I assumed, perhaps wrongly, that the _ns board should be used in all circumstances.

    For the benefit of anybody who may be interested I have put the working code for the nrf5340dk using the sht31 sensor on github here:-

    https://github.com/skealy/sht31

    Please note however based on the above advice to use the nrf5340dk_nrf5340_cpuapp board and not the nrf5340dk_nrf5340_cpuapp_ns which is also included in the boards folder.

    Thanks for your help and for responding so promptly.

    Regards

    Seán

Related