ChristophK
Posts: 15
Joined: Thu Oct 06, 2016 1:34 pm

I2C Ack/Nack test with pigpio?

Wed Dec 21, 2016 1:09 pm

I tried to write a DS1077 clock oscillator.

Code: Select all

# open i2c-bus Nr.1 for DS1077 clock generator at address 0x58
DS1077 = pi.i2c_open(1, 0x58)

# DS1077 has 4 Command Registers: DIV=0x01, MUX=0x02, BUS=0x0d, E2=0x3f

# set DS1077 BUS: no automatic EEPROM write, Adr.Offset 0 
pi.i2c_write_byte_data(DS1077, 0x0d, 0x08)

time.sleep(0.0005)  # wait 0.5 msec, 0.4ms is too short

# set DS1077 DIV: 1025=0xffc0
pi.i2c_write_device(DS1077, [0x01, 0xff, 0xc0])

# set DS1077 MUX (after DIV!):
pi.i2c_write_device(DS1077, [0x02, 0x18, 0x00])

# close i2c-bus for DS1077
pi.i2c_close(DS1077)
without the long "time.sleep" I get this error message:

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Documents/PythonProjects/i2c_test01.py", line 70, in <module>
    pi.i2c_write_device(DS1077, [0x01, 0xff, 0xc0])
  File "/usr/local/lib/python3.4/dist-packages/pigpio.py", line 2916, in i2c_write_device
    self.sl, _PI_CMD_I2CWD, handle, 0, len(data), [data]))
  File "/usr/local/lib/python3.4/dist-packages/pigpio.py", line 943, in _u2i
    raise error(error_text(v))
pigpio.error: 'I2C write failed'
The datasheet does't tell about the time to write the EEPROM - this seems to be the problem.
How can I wait for an ACK bit ?

User avatar
joan
Posts: 14748
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C Ack/Nack test with pigpio?

Wed Dec 21, 2016 2:41 pm

The i2c_* functions use the standard Linux driver which does not properly support clock stretching. Your work around seems like a good idea.

The bb_i2c_* functions do provide for clock stretching (up to 10 milliseconds per bit).

Personally I'd just continue using your work around.

ChristophK
Posts: 15
Joined: Thu Oct 06, 2016 1:34 pm

Re: I2C Ack/Nack test with pigpio?

Wed Dec 21, 2016 3:34 pm

Thanks for your answer.
I just started learning python, so my simple question is: can I catch the error caused by a NACK bit, polling it like a hardware busy flag input, e.g. using a "while" loop and "i2c_read_byte(DS1077) with "try - except" ? I used a oscilloscope and found that the error handling happens immediately after the NACK bit, followed just by a I2C-stop sequence. So I need only a one-byte transmission.

User avatar
joan
Posts: 14748
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: I2C Ack/Nack test with pigpio?

Wed Dec 21, 2016 3:53 pm

ChristophK wrote:Thanks for your answer.
I just started learning python, so my simple question is: can I catch the error caused by a NACK bit, polling it like a hardware busy flag input, e.g. using a "while" loop and "i2c_read_byte(DS1077) with "try - except" ? I used a oscilloscope and found that the error handling happens immediately after the NACK bit, followed just by a I2C-stop sequence. So I need only a one-byte transmission.
By default pi.* functions return a fatal exception on error. If you want to handle the error code yourself you could wrap that portion of code in pigpio.exceptions = False/True and test the status of the pi.* call.

ChristophK
Posts: 15
Joined: Thu Oct 06, 2016 1:34 pm

Re: I2C Ack/Nack test with pigpio?

Thu Dec 22, 2016 9:15 am

Ok, I read your discussion with Massi about catching exceptions. I think thats too complicated for me, I will use a simple time.sleep.
I also contacted maximintegrated.com about this behavior, they never heard about it. The chip also responds to other register addresses than those mentioned in the datasheet when I use i2cdump.
Attachments
I2C_DS1077.png
I2C bus DS1077 with NACK
I2C_DS1077.png (26.14 KiB) Viewed 1663 times

ChristophK
Posts: 15
Joined: Thu Oct 06, 2016 1:34 pm

Re: I2C Ack/Nack test with pigpio?

Thu Dec 22, 2016 9:34 am

here is the strange register map (is there no fixed spacing font available?):

[email protected]:~ $ i2cdump -y 1 0x58 b
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: XX ff 18 XX XX XX XX XX 1c XX XX XX XX e8 XX XX X.?XXXXX?XXXX?XX
10: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
20: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
30: XX XX XX 75 a0 fe ff ff XX c7 XX XX XX XX XX XX XXXu??..X?XXXXXX
40: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
50: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
60: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
70: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
80: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
90: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
a0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
b0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
c0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
d0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
e0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
f0: XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XXXXXXXXXXXXXXXX
[email protected]:~ $ i2cdump -y 1 0x58 w
0,8 1,9 2,a 3,b 4,c 5,d 6,e 7,f
00: XXXX c0ff 0018 XXXX XXXX XXXX XXXX XXXX
08: 001c XXXX XXXX XXXX XXXX 00e8 XXXX XXXX
10: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
18: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
20: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
28: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
30: XXXX XXXX XXXX 8075 aca0 00fe fcff fcff
38: XXXX 00c7 XXXX XXXX XXXX XXXX XXXX XXXX
40: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
48: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
50: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
58: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
60: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
68: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
70: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
78: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
80: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
88: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
90: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
98: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
a0: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
a8: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
b0: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
b8: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
c0: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
c8: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
d0: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
d8: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
e0: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
e8: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
f0: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
f8: XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX
[email protected]:~ $

ChristophK
Posts: 15
Joined: Thu Oct 06, 2016 1:34 pm

Re: I2C Ack/Nack test with pigpio?

Tue Jan 10, 2017 8:10 am

Update: I got an answer from [email protected]:
As for the issue reading from the DS1077 after writing to the device, this likely due the EEPROM write cycle being busy storing data from SRAM into EEPROM. We typically have a specification for this (about 20ms), but this seems to have been omitted from the DS1077. EEPROM write cycles typically take as long as 20ms to complete. During this time, the I2C bus will not respond to commands. So please wait 20ms after executing a write cycle before issuing your next command.
So this behavior is normal

Return to “Python”