Searching \ for '[PIC:] I2C & SPI on the same PIC...' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/i2cs.htm?key=i2c
Search entire site for: 'I2C & SPI on the same PIC...'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] I2C & SPI on the same PIC...'
2004\04\15@112449 by Ted Larson

flavicon
face
All this talk about SPI devices, has me thinking about an interesting
problem I have, that perhaps someone can suggest an easy solution for.

I am not too familiar with SPI, I am just learning about it, however, I am
pretty familiar with I2C at this point.  I have a circuit that has a
PIC18F252 as an I2C master, and it talks to several I2C slave devices.  I
have recently been presented with an SPI device that I need to interface to
the same I2C master PIC.  The SSP hardware on the PIC is pretty much I2C or
SPI, and not both.  Short of switching everything to SPI, what are my
options?  Is there some kind of I2C to SPI converter out there?  I have
poked around, and there doesn't appear to be a PIC with more than one SSP on
it...perhaps there is one I am missing?

Thanks,

- Ted

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\04\15@113317 by Alan B. Pearce

face picon face
>All this talk about SPI devices, has me thinking about an interesting
>problem I have, that perhaps someone can suggest an easy solution for.
>
>I am not too familiar with SPI, I am just learning about it, however, I am
>pretty familiar with I2C at this point.  I have a circuit that has a
>PIC18F252 as an I2C master, and it talks to several I2C slave devices.  I
>have recently been presented with an SPI device that I need to interface to
>the same I2C master PIC.  The SSP hardware on the PIC is pretty much I2C or
>SPI, and not both.  Short of switching everything to SPI, what are my
>options?  Is there some kind of I2C to SPI converter out there?  I have
>poked around, and there doesn't appear to be a PIC with more than one SSP
on
>it...perhaps there is one I am missing?

Bit bang SPI on another set of pins. IIRC there are code examples for 16
series on the piclist.com site which should be easily modified for 18 series
devices. It is reputedly easier to bit bang SPi than I2C, but I have never
tried to bit bang either of them.

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu

2004\04\15@114754 by Harold Hallikainen

face picon face
I'm working on a project that uses an 18f6720, and I'm writing the code in
Microchip C18. It's talking to both SPI and I2C devices. I just do the
appropriate "open" (initializing the SPP) prior to talking to the
particular device. I then do a close. The SPI devices ignore the I2C data
since their chip select lines are not low. The I2C devices ignore the SPI
data since SPI never sends a valid I2C start. It's worked so far!

Harold

{Quote hidden}

--
FCC Rules Online at http://www.hallikainen.com

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu

2004\04\15@123536 by hael Rigby-Jones

picon face
{Quote hidden}

SPI is an order of magnitude more simple than I2C.  Think of a shift
register that has a chip select signal and that's about as complex as it
gets.

The good news is that SPI is also much easier than I2C to bit bash, so
unless you need very high speed, you can keep the MSSP for I2C master and
bit bash the SPI:

Set CS (chip select) low
Set SDO (data out) according to bit (most significant bit first)
Set SCK (clock) high
Read SDI (data in)
Set SCK low

In assembly this boils down to relatively few instructions, so it's often
practical to code this inline for all 8 bits rather than use a loop for
optimal speed.

#define CS LATB,0
#define SDO LATB,1
#define SDI PORTB,2
#define SCK LATB,3

clrf     DataIn
bsf    CS        ; chip select low

; clock in/out bit 7
btfss  DataOut,7
bcf    SDO       ; data out low
btfsc  DataOut,7
bcf    SDO       ; data out high

bsf    SCK       ; clock high

btfsc  SDI       ; if input high
bsf    DataIn, 7 ; set bit in DataIn

bcf    SCK       ; clock low

; clock in/out bit 6
btfss  DataOut,6
bcf    SDO       ; data out low
btfsc  DataOut,6
bcf    SDO       ; data out high

bsf    SCK       ; clock high

btfsc  SDI       ; if input high
bsf    DataIn, 6 ; set bit in DataIn

bcf    SCK       ; clock low
...etc....

This emulates the operation of the MSSP, where 8 bits are read in at the
same time that 8 bits are transmitted (i.e. to read only, you would perform
a dummy write).  If you only ever need to read or write separately you can
make a separate read and write function that would execute more quickly.

There was a recent discussion on the faster method of clocking out 8 bits in
the manner, regarding some benchmakrs for the Maxim "MAXQ" microcontroller.
You should be able to find this in the archive.

Regards

Mike




=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to
@spam@postmasterKILLspamspambookham.com.

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu

2004\04\15@132003 by Ken Pergola

flavicon
face
Regarding: Bit-banging SPI
--------------------------

Always keep in mind that the Serial Peripheral Interface has 4 different bus
modes (timing relationships) due to the combinations of clock phase (CPHA)
and clock polarity (CPOL).


Best regards,

Ken Pergola

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\04\15@133455 by Bob Ammerman

picon face
SPI is simply enough that you can just 'bit-bang' on a couple of pins.

Bob  Ammerman
RAm Systems

----- Original Message -----
From: "Ted Larson" <spamBeGonetedspamBeGonespamLARSONLAND.COM>
To: <TakeThisOuTPICLISTEraseMEspamspam_OUTMITVMA.MIT.EDU>
Sent: Thursday, April 15, 2004 11:09 AM
Subject: [PIC:] I2C & SPI on the same PIC...


> All this talk about SPI devices, has me thinking about an interesting
> problem I have, that perhaps someone can suggest an easy solution for.
>
> I am not too familiar with SPI, I am just learning about it, however, I am
> pretty familiar with I2C at this point.  I have a circuit that has a
> PIC18F252 as an I2C master, and it talks to several I2C slave devices.  I
> have recently been presented with an SPI device that I need to interface
to
> the same I2C master PIC.  The SSP hardware on the PIC is pretty much I2C
or
> SPI, and not both.  Short of switching everything to SPI, what are my
> options?  Is there some kind of I2C to SPI converter out there?  I have
> poked around, and there doesn't appear to be a PIC with more than one SSP
on
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestEraseMEspam.....mitvma.mit.edu

2004\04\16@113655 by Ted Larson

flavicon
face
Thanks for the example....this is very helpful.

Thanks,

- Ted


-----Original Message-----
From: Michael Rigby-Jones [EraseMEMichael.Rigby-JonesspamBOOKHAM.COM]
Sent: Thursday, April 15, 2004 9:36 AM
To: RemoveMEPICLISTEraseMEspamEraseMEMITVMA.MIT.EDU
Subject: Re: [PIC:] I2C & SPI on the same PIC...

{Quote hidden}

SPI is an order of magnitude more simple than I2C.  Think of a shift
register that has a chip select signal and that's about as complex as it
gets.

The good news is that SPI is also much easier than I2C to bit bash, so
unless you need very high speed, you can keep the MSSP for I2C master and
bit bash the SPI:

Set CS (chip select) low
Set SDO (data out) according to bit (most significant bit first) Set SCK
(clock) high Read SDI (data in) Set SCK low

In assembly this boils down to relatively few instructions, so it's often
practical to code this inline for all 8 bits rather than use a loop for
optimal speed.

#define CS LATB,0
#define SDO LATB,1
#define SDI PORTB,2
#define SCK LATB,3

clrf     DataIn
bsf    CS        ; chip select low

; clock in/out bit 7
btfss  DataOut,7
bcf    SDO       ; data out low
btfsc  DataOut,7
bcf    SDO       ; data out high

bsf    SCK       ; clock high

btfsc  SDI       ; if input high
bsf    DataIn, 7 ; set bit in DataIn

bcf    SCK       ; clock low

; clock in/out bit 6
btfss  DataOut,6
bcf    SDO       ; data out low
btfsc  DataOut,6
bcf    SDO       ; data out high

bsf    SCK       ; clock high

btfsc  SDI       ; if input high
bsf    DataIn, 6 ; set bit in DataIn

bcf    SCK       ; clock low
...etc....

This emulates the operation of the MSSP, where 8 bits are read in at the
same time that 8 bits are transmitted (i.e. to read only, you would perform
a dummy write).  If you only ever need to read or write separately you can
make a separate read and write function that would execute more quickly.

There was a recent discussion on the faster method of clocking out 8 bits in
the manner, regarding some benchmakrs for the Maxim "MAXQ" microcontroller.
You should be able to find this in the archive.

Regards

Mike




=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by law. If
you are not the intended recipient of this message, you must not make any
use of this information, or copy or show it to any person. Please contact us
immediately to tell us that you have received this e-mail, and return the
original to us. Any use, forwarding, printing or copying of this message is
strictly prohibited.
No part of this message can be considered a request for goods or services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to
EraseMEpostmasterspamspamspamBeGonebookham.com.

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestKILLspamspammitvma.mit.edu

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...