SPI/I2C question MSSP related

31 views
Skip to first unread message

vasile surducan

unread,
Mar 9, 2010, 6:16:38 AM3/9/10
to jal...@googlegroups.com
Hi all,

It's been a long time since I used both SPI and I2C from MSSP. As far I remember there is no issue using alternately SPI and I2C as long the unused device on the bus is highZ.
Does anyone tested this recently on PIC18 ?

thx,
Vasile

mattschinkel

unread,
Mar 11, 2010, 11:31:57 PM3/11/10
to jallib
I was thinking about doing this a few months ago to save pins. I did
not bother to test this because on my pic 18f452, they will have to
share the pin RC3/SCK/SCL and RC4/SDI/SDA. Sharing the clock line (SCK/
SCL) should be ok since the direction is always an output.

I worry about the SDI/SDA line. With SPI, this pin must always be
input. Does the I2C lib change the direction of this pin?

The SPI lib does not set the pin direction within the init procedure,
the user must do it.

There is also the SSPSTAT register to worry about, so maybe a call to
the init procedures before switching would solve these problems. I
would like to find a proper solution for this as well. Any Idea's?

Matt

vasile surducan

unread,
Mar 12, 2010, 12:16:00 AM3/12/10
to jal...@googlegroups.com
On Thu, Mar 11, 2010 at 8:31 PM, mattschinkel <mattsc...@hotmail.com> wrote:
I was thinking about doing this a few months ago to save pins. I did
not bother to test this because on my pic 18f452, they will have to
share the pin RC3/SCK/SCL and RC4/SDI/SDA. Sharing the clock line (SCK/
SCL) should be ok since the direction is always an output.

I worry about the SDI/SDA line. With SPI, this pin must always be
input. Does the I2C lib change the direction of this pin?

The SPI lib does not set the pin direction within the init procedure,
the user must do it.

   I'm using a particular SPI device (SD card) which has a CS pin. Disabling the SPI device will force an open impedance on all SPI lines. As long the SPI and I2C are not used in the same time, remains the issues you have pointed at, which seems software maintainable.
I hope I don't mistake here because I'm already working to the PCB.
 

There is also the SSPSTAT register to worry about, so maybe a call to
the init procedures before switching would solve these problems. I
would like to find a proper solution for this as well. Any Idea's?

Matt

On Mar 9, 3:16 am, vasile surducan <vsurdu...@gmail.com> wrote:
> Hi all,
>
> It's been a long time since I used both SPI and I2C from MSSP. As far I
> remember there is no issue using alternately SPI and I2C as long the unused
> device on the bus is highZ.
> Does anyone tested this recently on PIC18 ?
>
> thx,
> Vasile

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To post to this group, send email to jal...@googlegroups.com.
To unsubscribe from this group, send email to jallib+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jallib?hl=en.


mattschinkel

unread,
Mar 12, 2010, 12:50:21 AM3/12/10
to jallib
>    I'm using a particular SPI device (SD card) which has a CS pin. Disabling
> the SPI device will force an open impedance on all SPI lines. As long the
> SPI and I2C are not used in the same time, remains the issues you have
> pointed at, which seems software maintainable.
> I hope I don't mistake here because I'm already working to the PCB.

Yes, this is true for SD Cards. The CS pin should be disabled on the
SD card before using the SPI port for anything else (in this case, the
MSSP port). If the sd card CS line is still active when sending via
I2C, the sd card may pick up some data. You could accidently write to
the SD card. Some SPI divices allow the CS line to be disabled during
a data transfer, such as sram_23k256.

As stated in the SD card lib, you must finnish your your sd card
transfer before changing the CS pin. So, this must be handled in your
code. Do sd_stop_read() before using MSSP for another purpose.

Matt.

Joep Suijs

unread,
Mar 12, 2010, 1:20:06 AM3/12/10
to jal...@googlegroups.com
Hi Vasile,

2010/3/9 vasile surducan <vsur...@gmail.com>:


> Hi all,
> It's been a long time since I used both SPI and I2C from MSSP. As far I
> remember there is no issue using alternately SPI and I2C as long the unused
> device on the bus is highZ.

Why not use software i2c, on other pins?

Joep

vasile surducan

unread,
Mar 12, 2010, 1:54:28 AM3/12/10
to jal...@googlegroups.com
  I'm thinking at this option too. I don't have too many pins, even device has 44pins, only 40 are true, 4 are NC.
 thx.
Vasile

Joep

mattschinkel

unread,
Mar 12, 2010, 1:07:49 PM3/12/10
to jallib
I think another issue is that if a SPI device is in use, it will be
sending data to the pic on the SDI line, and at the same time, the clk
line will be running. If this occurs, I2C devices could pickup the
signal if addressed accidently via SDI. So, maybe it's not possible to
use both on the same pins.

Matt.

Mike@watty

unread,
Mar 12, 2010, 2:49:37 PM3/12/10
to jallib

However if you gate the I2C clock line with the CS of the SDI device,
(using AND gate or 1/4 4066) then the I2C will not see any clocks
while the CS is low to enable the SD card.

You can even make gate from two Schottky diodes from pull up resistor
of I2C slave device clock pin to SCLK and SD card /CS if it is low to
active SD card.

Joep Suijs

unread,
Mar 12, 2010, 3:55:09 PM3/12/10
to jal...@googlegroups.com
Hi,

2010/3/12 Mike@watty <watt...@gmail.com>:


>
>
> However if you gate the I2C clock line with the CS of the SDI device,
> (using AND gate or 1/4 4066)  then the I2C will not see any clocks
> while the CS is low to enable the SD card.
>
> You can even make gate from two Schottky diodes from pull up resistor
> of I2C slave device clock pin to SCLK and SD card /CS if it is low to
> active SD card.
>

Matt is right and solving is not as straight forward as this, since
both clock and data are bidirectional in i2c. If you can spare one
pin, I'd suggest you use that as a dedicated i2c clk pin. i2c data can
be one of the pins that is output when used with spi. If you don't
have a spare pin or insist on use hardware i2c, use a 'gate' like 4066
to keep the i2c clk high during spi operation.

Joep

Joep

mattschinkel

unread,
Mar 12, 2010, 10:53:40 PM3/12/10
to jallib
> i2c data can be one of the pins that is output when used with spi.

Will I2c change this pin to an input?

Matt.

Joep Suijs

unread,
Mar 13, 2010, 2:29:34 AM3/13/10
to jal...@googlegroups.com
2010/3/13 mattschinkel <mattsc...@hotmail.com>:

> Will I2c change this pin to an input?
Yes. Both i2c pins are either low-driving outputs or inputs.

Joep

vasile surducan

unread,
Mar 13, 2010, 2:43:48 AM3/13/10
to jal...@googlegroups.com
On Fri, Mar 12, 2010 at 10:07 AM, mattschinkel <mattsc...@hotmail.com> wrote:
I think another issue is that if a SPI device is in use, it will be
sending data to the pic on the SDI line, and at the same time, the clk
line will be running. If this occurs, I2C devices could pickup the
signal if addressed accidently via SDI.

I'm not sure if SPI combination of data-clock can really issue a start condition. As long there isn't a start, there isn't accidently addresing. I will check this...
Vasile
 
So, maybe it's not possible to
use both on the same pins.

Matt.

--
Reply all
Reply to author
Forward
0 new messages