I2C

Title: Issue with I2C (TWI) Communication on nRF52840 (SDK 16, Segger 8.2a)

Description:

I am working with the nRF52840 using nRF SDK 16 in Segger Embedded Studio 8.2a. As I am new to the SDK, I started with an I2C (TWI) scanner code to detect my sensor (HTU with address 0x40). However, I am facing an issue where no devices are detected.

Observations & Debugging Attempts:

Hardware Setup:

I am using P0.26 for SDA and P0.27 for SCL.

I have verified the connections, and the sensor is powered correctly.

Oscilloscope Observations:

When probing the SDA and SCL lines, both remain at 3.3V (high state).

There is no clock signal on the SCL line, meaning communication is not being initiated.

Software Modifications & Issues:

Initially, I encountered an error related to vprintf, which was resolved by removing the related file.

The program now compiles and flashes successfully, but no devices are detected during scanning.

Questions:

Why is the SCL line not toggling?

Do I need to configure any additional settings in sdk_config.h or modify my TWI initialization?

Are external pull-up resistors required on the SDA and SCL lines for proper operation?

Is there anything else I should check to establish proper I2C communication?

Any guidance on resolving this issue would be greatly appreciated.

  • Hi,

    First of all I would like to mention that if you are new to the SDK and that means that you are starting new development now, I would advice using the nRF Connect SDK instead of the old nRF5 SDK. See nRF Connect SDK and nRF5 SDK statement.

    When probing the SDA and SCL lines, both remain at 3.3V (high state).

    Can you disconnect the sensor and meaure on the pins directly just to verify that there is not an issue externally?

    Why is the SCL line not toggling?

    Good question. Can you share how you configure the pins so that we see that the correct pins are used? Are you using a custom board or the DK? If custom board, could it be that there is a soldering or some other routing issue? Do you have logging showing relevant information, and have you for instance cheked what is happening with a debugger?

    Do I need to configure any additional settings in sdk_config.h or modify my TWI initialization?

    Internall pull resistors are normally enough for lower speeds, but for higher speeds external pull resistors may be needed. That should not be the main issu ehere though, as you report measuring a constant high voltage as I read it.

  • Hi, 

    thanks for the reply .

    i resolve the isssue of SDA and scl not toggling  ,  i am using nrf52840 DK , it  was the issue in my code now i m am usimng P0.27  and P90.26 for SCL and SDA but stiil it is not able to detect  my htdu sensor  whose adress is 0X40 .
    As suggested by you i will switch to nrf connect sdk , can you tell me or share me resources how to learn it efectively beacuse it take lot of time to me understnd it and sometime i get overwhelmed with the tyhing not working 

  • Hi,

    I am glad to hear you resolved the first issue. When switching to the nRF Connect SDK I recommend going through the nRF Connect SDK Fundamentals course. This takes about a day, but will get you started with all the tools and the basic understanding of how to work with the SDK. At a later point, I also recommend going through nRF Connect SDK Intermediate which covers more advanced topics. Other than that, the SDK documentation is quite extensive.

Related