Configuring 52832 for I2C slave mode using zephyr and VS code

Hello

I'm following the tutorial in the devacademy to learn how to use zephyr and VsCode.  I'm using an NRF52DK with the NRF52832 installed.  Within Lesson 6, I can configure the device to use I2C in master mode.  I've tested the code with a Sensirion temperature and humidity sensor and it works well.  

The problem I'm having is adapting this code and configuring the device as an I2C slave.  I found a blog online that walks the user through this but I cannot get past the first step of modifying the Prf.conf.  I get the squiggly line error on CONFIG_NRFX_TWIS0=y.    Here is the website: link

Anyway, I've tried to tweak the code in prj.conf, .overlay and main.c files but am unable to build the code.  Could someone please assist me with this issue?  I'm sure that I'm making a basic mistake somewhere but I have little direction at this point.

-Shawn   

  • Are you talking about configuring the MCU (nRF52832) as a slave or the sensor itself as a slave?

    If you want to configure the nRF52832 as a slave, modify your prj.cfg to the following:

    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y
    CONFIG_NRFX_TWIS0=y
    #the rest of your configurations

    Regarding the yellow squiggles, you need to build your project to enable it. But even if you're getting a yellow squiggle - it's a warning, not an error.

    If you're talking about the latter, the following configurations will do well:

    prj.cfg

    CONFIG_I2C=y
    CONFIG_LOGGING=y #In case you want to debug your code using log module and not printk

    Overlay:

    &i2cx {
    //status = "okay"; //This is if you're using a non-default node (so in i2c0 you don't need it)
        my_sensor: mysensor@0xaddress
        {
            compatible = "i2c-device";
            label = "YOUR_SENSOR_NAME_OR_ANYTHING_YOU_WANT";
            address = "0xaddress"; //The same value from the node configuration
        };
    
    };

    main.c or .c file of your driver:

    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/i2c.h>
    
    #define SENSOR_NODE	DT_NODELABEL(my_sensor)
    static const struct i2c_dt_spec dev = I2C_DT_SPEC_GET(SENSOR_NODE);
    
    /*
    *
    * The rest of your configurations
    *
    */
    
    //Usage:
    
    //Reading:
    uint8_t *buffer;
    ret = i2c_reg_read_byte_dt(&dev, REGISTER_ADDR, buffer);
    //Error handling code
    
    //Writing:
    uint8_t content = 0x69; //or any other value you wish to write
    ret = i2c_reg_write_byte_dt(&dev, REGISTER_ADDR, content);
    //Error handling code
    

    It would also be helpful to see your current project's code so that I can be more precise with my answer.

  • Thanks for your reply.  I'm attempting to configure the NRF52832 as a slave.  My project has a separate MCU acting as master. It will gather sensor data and provide it to the NRF52832.   

    Here is the warning I'm getting after pristine build.  How do I eliminate this warning?

    CONFIG_NRFX_TWIS0 was assigned the value y, but got the value n. Missing dependencies: n
     

  • Try to compile and run the project. Ignore it for now.

Related