Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2cdetect skips last address (0xff) #115

Closed
RoboSchmied opened this issue Mar 7, 2024 · 0 comments · Fixed by #116
Closed

i2cdetect skips last address (0xff) #115

RoboSchmied opened this issue Mar 7, 2024 · 0 comments · Fixed by #116

Comments

@RoboSchmied
Copy link
Contributor

RoboSchmied commented Mar 7, 2024

Problem

ipctool i2cdetect is always skipping the last address in its output. So i2c address 0xff is not readable with it.

root@openipc-gk7205v210:/tmp# ./ipctool i2cdetect
       0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f
    : xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  10: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  20: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  30: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  40: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  50: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  60: 60 61 xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  70: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  80: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  90: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  a0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  b0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  c0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  d0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  e0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  f0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx 

The problem is similar to #113 (but in an other function).

for (i2c_addr = 0x0; i2c_addr < 0xff; ++i2c_addr) {

Solution

The solution is not as simple as #114 because the data type unsigned char used for i2caddr is always a value between 0-255 (0x00 - 0xFF). And 0xff + 1 = 0x00.
So changing the < to <=will result in an infinite loop because the condition i2c_addr <= 0xff is always true when using unsigned char.

So we have to check the condition at the end of the loop to get the desired output.

} while (i2c_addr != 0xff);

Final output:

root@openipc-gk7205v210:/tmp# ./ipctool i2cdetect
       0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f
    : xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  10: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  20: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  30: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  40: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  50: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  60: 60 61 xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  70: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  80: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  90: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  a0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  b0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  c0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  d0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  e0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |  
  f0: xx xx xx xx xx xx xx xx  xx xx xx xx xx xx xx xx  |
@RoboSchmied RoboSchmied changed the title i2cdetect skips last byte i2cdetect skips last address (0xff) Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant