Searching \ for ' Microchip C Compiler and SPI' 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/microchip/ios.htm?key=spi
Search entire site for: 'Microchip C Compiler and SPI'.

No exact or substring matches. trying for part
PICList Thread
'[PIC:] Microchip C Compiler and SPI'
2002\05\07@194702 by Harold M Hallikainen

picon face
       I'm trying to figure out SPI operation in the Microchip C Compiler. As I
understand it, writing outgoing data to SSPBUF causes that data to be
loaded into  SSPSR, which then shifts it out. As data is being shifted
out, input data is being shifted in to SSPSR. On completion of the shift
in and out, the received data in SSPSR is put in SSPBUF so it can be
read. So far so good.
       Looking at the C compiler library documentation on the SPI library, it
LOOKS like BOTH WriteSPI and ReadSPI initiate an SPI bus cycle. It seems
to me that only WriteSPI should do that. ReadSPI would then pick up the
data received during the previous write. How does this actually work?
Actually, I could imagine a function called SPIrw that would have a
prototype of

unsigned char SPIrw (unsigned char DataToSend)

You'd pass it the data to send and it would return the received data.
But, that doesn't seem to be how it works.  So, how DOES it work?

Thanks!

Harold



FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com


________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
dl.http://www.juno.com/get/web/.

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


2002\05\16@163459 by Harold M Hallikainen

picon face
Still trying to figure out the Microchip C compiler libraries for SPI.
I'm successfully sending stuff to shift registers and reading stuff from
shift registers. Next job is a full SPI with simultaneous shift out and
in. Anyone used Microchip libraries for this? The problem is that it
APPEARS (according to the documentation) that BOTH WriteSPI and ReadSPI
initiate an SPI bus cycle.  So, if I write something out, then read, it
seems as though the read is from a second bus cycle (which sent something
out to the SPI device also). So, should I just do writes, then read the
input from the SSPBUF after DataRdySPI goes true?

Anyone doing SPI with these libraries?

THANKS!

Harold


FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com


________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
dl.http://www.juno.com/get/web/.

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


2002\05\17@032520 by Alan B. Pearce

face picon face
>The problem is that it APPEARS (according to the documentation)
>that BOTH WriteSPI and ReadSPI initiate an SPI bus cycle.

I have not used SPI, but if I remember correctly from my perusal of the
documentation, to read a character from the SPI, it does a dummy write. The
SPI hardware then thinks it is writing a byte out to the bus, and so
generates clocks which are actually reading in a byte. The apparent write is
needed for the clock generation to occur.

I have done this trick on other hardware I was involved with for this exact
reason, it was the only way to make the clock generation circuit work
correctly.

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


2002\05\17@042436 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,
an SPI *read* is performed by a dummy *write* ( normally sending 0x00 ).

It doesn't really matter as you have dedicated lines for DIN and DOUT.
However if using s/w spi make sure that the DOUT line does not contain
any 'valid' data when reading, normally all 0's is ok.

/Tony

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


2002\05\20@160142 by Harold M Hallikainen

picon face
       Since I was concerned about the read doing another SPI cycle, I just
went right to the register using code like this:

 WriteSPI(ToExtSpi2.byte);             // Send the next byte
 while(!DataRdySPI());                 // Loop until data ready
 FromSpi2.byte=SSPBUF;                 // Read the next byte

       Seems to work. I've got it talking to a Maxim MAX3100.

Thanks for the help!

Harold


On Fri, 17 May 2002 08:23:52 +0100 "Alan B. Pearce" <.....A.B.PearceKILLspamspam@spam@RL.AC.UK>
writes:
{Quote hidden}

FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com


________________________________________________________________
GET INTERNET ACCESS FROM JUNO!
Juno offers FREE or PREMIUM Internet access for less!
Join Juno today!  For your FREE software, visit:
dl.http://www.juno.com/get/web/.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


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