Error When Compiling I2C Code

Hello,

I wrote a sample code to read 8bits from an I2C device as below.

But I get the following error when I try to compile.

I'm quite new to this platform and I appreciate any help with this. Thank you.

Parents
  • Hi 

    If you are new to Nordic I would strongly check out the Nordic Developer Academy. The introductory course even includes a chapter dedicated to I2C which should help you get started. 

    I expect the problem with your sample is that you haven't created an I2C sensor in your overlay. The I2C_DT_SPEC_GET() macro will not work on the I2C top node itself, you have to use it with one of the sensors (or buses) on the I2C interface. The devacademy chapter will explain this in more detail. 

    Best regards
    Torbjørn

Reply
  • Hi 

    If you are new to Nordic I would strongly check out the Nordic Developer Academy. The introductory course even includes a chapter dedicated to I2C which should help you get started. 

    I expect the problem with your sample is that you haven't created an I2C sensor in your overlay. The I2C_DT_SPEC_GET() macro will not work on the I2C top node itself, you have to use it with one of the sensors (or buses) on the I2C interface. The devacademy chapter will explain this in more detail. 

    Best regards
    Torbjørn

Children
  • Hello,

    Thank you so much. I went through the exercise and implemented I2C and it worked! At least I don't get any errors for now. However, to complete the communication, the other device must receive the chip select pin as LOW. I went ahead and tried to use the GPIO 0.00 to use as a chip select. But the code doesn't continue after:

    gpio_is_ready_dt(&cs)

    I am working on the Make It Matter project and I'm trying to complete my firmware. This is why I didn't yet complete this course as there's only a limited number of days left.

    My code is as follows:

    The overlay file is below:

    Any suggestion is highly appreciated.

  • Hi Asanka

    Why would an I2C sensor have a chip select line? 

    Chip select is used by SPI devices, I haven't seen any I2C devices use it. 

    Regardless I don't think your overlay is quite correct. 

    I did something similar in a hobby project of mine, where I needed two output pins that could be manually controlled. 

    You can see the overlay here, and the relevant source here and here.

    Best regards
    Torbjørn 

  • Thank you. This is the device that I'm trying to control. It's an ADC.

    I will take a look at the overlays. I appreciate the support.

  • Hi 

    That looks like an SPI device to me, not an I2C device. If this is the case the I2C interface will struggle to communicate with it, since it will not receive any acknowledge. 

    Best regards
    Torbjørn

  • Hi,

    I think you're right. It seems to be an SPI device. Since it had only CLOCK and DATA, I thought it was I2C. I wrote the code for an SPI device but it doesn't initialize. Can you please let me know what I'm doing wrong?

    The device boots and then prints 'Device not ready...' and reboots.

    Code:

    DT: