DevAcademy I2C doing weird things nRF52840 DK

I'm having 3 issues with I2C:

A) It keeps returning -5 (-EIO), failed to write to I2C device..., however I do sometimes see the byte going out so I'm not sure why it always fails even when I can see it being transmitted.

B) The function i2c_write_dt keeps doing different things each time:

  temp_byte = 0xff;
ret = i2c_write_dt(&dev_i2c, &temp_byte, 1);

Most of the time it does 2 back-to-back low pulses on SDA whilte SCL remains high, sometimes the SDA line remains low afterwards.

On rare occasions the byte is sent and it looks perfect from what I can tell.

Every now and then it looks like it is sending the byte but SCL remains high the whole time.

C) When I call i2c_write_dt from an interrupt twice (void button_pressed(... and I press the button twice), the program seems to just crash and nothing else happens, I have to hit reset and it works again. I probably made a mistake calling that from an interrupt however it's a little bit worrisome that something so trivial causes the program to stop working. Is Zephyr / nRF Connect SDK prone to crashing / hanging?

At this point I'm going through DevAcademy because I've never used Zephyr before so I'm trying to learn it. I'm used to working directly with the hardware so this Zephyr thing is like inserting a black box between me and the hardware, most of the time I have no idea what's going on, I really hope that will change as I get better with it.

  • Check out this previous ticket in regards to using i2c in an ISR context.

    Zephyr does get easier as you fall deeper and deeper into the black box lol. Just be ready to have nightmares about 20 layers of MACRO expansions.

  • Hi

    Just a few questions to start with

    Which version of NCS are you using? 

    Are you doing any of the exercises in the fundamentals or the intermediate course, if so which? Just so that I can try to replicate what you seeing. 

    C) When I call i2c_write_dt from an interrupt twice (void button_pressed(... and I press the button twice), the program seems to just crash and nothing else happens, I have to hit reset and it works again. I probably made a mistake calling that from an interrupt however it's a little bit worrisome that something so trivial causes the program to stop working. Is Zephyr / nRF Connect SDK prone to crashing / hanging?

    The best would if you can provide any log of what is happening. I would also suggest checking out the link Louis posted. 

    At this point I'm going through DevAcademy because I've never used Zephyr before so I'm trying to learn it. I'm used to working directly with the hardware so this Zephyr thing is like inserting a black box between me and the hardware, most of the time I have no idea what's going on, I really hope that will change as I get better with it.

    Talking from experience it gets better and at times it feels good to don't have to write everything from scratch each time. Zephyr is in active development and it have greatly improved since I started with it and the tools have improved. 

    Regards

    Runar

  • Thanks for the replies. I ended up solving the issue, the sensor was a knock-off and used a different address. It didn't provide the ACK, so I think that was the root cause. I'm not sure why the I2C transmissions ended up looking different from one time to the next, I would have expected it to look the same and I don't know why it would basically freeze the program (at least it appeared that way). Let's chalk it up to me not knowing what I'm doing. If I discover issues again I will create a new thread / ticket. Thank you for your help!

  • Glad to hear you figured out the issue. Don't hesitate to create new tickets in the future is there is any question

    Regards

    Runar

Related