Searching \ for 'newbie SPI hardware use question' 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/io/serial/spis.htm?key=spi
Search entire site for: 'newbie SPI hardware use question'.

Truncated match.
PICList Thread
'newbie SPI hardware use question'
2000\04\06@004449 by Ben Langhals

flavicon
face
I'm using a PIC 16F876's SSP module to realize SPI communication.  I use
the following code to initialize all the registers (I think)

;  Initialize SPI registers

SPI Initial
       bcf     TRISC, 5                        ; Enable SDO
       bcf     TRISC, 3                        ; SCK in Master mode
       bsf     SSPCON, SSPEN   ; enable synchronous serial port
       bsf     SSPCON, CKP             ; SCK will idle high
       bcf     SSPCON, SSPM3   ; last 4 bits of SSPCON clear for SPI master mode with
SCK = Fosc / 4
       bcf     SSPCON, SSPM2
       bcf     SSPCON, SSPM1
       bcf     SSPCON, SSPM0
       bcf     SSPCON, WCOL
       bcf     SSPCON, SSPOV
       bsf     SSPSTAT, SMP    ; input data sampled at end of output line
       bsf     SSPSTST, CKE            ; CPK = 1 and data transmitted on falling edge of SCK
       retrun

Now to perform a write to the SPI bus is all I have to do is this? (where
txdata is the 8 bit word I want to write)

bcf             status, rp0     ; specify Bank0
movf            txdata, w       ; w reg holds contents of txdata
movwf           sspbuf          ; new data to xmit

I know it can't be that simple

2000\04\07@124825 by Snail Instruments

flavicon
face
The init sequence can be shortened like:

       movlw   1<<smp|1<<cke
       movwf   sspstat
       movlw   1<<sspen|1<<ckp
       movwf   sspcon

The output routine should check if the previous byte has been shifted out
(but in your particular case the SPI clock is fast enough and so it is
unlikely that you manage somehow to overwrite previous data).

       bcf     status, rp0     ; specify Bank0
       btfss   pir1,sspif
       goto    $-1
       movf    txdata, w       ; w reg holds contents of txdata
       movwf   sspbuf          ; new data to xmit
       bcf     pir1,sspif

Josef

>;  Initialize SPI registers
>
>SPI Initial
>        bcf     TRISC, 5                        ; Enable SDO
>        bcf     TRISC, 3                        ; SCK in Master mode
>        bsf     SSPCON, SSPEN   ; enable synchronous serial port
>        bsf     SSPCON, CKP             ; SCK will idle high
>        bcf     SSPCON, SSPM3   ; last 4 bits of SSPCON clear for SPI
master mode with
>SCK = Fosc / 4
>        bcf     SSPCON, SSPM2
>        bcf     SSPCON, SSPM1
>        bcf     SSPCON, SSPM0
>        bcf     SSPCON, WCOL
>        bcf     SSPCON, SSPOV
>        bsf     SSPSTAT, SMP    ; input data sampled at end of output line
>        bsf     SSPSTST, CKE            ; CPK = 1 and data transmitted on
falling edge of SCK
>        retrun
>
>Now to perform a write to the SPI bus is all I have to do is this? (where
>txdata is the 8 bit word I want to write)
>
>bcf             status, rp0     ; specify Bank0
>movf            txdata, w       ; w reg holds contents of txdata
>movwf           sspbuf          ; new data to xmit

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