using I2C and SPI module on PIC18F452

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


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....


Re: using I2C and SPI module on PIC18F452


The simple answer is to make a bit bang interface using two currently
unused pins. If your PIC is the master, set one pin as an output for
clock (SCL) and you'll have to fiddle with the data line to make it an
input except when transmitting.

The entire spec can be found at
http://www.semiconductors.philips.com/markets/mms/protocols/i2c /

Cheers

PeteS


Re: using I2C and SPI module on PIC18F452




Quoted text here. Click to load it
the
PORTB
address

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.


Re: using I2C and SPI module on PIC18F452



Quoted text here. Click to load it



Re: using I2C and SPI module on PIC18F452



Quoted text here. Click to load it

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
 



Re: using I2C and SPI module on PIC18F452




petrus bitbyter wrote:

Quoted text here. Click to load it

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

Graham


Re: using I2C and SPI module on PIC18F452



Quoted text here. Click to load it

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



Re: using I2C and SPI module on PIC18F452




petrus bitbyter wrote:

Quoted text here. Click to load it

Maybe the OP could assist here ?


Quoted text here. Click to load it

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.

Quoted text here. Click to load it

That involves lots of extra hardware though.

Graham


Re: using I2C and SPI module on PIC18F452



Quoted text here. Click to load it

Yes, guess he should.

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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

petrus bitbyter



Re: using I2C and SPI module on PIC18F452


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.


Re: using I2C and SPI module on PIC18F452



Quoted text here. Click to load it

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



Re: using I2C and SPI module on PIC18F452


Ok tht makes it much clearer...thanks alot petrus an everybody else...


Re: using I2C and SPI module on PIC18F452




aerona wrote:

Quoted text here. Click to load it

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


Re: using I2C and SPI module on PIC18F452


Quoted text here. Click to load it
http://www.acpd.co.uk/87.html



Site Timeline