Searching \ for '%SPI,%' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: massmind.org/techref/io/serial/spis.htm?key=spi
Search entire site for: 'SPI,'.

Sub string match.
PICList Thread
'implementing SPI, QSPI, or Microwire interfaces'
1996\10\02@222058 by Gerry Smith

flavicon
face
Hello,
I need to implement a SPI, QSPI or Microwire interface with a pic16cxx
and was wondering if anyone had any information/source code on it?
Thanks for the help.

1996\10\03@032606 by Herve Cousin

flavicon
face
At 22:19 02.10.96 -0400, you wrote:
>Hello,
>I need to implement a SPI, QSPI or Microwire interface with a pic16cxx
>and was wondering if anyone had any information/source code on it?
>Thanks for the help.
>
>
Hi Gerry,

Have a look at the application notes-page of Microchip, especially under
"Serial EEPROMS TUTORIALS AND APPLICATION NOTES" with SPI and IIC (with
source code):

http://www.microchip2.com/appnotes/appnotes.htm

Regards,

Herve
Herve R. Cousin - Inorganic Analytical Chemistry,
Federal Institute of Technology (ETH-Z)
CH-8092 Zurich, Switzerland
Tel.:    + 41-1-632-4472, Fax:     + 41-1-632-1090,
spam_OUTcousinTakeThisOuTspaminorg.chem.ethz.ch, http://www.analytica.ethz.ch/cousin.html

1996\10\03@195604 by Gael Waiche

picon face
Hi Gerry. I've got those routines implementing the SPI bus.
They come from the Microchip server.

I hope they will be of some use.

Regards

Gael



; Filename: ADVSPI.ASM
; **********************************************
; * Advanced Seminar Sample File               *
; * Revision: 1.0                              *
; * Date      Feb 6, 1996                      *
; **********************************************
;
****************************************************************************
; * This program shows examples of SPI transmission and reception
   *
;
****************************************************************************
       LIST     P=16C74,F=INHX8M,R=DEC       ; Set processor to 16C74
       #INCLUDE C:/MPLAB/P16C74.INC ; Include processor INC file
       __CONFIG _XT_OSC&_WDT_OFF&_CP_OFF     ; Set up config bits
       __IDLOCS 5678                         ; Set up ID locations
       ERRORLEVEL 1,-302                     ; Turn OFF message ID 302

COUNT           EQU     20h     ; Location of count variable to count
bits
SPIDATAL        EQU     21h     ; Location of SPI low byte data
SPIDATAH        EQU     22h     ; Location of SPI high byte data
#define         DOUT    PORTA,0 ; SPI port DOUT signal
#define         CS      PORTA,1 ; SPI port CS signal
#define         SCLK    PORTA,2 ; SPI port SCLK signal
#define         DIN     PORTA,3 ; SPI port DIN signal

       ORG 0
       clrf    PORTA           ; Clear output latch register
       bsf     STATUS,RP0      ; Switch to bank 1
       movlw   b'11111000'     ; Place PORTA direction data into W
       movwf   TRISB           ; Set RA0-2 outputs, RA3 input
       movlw   7               ; Place 7 into W
       movwf   ADCON1          ; Make RAX digital inputs
       bcf     STATUS,RP0      ; Switch to bank 0
mainloop
       movlw   b'01010101'     ; Place alternating 1 and 0 into W
       movwf   SPIDATAL        ; init SPI data low register
       movlw   b'00001111'     ; Place 00001111 into W
       movwf   SPIDATAH        ; init SPI data high register
       call    spidataio       ; Send/receive SPI data
       goto    mainloop        ; Jump back and do it again!

;**************************************************
;* 16 bit SPI serial I/O xmit and receive routine *
;* Data to Transmit:     ADRESL, ADRESH           *
;* Data to Receive:      ADRESL, ADRESH           *
;* Time = (13 * 16) + 7 = 215 cycles              *
;**************************************************
spidataio
       movlw   .16             ; Place bit count value into W
       movwf   COUNT           ; W -> COUNT for counting bits
       bcf     CS              ; Select the SPI device
loopspidata
       bcf     STATUS,C        ; Assume we are receiving a ZERO from SPI
device
       btfsc   DIN             ; Skip if we are receiving a ZERO from
SPI device
       bsf     STATUS,C        ; Receive a ONE from the DIN line
       rlf     SPIDATAL,F      ; Rotate received bit into Low digit
       rlf     SPIDATAH,F      ; Rotate high digit, place xmiit bit into
carry
       bcf     DOUT            ; Assume we are transmitting a ZERO to
SPI device
       btfsc   STATUS,C        ; Skip if we are senDOUTg a ZERO to SPI
device
       bsf     DOUT            ; Transmit a ONE onto the DOUT line
       bsf     SCLK            ; Clock in the DOUT output
       bcf     SCLK            ; Lets get ready to clock the next digit!
       decfsz  COUNT,F         ; Skip if we have XMIT/RCV all 16 bits
       goto    loopspidata     ; Not done yet so loop back for next bit
       bsf     CS              ; De-select the SPI device
       return                  ; DONE receiving/xmiting - GO HOME!

   END


'[PICLIST] clock SPI, get me crazy !'
2002\01\31@065758 by Vasile Surducan
flavicon
face
Sorry for bothering you, but I'm feeling so annoyed !
I don't understood from pic archive examples and data sheet if
master clock is generated automaticaly by the MSSP module or not.
My first thought was yes. I understood that 8 bites of data can be
transmitted synchronously with clock pulses.
I'm trying to initiate a communication using master1 mode, the
sspstat = 0b_0000_0000 and sspcon = 0b_0010_0010 are set appropiate
for fosc/64. The pins used are rc3 ( spi-clk ) and rc4 ( spi-data in )
and an extra pin for chip select, all direction are set correct in
TRIS register.

According to data sheet:
" In master mode the data is transmitted/received as soon as the
SSPBUF register is written to " and:
"The master can initiate the data transfer at any time because it
controls the SCK "

My device ( MAX121 ) is connected to receive clocks from PIC and to
deliver data's as soon as the chip select ( or convst ) is tied to gnd.
But how can be determined MSSP to send clocks ? ( I don't want to use
slave mode ). And I don't saw any damn clock on to my scope...

Thank you in advance,
Vasile

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


2002\01\31@091723 by Thomas C. Sefranek
face picon face
Vasile Surducan wrote:

>Sorry for bothering you, but I'm feeling so annoyed !
>I don't understood from pic archive examples and data sheet if
>master clock is generated automaticaly by the MSSP module or not.
>
It certainly is!  (At least it works for me!)

{Quote hidden}

RC3 = 0?

>
>According to data sheet:
>" In master mode the data is transmitted/received as soon as the
>SSPBUF register is written to " and:
>"The master can initiate the data transfer at any time because it
>controls the SCK "
>
True!

>
>My device ( MAX121 ) is connected to receive clocks from PIC and to
>deliver data's as soon as the chip select ( or convst ) is tied to gnd.
>But how can be determined MSSP to send clocks ?
>
You send a dummy byte to the SSPBUF,
(Making sure there is no collision with any previousls sent byte.)
the SPI sends the dummy byte AND clocks and clocks in data from the
slave. (MAX121)

{Quote hidden}

--
 *
 |  __O    Thomas C. Sefranek  .....tcsKILLspamspam.....cmcorp.com
 |_-\<,_   Amateur Radio Operator: WA1RHP
 (*)/ (*)  Bicycle mobile on 145.41, 448.625 MHz

ARRL Instructor, Technical Specialist, VE Contact.
hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org

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


2002\01\31@100612 by Jennifer Loiacono

flavicon
face
> I don't understood from pic archive examples and data sheet if
> master clock is generated automaticaly by the MSSP module or not.

Yes, it is.  As you said, when data is placed in SSPBUF, the module clocks
it out automatically.

BUT

Make sure the data directions are set properly in the TRIS registers.  The
clock line MUST be set as output (0).

Jen

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



'[PICLIST] clock SPI, get me crazy !'
2002\02\01@023958 by Vasile Surducan
flavicon
face
I have no ideea were was stuck this message so I'll post again,
please take a look and tell me your ideeas about what is wrong here...
{Quote hidden}

sending dummy data, but then how can be readed incoming datas ?
( I don't want to use slave mode ).
 And I don't saw any damn clock on to my scope...
>
> Thank you in advance,
> Vasile
>
>

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



'[OT]: SPI, I2C and MicroWire, please help'
2002\08\05@052952 by mpavlica
flavicon
face
Hello!
I am developing simple eeprom programmer for 8pin devices
Is there any avaiable on internet to download source code (or controls,
DLLs, doesnt matter) for sending those protocols to LPT port?
I have source for I2C, and SPI but, for MicroWire, could not find anything.
I still do not know what prog. language will use (VB or Delphi) - depend
what kind of libraries i will find for those protocols.
Or, maybe, is there anyone who wish to help me, to write DLL files?
I am just hardware designer, and software is my weak side :(
THANKS IN ADVANCE!
Milan Pavlica YU7XW
student of electrotenics

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



'[PIC] hardware SPI, problem optimizing'
2007\11\21@120142 by Edson Brusque
face
flavicon
face
Hello,

    the usual way of having a sendSPI() function is something like:

#asm
       MOVF   SSPBUF,W        // Discard received data in buffer and
                               //    clear SSPSTAT_BF
       MOVFF  spiData,SSPBUF  // Put data to send on buffer
                               //    and start sending
       loopssp:
       BTFSS  SSPSTAT_BF      // If there's not received byte
                               //     in buffer (transmit completed)
       BRA    loopssp         // loop
#endasm

    This is working perfectly as it should, but my data sending routine
does this:

    calculateByteToSend()
    sendSPI()
    calculateByteToSend()
    sendSPI()
    calculateByteToSend()
    sendSPI()
    calculateByteToSend()
    sendSPI()
    etc...

    Of course, this isn't very efficient because the PIC waits to send
the data when it would be calculating the next byte, so I tried:


#asm
       loopssp:
       BTFSS  SSPSTAT_BF      // If there's not received byte
                               //     in buffer (transmit completed)
       BRA    loopssp         // loop

       MOVF   SSPBUF,W        // Discard received data in buffer and
                               //    clear SSPSTAT_BF

       MOVFF  spiData,SSPBUF  // Put data to send on buffer
                               //    and start sending
#endasm

    But, the PIC hands after some transmits. Can anyone tell me what
I'm doing wrong?

    Best regards,

    Brusque

--
---------------------------------------------------------------------
Edson Brusque                    Stagetronics Eletro Eletrônicos Ltda
Research and Development                   Blumenau  -  SC  -  Brazil
http://www.ryan.com.br/netiqueta.htm             http://www.citronics.com.br
---------------------------------------------------------------------

2007\11\21@122827 by M. Adam Davis

face picon face
Looks ok for the part you gave - might want to post your schematic
and/or setup code as well (interupts, SPI, etc)

I'd look at placing a timout on the receive part - if you don't get a
received byte in 2x the length of time it should have finished in,
return an error.  In theory it shouldn't happen, but the reality is
much more complex.

Also, check the other flags.

Where exaclty in the code does it hang?

-Adam

On 11/21/07, Edson Brusque <@spam@brusque.listasKILLspamspamcitronics.com.br> wrote:
{Quote hidden}

>

2007\11\21@130044 by Edson Brusque

face
flavicon
face
Hello M. Adam,

> Looks ok for the part you gave - might want to post your schematic
> and/or setup code as well (interupts, SPI, etc)

       setup_spi (SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4);

       SSPCON1_CKP = 1; // Idle state for clock is a high level
       SSPSTAT_CKE = 0; // Transmit occurs on transition from Idle
                         // to active clock state

> I'd look at placing a timout on the receive part - if you don't get a
> received byte in 2x the length of time it should have finished in,
> return an error.  In theory it shouldn't happen, but the reality is
> much more complex.

    Actually, it's a really simple setup. The PIC just send data over
SPI to a slave. The PIC doesn't receive data and doesn't needs to check
anything from the slave. It just keeps sending data over and over.

    With the cheking just after the "SSPBUF = dmData;" line it works
perfectly. Putting it just before, the PIC hangs.

> Also, check the other flags.

    Wich flags? I've tried to make it checking the SSP interrupt flag,
no sucess either.

> Where exactly in the code does it hang?

    I don't have a debugger (working) so I can't tell but it seens that
it hangs on the BF check loop.

    The code between the sendSPI() calls just read a byte from a table,
gets a code from another table and makes some bit manipulation,
calculating the value to be sent by SPI. Interrupts are not utilized in
this application.

    Best regards,

    Brusque

--
---------------------------------------------------------------------
Edson Brusque                    Stagetronics Eletro Eletrônicos Ltda
Research and Development                   Blumenau  -  SC  -  Brazil
http://www.ryan.com.br/netiqueta.htm             http://www.citronics.com.br
---------------------------------------------------------------------


'[PIC]I2C, SPI, etc.'
2010\02\15@214956 by Jason Hsu
picon face
>From what little I understand so far, I2C and SPI are standards for
programming microcontrollers IN their target circuits.  For obvious
reasons, avoiding the need to swap the microcontroller back and forth
between the target circuit and a programmer like the PICSTART PLUS is
essential for surface mount microcontrollers.

Is there a list of all of these in-circuit programming/emulating
methods used for surface mount microcontrollers?  How do you decide
which standard to use?  What type of connector/cable do you normally
use to connect the computer to the embedded circuit?  How do you
recommend getting started?  (So far, all of my experience has been
with through hole microcontrollers programmed with the PICSTART PLUS.)

--
Jason Hsu
http://www.jasonhsu.com/swrwatt.html
http://www.jasonhsu.com/swrwatt-c.txt
http://www.jasonhsu.com/swrwatt-asm.txt

2010\02\15@220624 by Matt Callow

flavicon
face
Hi Jason,

I2C and SPI are not generally used to program a PIC micro. For that
you would normally use ICSP (In-Circuit Serial Programming) (or
possibly JTAG).
See http://ww1.microchip.com/downloads/en/DeviceDoc/30277d.pdf for info on ICSP.

I2C and SPI are often used to communicate between the PIC micro and
other components in the circuit (e.g. real-time clock, ADC, EEPROM
etc)

Matt

On 16 February 2010 13:49, Jason Hsu <KILLspamjhsu802701KILLspamspamgmail.com> wrote:
{Quote hidden}

>

2010\02\16@041357 by William \Chops\ Westfield

face picon face

On Feb 15, 2010, at 7:06 PM, Matt Callow wrote:
>
> On 16 February 2010 13:49, Jason Hsu <RemoveMEjhsu802701TakeThisOuTspamgmail.com> wrote:
>>> From what little I understand so far, I2C and SPI are standards for
>> programming microcontrollers IN their target circuits.

SPI and I2C are standards for short range serial communications.  
They're NOT directly "for" "In Circuit Programming" (Let's call it  
ICP) of microcontrollers, although they presumably COULD be used for  
such purposes.   ICP of Atmel AVRs uses SPI, I believe, for example.  
I don't think that PIC ICP is either one, exactly...
>
> I2C and SPI are not generally used to program a PIC micro. For that
> you would normally use ICSP (In-Circuit Serial Programming) (or
> possibly JTAG).
> See http://ww1.microchip.com/downloads/en/DeviceDoc/30277d.pdf for  
> info on ICSP.
>

Yeah.

>> Is there a list of all of these in-circuit programming/emulating
>> methods used for surface mount microcontrollers?  How do you decide
>> which standard to use?  What type of connector/cable do you normally
>> use to connect the computer to the embedded circuit?  How do you
>> recommend getting started?  (So far, all of my experience has been
>> with through hole microcontrollers programmed with the PICSTART  
>> PLUS.)

For any particular microcontroller, you probably don't have a choice.  
You do whatever the manufacturer tells your to, generally using a  
manufacturer-specified connector (or two or three) and a manufacturer-
provided programmer or compatible.  For Microchip parts there are  
several programmers that support their ICSP protocol, including the  
ICD2, Pickit2, and pickit3.  Plus programers form other vendors.  You  
have to go out looking for a programmer than supports ICSP on your  
particular chip, rather than just one that supports a low-level  
protocol like SPI or I2C.

BillW

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