Thanks for the overview. It leads me to another question. These both PICs need to be able to initiate communications. Since the master is the one running the show, can I switch from slave to master mode and start talking? Would it be simpler to dedicate the needed number of pins on each PIC, and have them pass info back and forth just using bit status? Thanks, Jim -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Harold Hallikainen Sent: Tuesday, March 02, 2004 10:40 To: PICLIST@MITVMA.MIT.EDU Subject: Re: [PIC:] overview of spi A quick summary on SPI. The master is in control of the SPI communications and generates clock. It can talk to multiple slave devices. To talk to a slave device, the master pulls the chip select for that device low (using a general purpose output pin on the PIC). You then dump data into the SSPBUF. This clocks the data out to the slave and simultaneously clocks some data back from the slave. When the shifting of data is done, the BF bit in SSPSTAT is set. You can pull the data out of SSPBUF and put new data in if you need to do more than 8 bits. If not, force the chip select high. I generally write an "ExchangeData" routine for SPI devices. You pass in the data to be sent to the device and it returns the data that came back. I then interpret the data outside that. Here's some C code to talk to a Maxim MAX3100 SPI UART. This actually has a couple global buffers where bits are set and cleared, data pulled out, or whatever, before and after the Exchange function. Note also that SPI has various modes as to whether the clock idles high or low, whether data is shifted on positive or negative edges, and what clock edge the incoming data is sampled on. I end up comparing the serial waveforms in the PIC datasheet with the waveforms on the SPI device and configure the PIC accordingly, finally looking at the serial data on a scope to see if I got it right. Good luck! Harold void ExchangeU19(void){ // Puts data from ToU19h and ToU19l into U19 while putting data from U19 into FromU19h and FromU19l. OpenSPI(SPI_FOSC_4, MODE_00, SMPMID); // Open the spi LATFbits.LATF7=0; // chip select low WriteSPI(ToU19h.byte); // Send the high byte while(!DataRdySPI()); // Loop until data ready FromU19h.byte=SSPBUF; // Read the high byte WriteSPI(ToU19l.byte); // Send the low byte while(!DataRdySPI()); // Wait until data ready FromU19l.byte=SSPBUF; // and read the low byte LATFbits.LATF7=1; // chip select high CloseSPI(); } -- FCC Rules Online at http://www.hallikainen.com -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads