View previous topic :: View next topic |
Author |
Message |
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
Is it possible to run spi and i2c protocol with one uC? |
Posted: Sun Jun 24, 2007 3:25 am |
|
|
I will drive with a pfc8583 (i2c interface) a dot matrix display
This matrix display has 10 Max7221 on it (spi interface)
(Will display the time on the dot matrix display)
The uC is an PIC18F4620
My question is now:
Is it possible to control the i2c and spi interface the same time
... and how do that? |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Jun 24, 2007 10:45 am |
|
|
It is not possible to do it simultaneously. The main reason is that the built in
hardware module that control both operating modes (SPI & I2C) is the same.
This module, the MSSP (Master Synchronous Serial Port) can be configured
to operate in:
1) SPI Mode: Using this four registers:
SSPCON1 SSPSTAT SSPBUF SSPSR
2) I2C Mode: Using this six registers:
SSPCON1 SSPSTAT SSPBUF SSPSR SSPCON2 SSPADD
Looking at the dedicated pins for both operations, you will see that pins RC3
and RC4 share its functionalities in SPI or I2C modes. From the I2C and SPI
hardware levels point of view, there are no risk for any hardware damage,
but you will realize that the system behaviour would be unpredictable running
at the same "time shared" time.
Humberto |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sun Jun 24, 2007 10:59 am |
|
|
Then the only possible is that i then must use a Spi interface clock chip
Is that correct?
The pcf8583 is on a PIC development board.
The i2c pins are hardwired to the pic, thus i can not use diferent lines for soft i2c mode |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 24, 2007 12:40 pm |
|
|
Use software SPI for the Max7221 chips.
The Max7221 needs three signals: DIN, \CS, and CLK.
Use three free i/o pins for this, such as pins B0, B1, B2.
The PCF8583 can stay on pins C3 and C4. |
|
|
The Puma
Joined: 23 Apr 2004 Posts: 227 Location: The Netherlands
|
|
Posted: Sun Jun 24, 2007 1:53 pm |
|
|
How to do software spi?
Are there standard libs for? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 24, 2007 2:12 pm |
|
|
There are many examples in the CCS example and driver files.
According to the latest manual, version 4 of the compiler has a
#use spi() library which can create software (or hardware) SPI code.
I haven't tested this library.
Look in these directories:
c:\Program Files\Picc\Examples
c:\Program Files\Picc\Drivers
The write_isd() function in the isd4003.c driver will write 16 bits
using software SPI, in SPI mode 0.
c:\program files\picc\drivers\isd4003.c |
|
|
|