You've attached code for an SPI MASTER. I was asking about an SPI SLAVE. If you have matching SPI slave code that works with your bit-banged master clock pulse I'd like to take a look. In any case, the answer for me is simple. I just needed to slow the master clock down enough so my inefficient C code slave could process each in/out bit within the clock period. I did this by configuring the master to use TMR2 as a timing source. I was more interested in learning the protocol than making it fast. --- Michael Rigby-Jones wrote: > > -----Original Message----- > > From: Rick Regan [SMTP:rdrdr2k@YAHOO.COM] > > Sent: Friday, June 27, 2003 4:04 PM > > To: PICLIST@MITVMA.MIT.EDU > > Subject: Re: [PIC]: SPI clock pulse width > > > > In this case I am writing the slave (on another > > PIC16F877), so I think I need to know the width. > > I want to make sure I can detect the pulse by > polling, > > and send/receive the data before the next pulse. > > It looks like in order to do that, I need to set > the > > master's clock rate high enough. > > > SPI is (usualy) a static bus that can work down to > DC (although this does > depend on the slave, check the datasheet). The only > things you have to worry > about are the maximum clock speed of your slave, and > the setup/hold times > for the clock and data. Writting a software SPI > peripheral is really quite > easy, far simpler than say I2C. A short snippet > from a function I wrote a > while back in C: > > #define SDO LATB0 // use latch > register on 18 series to avoid > RMW problems > #define SCK LATB1 > #define SDI RB2 > #define SPI_HI 1 > #define SPI_LO 0 > > uchar ucSpiIn = 0x00; > > SDO = (ucSpiOut & 0x80)? SPI_HI : SPI_LO; > // test first bit > and set SDO > NOP(); // delay to > allow data to stabilise > before clocking > SCK = SPI_HI; > // clock high > if(SDI) ucSpiIn |= 0x80; > // > check SDI and set relevant bit in ucSpiIn > SCK = SPI_LO; > // clock low > > SDO = (ucSpiOut & 0x40)? SPI_HI : SPI_LO; > // repeat for each > bit .... > NOP(); > SCK = SPI_HI; > if(SDI) ucSpiIn |= 0x40; > SCK = SPI_LO; > > ... > > It used to be in a loop which I unrolled to get a > higher speed, purely in > the interests of saving time rather than any slave > requirements. This > emulates the PIC's MSSP module by reading in a bit > for each bit output. If > you have no requirement for this you can ignore the > reading part. This > should be very easy to translate to assembler: > > #define SDO PORTB,0 > #define SCK PORTB,1 > #define SDI PORTB,2 > > movlw 0 ; clear w > > btfsc SpiOut,7 ; check most > significant bit and set data > line accordingly > bsf SDO > btfss SpiOut,7 > bcf SDO > nop ; > you will need at least one > NOP here for reliable operation > ; on > 16 series if clock and > data are on the same port. > bsf SCK ; Set clock > high. May need a NOP > after this for slow > ; > SPI devices or fast PICs, > check datasheet! > btfsc SDI ; check data > in pin... > iorlw 0x80 ; and set relevant > bit in W > bcf SCK ; clock low > > Repeat for the next 7 bits, of if code space is > tight put it into a loop. > For SPI devices that require 16/24 bits simply call > function multiple times. > > 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 postmaster@bookham.com. > > -- > http://www.piclist.com hint: The list server can > filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics