nrf52805 sample simple I2C

Is there any simple sample application utilizing i2c communications for nrf52805?

In Visual Studio Code with installed nrf connect SDK 2.0.0 doesn't show up any code sample.

Googling I came up with twi_scanner and a couple more of them, but I can't find them.

I found in the forum a tw_scanner.zip file, but still I face a hard time to wire up the configuration to make include files accessible (none of #include "boards.h", #include "app_util_platform.h", #include "app_error.h", #include "nrf_drv_twi.h") are found, although in a subdirectory it shows up that it is available for pca10040 and I have this DK and try to program an external board with nrf52805 (I managed to flash other bleutooth projects).

  • Hi

    We actually have two different SDK-s, one new and one old. See the nRF Connect SDK and nRF5 SDK statement for more information on this.

    For nRF Connect SDK, I recommend that you have a look at https://academy.nordicsemi.com/, where we have tutorials on getting started and some protocols, such as I2C.

    Regards,
    Sigurd Hellesvik

  • Dear Mr. Hellesvik,

    I followed your suggestion and studied the tutorial.

    Unfortunately, I can't still communicate with ADS7142,

    In my board, SDA is on P0.16 and SCL on P0.12.

    I added in the overlay file the following:

    &pinctrl {
    	i2c0_default: i2c0_default {
    		group1 {
    			psels = <NRF_PSEL(TWIM_SDA, 0, 16)>,
    				<NRF_PSEL(TWIM_SCL, 0, 12)>;
    		};
    	};
    
    	i2c0_sleep: i2c0_sleep {
    		group1 {
    			psels = <NRF_PSEL(TWIM_SDA, 0, 16)>,
    				<NRF_PSEL(TWIM_SCL, 0, 12)>;
    			low-power-enable;
    		};
    	};
    
    	spi0_default: spi0_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 29)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 31)>,
    				<NRF_PSEL(SPIM_MISO, 0, 30)>;
    		};
    	};
    };
    &i2c0 {
        pinctrl-0 = <&i2c0_default>;
        pinctrl-1 = <&i2c0_sleep>;
        pinctrl-names = "default", "sleep";
        ads7142: ads7142@18{
            status = "okay";
            compatible = "i2c-device";
            reg = < 0x18 >;
            label = "ADS7142";
        };
     };
    Then I followed the tutorial and have the following in the main.c:
    #define ADS7142_CHANNEL_CFG 0x24
    #define ADS7142_OPMODE_CFG 0x1C
    
    #define ADS7142_NODE DT_NODELABEL(ads7142)
    ...
    void main(void){
        static  struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(ADS7142_NODE);
        uint8_t i2c_write_reg2[3]={0b00001000,ADS7142_CHANNEL_CFG,0x00};
        ...
        if (!device_is_ready(dev_i2c.bus)) {
    		printk("I2C bus %s is not ready!\n\r",dev_i2c.bus->name);
    		return;
    	}
    	...
    	ret =i2c_write_dt(&dev_i2c,i2c_write_reg2, sizeof(i2c_write_reg2));
    	...
    	
    	}
    
    Off course I had enabled I2C in prj.conf, but I cannot manage to communicate properly.
    TI manual for ADS7142 specifies the following sequence of bytes to write to a register:
    I supposed that the first byte is automatically generated by the i2c_write_dt, but I had also tried to send all 4 bytes, again with no success.
     
    Any idea?
  • Hi

    It is helpful to know if the nRF chip sends data or just tries.

    Try to connect a logic analyzer or oscilloscope to the I2C lines and see if you can detect signals when sending data

    Regards,
    Sigurd Hellesvik

  • Just a question.

    I implemented logging and I saw the following error message:

    [00:00:05.004,547] <err> i2c_nrfx_twi: Error 0x0BAE0001 occurred for message 0

    How can I interpret this error?

  • Forget the last message, I managed out from nrfx_error.h that this is an address NACK, i.e. the slave address is not acknowledged.

Related