Il 30/03/21 22:36, MogensB ha scritto:
> I had trouble getting it to work, until I tried an I2C bus scanner
> for Arduino, which reported a device address of 0x3F. for the SC407.
> I can now read buttons, and write LEDs on that same device address
> using Arduino "Wire" library and I2C device address 0x3F.
>
> But reading the docs for SC407 I would expect writes to 0x7E and
> reads from address 0x7F? I have set jumpers A0, A1 and A2 to the "1"
> position. Maybe I am misinterpreting the addresses 0x7E and 0x7F? Do
> they have anything to do with the I2C device address?
The answer is that both are correct, depending on how you "see" the I2C
addressing.
The Arduino hardware, and somewhat "official" I2C documentation, uses
the 7 bit address (3F in your case), however when the hardware sends it
to the device it automatically "shifts" the address 1 bit to the left
because bit 0 is the read/write flag. So again, writing to 7E and
reading from 7F is correct because 3F << 1 = 7E, bit 0 is 0 for write
and 1 for read, thus 7E/7F.
In a (hopefully clear) schematic representation:
+-----+-----+-----+-----+-----+-----+-----+-----+
Bit N. | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+-----+-----+-----+-----+-----+-----+-----+-----+
| I2C address (7 bit) | r/w |
+-----+-----+-----+-----+-----+-----+-----+-----+
3F -> | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1/0 | 7F/7E
+-----+-----+-----+-----+-----+-----+-----+-----+
In the thread 'Need I2C and SPI sample code' I have posted some source
examples for I2C, including a scanner that will show you the address as
the Arduino scanner.
Hope to not have misplaced something.
Best regards,
Marco