Pages: [1]   Go Down
Author Topic: I2C Synthax - beginner  (Read 724 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I've found a great tutorial on:
http://www.neufeld.newton.ks.us/electronics/?p=241

but I have some questions:
(my questions as comments)
Code:
#define DIP_ADDRESS (0x4 << 3 | 0x0) // how should I understand that << and |
Wire.send(0xff & dir);  //  the same question with &
Wire.send(dir >> 8);    //  the same question with >>
//What make that three lines?
and one more question here:
Code:
#define REGISTER_CONFIG (6) // has REGISTER_CONFIG a value 6?
Wire.send(REGISTER_CONFIG); // why am I sending 6?

Thanks for Your help!


Logged

Canberra, Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 31
I always look this excited
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

<<, >>, |, & are plain ordinary C operators. I'd look for a C tutorial if I were you
Logged

Cheers,

PeterV in Canberra

Grenoble/Lyon - France
Offline Offline
Sr. Member
****
Karma: 0
Posts: 363
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

On the page you linked
Quote
To write to a register, send the chip the register address followed by the desired data.

The full code is :
Code:
#define REGISTER_CONFIG (6)

void gpio_dir(int address, int dir) {
  //  Send config register address
  Wire.beginTransmission(address);
  Wire.send(REGISTER_CONFIG);

  //  Connect to device and send two bytes
  Wire.send(0xff & dir);  //  low byte
  Wire.send(dir >> 8);    //  high byte

  Wire.endTransmission();
}

You're using a PCA9555, 16bit I/O expander, so by looking at the datasheet pf the chip, you see that
Quote
The Configuration registers (registers 6 and 7) configure the directions of the I/O pins. If a bit in this register is
set to 1, the corresponding port pin is enabled as an input with a high-impedance output driver. If a bit in this
register is cleared to 0, the corresponding port pin is enabled as an output.

Register 6 is the configuration for 8 I/O pins, register 7 for the 8 olthers pins.
So, you are sending the number 6 to the chip to tell it that you want to access the register number 6 (REGISTER_CONFIG = 6).

In the code from the page, the variable dir is an integer used to tell which pins will be an input & which ones will be outputs.

Have a look here for the bitwise operators : http://www.arduino.cc/en/Tutorial/BitMask
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
On the page you linked
Register 6 is the configuration for 8 I/O pins, register 7 for the 8 olthers pins.
So, you are sending the number 6 to the chip to tell it that you want to access the register number 6 (REGISTER_CONFIG = 6).

Now I understand...
but have one more question..

I've found a datasheet: http://www.datasheetcatalog.org/datasheet/philips/PCA9555_3.pdf
"... This register is an input-only port. It reflects the incoming logic levels
of the pins,..." (site 6)

if I understand I can not set all 16 pins as output or input?
Is there a I/O I2C chip where I can set all 16 pins how I want?

Thanks for help!
Logged

Pages: [1]   Go Up
Jump to: