Go Down

Topic: I2C Synthax - beginner (Read 846 times) previous topic - next topic

windmis

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: [Select]

#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: [Select]

#define REGISTER_CONFIG (6) // has REGISTER_CONFIG a value 6?
Wire.send(REGISTER_CONFIG); // why am I sending 6?


Thanks for Your help!



verstapp

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

PeterV in Canberra

melka

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: [Select]
#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
http://melka.one.free.fr/blog/
http://www.flickr.com/photos/melkaone/

windmis

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!

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy