Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Atmega32u4 interfacing with PCA9555 I/O Expander using I2C Protocol

Status
Not open for further replies.

embRTS

Full Member level 4
Full Member level 4
Joined
Sep 8, 2013
Messages
201
Helped
36
Reputation
72
Reaction score
33
Trophy points
28
Location
Bangalore
Visit site
Activity points
1,191
Hi all I want to interface AVR(atmega32u4) with I/O expander and I want to control and regulate the pins of PCA9555 i/O expander so that I could blink some led's connected to I/O pins of PCA9555,
and also want to control the pins whichever i want to use

I have gone through I2c protocol it requires the device address of the PCA9555,
which is acting as Slave
so according to datasheet of PCA9555
it has A0,A1,A2 address bits but I am confused how to write values on those bits and Finally

How to control the I/O pins of PCA9555 with AVR
 

Well, with A2, A1, A0 YOU have the power of assigning I2C address to IC (see Section 6.1 of NXP datasheet). Because with A2, A1, A0 there are eight possible addresses, the 8 devices with unique assigned I2C address can be added to same I2C bus. Connect these pins to DIP switch and you can switch addresses for testing purposes or just simply connect them to GND and you will get address 0.

Sincerely,
Marko
 

I didn't get you properly
look I have 4 DIP switch connected to I/O pins of PCA9555 and 4 LED's connected to the remaining 4 pin of PCA9555

SO i want to control like this

The Switch one end is connected to ground and same is for LED also

So whenever I press the Switch the respective LED should glow and the same is followed for the remaining 3 LED's

As PCA9555 has two sets of I/O configurations I/O 0 and I/O 1

Those switch and LED's are connected to I/O 0
 

I didn't get you properly
look I have 4 DIP switch connected to I/O pins of PCA9555 and 4 LED's connected to the remaining 4 pin of PCA9555

SO i want to control like this

The Switch one end is connected to ground and same is for LED also

So whenever I press the Switch the respective LED should glow and the same is followed for the remaining 3 LED's

As PCA9555 has two sets of I/O configurations I/O 0 and I/O 1

Those switch and LED's are connected to I/O 0
Wait, wait! We are currently talking about A2, A1, A0 setup, not functionality itself! If you pull down A2, A1, A0 to GND, then you will have PCA9555 I2C address 000 (binary). For example, if you pull up these lines to VCC, then you will have PCA9555 I2C address 111 (binary). Between 000 and 111 are six more combinations, so up to 8 devices can be addressed on same IC2 bus.I understood this was your questions.
 

I got the idea of Programming the Address A2,A1,A0

ok like one device is LCD then address is something like "000"

one device is Switch , led and it's address is something like that "111".

Got the point what i tried to say

and in my previous post I explained that only i.e. interfacing of Switch & LED

So , i can assign a unique address for each device right ????
 

No, address of your port expander PCA9555 is 000. Then, you address connected devices (connected to PCA9555) through sending commands on I2C bus with address 000 (i.e., you "tell" PCA9555: "this data is for LCD", "this data is for SWITCH", etc ... That is why you need to read datasheet carefully ... Can you attach datasheet of PCA9555, Since Texas Instruments has such device and NXP has such devices and they are NOT THE SAME ...
 

Ya i.e of NXP only
one more confusion still after address bytes ,
Command bytes are sent I have attached an image also here can you send me how to access that like
we define in AVR by
DDR? = (1<<DDR??); //Declaring as Output Pin/Port

so how I can manage the i/o pins of PCA9555 I had gone through the datasheet also there are configurations register and some more Register Pair also
Untitled.png
 

You cannot do it in that way. You must issue command to configure I/O ports of PCA9555. Check page 8 of datasheet (6.2.5 Registers 6 and 7: Configuration registers).
 

Ya I had gone through that but I wish that you could tell me how should I assign the command bytes in C code
 

Well, try it yourself a little, I cannot do your task instead of you! Google for "C string manipulation"!
 

No no u get me wrong I am not saying you to write C code for me dude I have just tried to ask a general way to write for the Command Bytes only ,
Anyways thanks for your Support !!
 

You don't write values to A0, A1, A2 pins. Connect A0, A1, A2 to GND and the slave address will be 0b000. This is the address you send through I2C when talking with the device. A0, A1, A2 can have 8 values like

000
001
010
011
100
101
110
111

If you connect A0,A1,A2 to +5V (logic high) then device address is 0b111 = 7.

Edit:

If A0, A1, A2 is 000 then

Device address is

0100000x

x = 1 or 0

x = 0 is write operation
x = 1 is read operation

If 01000001 is thsent to device then device gets ready for read operation.

See page 8 of TI datasheet for PCA9555.

http://www.mikroe.com/forum/viewtopic.php?t=15942
http://www.libstock.com/projects/vi...55-io-expander-with-proteus-7-8-sp2-in-mikroc

- - - Updated - - -

Configuration register is used to set the PCA9555 port as input/output port. If example P0 is set as output port then you can write values to P0.

- - - Updated - - -

Configuration register is used to set the PCA9555 port as input/output port. If example P0 is set as output port then you can write values to P0.
 
Last edited:
  • Like
Reactions: embRTS

    embRTS

    Points: 2
    Helpful Answer Positive Rating
Hi Milan that was done Now i need a bit help of yours
earlier I have accessed that Configuration Register
as like (0x00) i.e I accessed the whole 8 bit Register
Now my Question is
Can it be possible to access individual bits
like configuration register 6 for Port 0 I am using so
for this
I wished that like in AVR
we do
DDRB= (1<<DDB7); //That Configures PORTb.7 as Output

or in the same Register I can do like
DDRB = (0<<DDB5); //That Configures PORTB.5 as INPUT

So like wise I wish to access the configuration Register of PCA9555
 

You have to read the whole port and then perform ANDing and ORing and write back the new value to the device.
 

that i've done just wanted to thanks for the things ,
it is very late but still thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top