Maker Pro
Maker Pro

using I2C and SPI module on PIC18F452

A

aerona

hello guys.. I wonder if someone can help me....

I''m having trouble with a project i've undertaken recently where i am
trying to interface a Anybus module to a PIC18f452. Everything was
going fine until i found that I don't have enough I/O pins to address
the Anybus module's 12bit address. Therefore I wanted to use a PCF8575
I/O expander chip which uses I2C interface. But I'm already using the
pins SCL and SDA pins for the DAC which I use (its interfaced using the
SPI interface) hence I've got a problem. I'm already using PORTD an
PORTE for the Parallel Slave Port (PSP) to get data to the Anybus and
PORTA is used for the Analog to Digital converter and I only have PORTB
(8bits) left. I've tried to implement a latching system where i address
the 12bits with 8bits by de-multiplexing but its very complex. I'm
using the PIC18f452 chip as stated before with MICRO CHIP MPLAB C18
compiler.

thanks....
 
P

petrus bitbyter

aerona said:
hello guys.. I wonder if someone can help me....

I''m having trouble with a project i've undertaken recently where i am
trying to interface a Anybus module to a PIC18f452. Everything was
going fine until i found that I don't have enough I/O pins to address
the Anybus module's 12bit address. Therefore I wanted to use a PCF8575
I/O expander chip which uses I2C interface. But I'm already using the
pins SCL and SDA pins for the DAC which I use (its interfaced using the
SPI interface) hence I've got a problem. I'm already using PORTD an
PORTE for the Parallel Slave Port (PSP) to get data to the Anybus and
PORTA is used for the Analog to Digital converter and I only have PORTB
(8bits) left. I've tried to implement a latching system where i address
the 12bits with 8bits by de-multiplexing but its very complex. I'm
using the PIC18f452 chip as stated before with MICRO CHIP MPLAB C18
compiler.

thanks....
 
A

Anthony Fremont

aerona said:
hello guys.. I wonder if someone can help me....

I''m having trouble with a project i've undertaken recently where i am
trying to interface a Anybus module to a PIC18f452. Everything was
going fine until i found that I don't have enough I/O pins to address
the Anybus module's 12bit address. Therefore I wanted to use a PCF8575
I/O expander chip which uses I2C interface. But I'm already using the
pins SCL and SDA pins for the DAC which I use (its interfaced using the
SPI interface) hence I've got a problem. I'm already using PORTD an
PORTE for the Parallel Slave Port (PSP) to get data to the Anybus and
PORTA is used for the Analog to Digital converter and I only have PORTB
(8bits) left. I've tried to implement a latching system where i address
the 12bits with 8bits by de-multiplexing but its very complex. I'm
using the PIC18f452 chip as stated before with MICRO CHIP MPLAB C18
compiler.

About all I could suggest is for you to take a couple of unused i/o pins
and bit-bang the I2C. Either that or switch to an I2C DAC. I have some
PIC assembler code that bit-bangs I2C if you'd like it, but you should
be able to find a C example somewhere.

Hint: toggling the TRIS bit is the easy way to simulate an open
collector output. You preset things by defaulting the i/o pin to input
mode, using an external pull-up, and preloading the PORTx bit with a
zero. Then to write a zero to the bus, you simply toggle the TRIS pin
to output mode. This will cause the pin to pull the resistor down to
Vdd causing other devices on the bus to interpret it as a 0. To write a
1 to the bus, you toggle the TRIS bit to input mode by setting it. The
pin then reverts to high impedance allowing the external pull-up
resistor to pull the bus line high. This will naturally be interpreted
as a 1 by other devices on the I2C bus.
 
P

petrus bitbyter

aerona said:
hello guys.. I wonder if someone can help me....

I''m having trouble with a project i've undertaken recently where i am
trying to interface a Anybus module to a PIC18f452. Everything was
going fine until i found that I don't have enough I/O pins to address
the Anybus module's 12bit address. Therefore I wanted to use a PCF8575
I/O expander chip which uses I2C interface. But I'm already using the
pins SCL and SDA pins for the DAC which I use (its interfaced using the
SPI interface) hence I've got a problem. I'm already using PORTD an
PORTE for the Parallel Slave Port (PSP) to get data to the Anybus and
PORTA is used for the Analog to Digital converter and I only have PORTB
(8bits) left. I've tried to implement a latching system where i address
the 12bits with 8bits by de-multiplexing but its very complex. I'm
using the PIC18f452 chip as stated before with MICRO CHIP MPLAB C18
compiler.

thanks....

The I2C and the SPI interfaces differ too much to use the same pins (unless
you want to run into a maze of both hard- and software problems). It simply
does not pay off.

Guess you already understand that either a DAC with an I2C interface or a
busexpander with an SPI interface will solve your problem.

You can use two I/O pins to emulate an I2C master as PeteS already
mentioned. As you have the PCF8575 already you don't need extra hardware.
Drawback: It's a lot of software and s-l-o-w.

Best solution I can provide is using a busregister. You split up the 12-bits
address in two 6-bits parts. Six out off the eight available output pins
should be used for the address bus. You write one half of the address on
that bus and then use one of the remaining output pins to clock it into an
old LS363 similar CMOS buslatch. When done, you put the other half of the
address on the bus and then use the remaining output pin to signal that the
address is valid. Due to the properties of the PIC processors, you need to
do five full port output commands. Consider you want to latch the high part
of the address first.
- output high address part with latch enable and address valid off
- output high address part with latch disable and address valid off
- output low address part with latch disabled and address valid off
- output low address part with latch disabled and address valid on
- output low address part with litch disabled and address valid off
So you only need one LS363 like chip instead of the PCF8575. The first being
smaller and much cheaper then the last.
You can also use a LS364 or similar. These are edge-triggered D-flipflops so
you need to give an extra output command before the other five:
- output high address part with latch disable and address valid off
to make sure the addresspart is stable when it is clocked into the
flipflops.

petrus bitbyter
 
P

Pooh Bear

aerona said:
hello guys.. I wonder if someone can help me....

I''m having trouble with a project i've undertaken recently where i am
trying to interface a Anybus module to a PIC18f452. Everything was
going fine until i found that I don't have enough I/O pins to address
the Anybus module's 12bit address. Therefore I wanted to use a PCF8575
I/O expander chip which uses I2C interface. But I'm already using the
pins SCL and SDA pins for the DAC which I use (its interfaced using the
SPI interface) hence I've got a problem. I'm already using PORTD an
PORTE for the Parallel Slave Port (PSP) to get data to the Anybus and
PORTA is used for the Analog to Digital converter and I only have PORTB
(8bits) left. I've tried to implement a latching system where i address
the 12bits with 8bits by de-multiplexing but its very complex. I'm
using the PIC18f452 chip as stated before with MICRO CHIP MPLAB C18
compiler.

What's an 'anybus' module ?

You can use any of the port pins to drive I2C ( or SPI ) .You need to write
your own handler but it's easy.


Graham
 
P

Pooh Bear

petrus said:
The I2C and the SPI interfaces differ too much to use the same pins (unless
you want to run into a maze of both hard- and software problems). It simply
does not pay off.

Guess you already understand that either a DAC with an I2C interface or a
busexpander with an SPI interface will solve your problem.

You can use two I/O pins to emulate an I2C master as PeteS already
mentioned. As you have the PCF8575 already you don't need extra hardware.
Drawback: It's a lot of software and s-l-o-w.

True but the stuff hanging off I2C or SPI rarely creates much traffic
typically.

Graham
 
P

petrus bitbyter

Pooh Bear said:
True but the stuff hanging off I2C or SPI rarely creates much traffic
typically.

Graham

As so often it depends. I've no idea how often that that Anybus needs to be
accessed - I even don't know what it looks like - but if you have to access
all of the 2^12 addresses you'll be busy bitbanging for quite some time. I
simply don't know whether or not that time is available. Besides, you'll
have to implement and debug that I2C interface. It's not very difficult and
examples are available but it *is* work that takes its time. The address
latch on the other hand is easy to implement requires hardly extra software
and can be considered proven technology. The old 6800 series, the 6502, the
8088 and several others used this way of address demultiplexing already.

petrus bitbyter
 
P

Pooh Bear

petrus said:
As so often it depends. I've no idea how often that that Anybus needs to be
accessed

Maybe the OP could assist here ?

- I even don't know what it looks like - but if you have to access
all of the 2^12 addresses you'll be busy bitbanging for quite some time. I
simply don't know whether or not that time is available. Besides, you'll
have to implement and debug that I2C interface. It's not very difficult and
examples are available but it *is* work that takes its time.

Well.....

A while back I implemented something new not dissimilar to I2C to control a
specific DSP chip with a proprietary serial interface.

It took almost no debugging time.

If you make the pins waggle as required, no reason it should be tricky.
The address
latch on the other hand is easy to implement requires hardly extra software
and can be considered proven technology. The old 6800 series, the 6502, the
8088 and several others used this way of address demultiplexing already.

That involves lots of extra hardware though.

Graham
 
P

petrus bitbyter

Pooh Bear said:
Maybe the OP could assist here ?

Yes, guess he should.
Well.....

A while back I implemented something new not dissimilar to I2C to control
a
specific DSP chip with a proprietary serial interface.

It took almost no debugging time.

If you make the pins waggle as required, no reason it should be tricky.

Sure. Apparently you have experience in this kind of software. But although
I ever build one myself - so I have it on the shelf - an old hardware guy
like me will choose for the addressbuslatch option. The only disadvantage I
see is the need for all eight output pins. The I2C emulater requires only
two.
That involves lots of extra hardware though.

Graham

That's what I deny in this particular case. It just requires one LS363
instead of the PCF8575.

petrus bitbyter
 
A

aerona

Thanks alot for all the replies... I've looked at all the ideas
mentioned and at first bit-banging the I2C on to 2 other pins seemed
good. However I am not sure if the data rates would be satisfactory...
Therefore I am also looking at using an I2C DAC with the PCF8575 as
mentioned by you guys... I've come across the DAC6573 by TI which seems
good alternative to the MAX522.
If there is anyone who has a C code example on how to implement 2, I2C
devices on the same bus line it would be very helpful.
As for the latch method I don't really get it still... I mean wouldn't
I have to design logic circuits to every 12 bit address I want to
address from the 8 bits? As far as my understanding goes it's not
possible to get the full range of addresses in the 12bit from the 8
right? If it is possible to give some places for further reference it
would be great.
I thank you once again for all the help and I am very grateful to all
of you...
Regards,
Aerona.
 
P

petrus bitbyter

aerona said:
Thanks alot for all the replies... I've looked at all the ideas
mentioned and at first bit-banging the I2C on to 2 other pins seemed
good. However I am not sure if the data rates would be satisfactory...
Therefore I am also looking at using an I2C DAC with the PCF8575 as
mentioned by you guys... I've come across the DAC6573 by TI which seems
good alternative to the MAX522.
If there is anyone who has a C code example on how to implement 2, I2C
devices on the same bus line it would be very helpful.
As for the latch method I don't really get it still... I mean wouldn't
I have to design logic circuits to every 12 bit address I want to
address from the 8 bits? As far as my understanding goes it's not
possible to get the full range of addresses in the 12bit from the 8
right? If it is possible to give some places for further reference it
would be great.
I thank you once again for all the help and I am very grateful to all
of you...
Regards,
Aerona.

Well, look here (using fixed font p.e. Courier):


+----------+
| |
..--------. | .----------. .-------------.
| | Address Valid | | G | | |
| D7|----------- | --| Q7|-- | Anybus |
| | Address Latch | | | | |
| D6|----------------+ --| Q6|-- | |
| PIC | | L | | |
| 18F D5|-----+----------------|D5 S Q5|---------|AD11 |
| 452 | | | 3 | | |
| D4|-----|-+--------------|D4 6 Q4|---------|AD10 |
| | | | | 3 | | |
| D3|-----|-|-+------------|D3 Q3|---------|AD9 |
| | | | | | | | |
| D2|-----|-|-|-+----------|D2 Q2|---------|AD8 |
| | | | | | | | | |
| D1|-----|-|-|-|-+--------|D1 Q1|---------|AD7 |
| | | | | | | | | | |
| D0|-----|-|-|-|-|-+------|D0 Q0|---------|AD6 |
| | | | | | | | | OC | | |
| | | | | | | | '----------' | |
| | | | | | | | | | |
| | | | | | | | GND | |
| | | | | | | +---------------------------|AD5 |
| | | | | | | | |
| | | | | | +-----------------------------|AD4 |
| | | | | | | |
| | | | | +-------------------------------|AD3 |
| | | | | | |
| | | | +---------------------------------|AD2 |
| | | | | |
| | | +-----------------------------------|AD1 |
| | | | |
| | +-------------------------------------|AD0 |
'--------' '-------------'
created by Andy´s ASCII-Circuit v1.24.140803 Beta www.tech-chat.de


As described earlier, first latch the upper part of the twelve bit address
into the LS363, then put the lower part on the address bus which has been
directly connected to the Anybus. This way you can offer all of the 2^12
addresses to the Anybus module.

petrus bitbyter
 
Top