To use this file copy and paste this:
// #URL-lib "http://pin1.org/forthlib/flb/General/SPI.flb" into BV Terminal 3
or here to download.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// SPI - This is the basic interface for SPI which has a very simple
// method of working. There is a data in, data out and chip select
// when data is going in, data is also comming out so if just data out is
// wanted then a dummy data in is sent.
// CS is hardware / device dependant and can be any port set to o/p normally
// a high hill select the device
// REQUIRES:
// #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb"
// #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb"
// CONSTANTS:
// SPI registers
&E0020000 constant S0SPCR // config
&E0020004 constant S0SPSR // status
&E0020008 constant S0SPDR // data
&E002000C constant S0SPCCR // clock
&E002001C constant S0SPINT
variable inital
Full Contents of File
&E0020000  constant  S0SPCR     
&E0020004  constant  S0SPSR     
&E0020008  constant  S0SPDR     
&E002000C  constant  S0SPCCR   
&E002001C  constant  S0SPINT
variable  inital
: set-speed 
    pclk  swap 
    -1  inital  !
;   
: init
        &20  S0SPCR  !       
        inital  @  0=  if  254  S0SPCCR  !  then     
        4  1  pinselect     
        5  1  pinselect     
        6  1  pinselect     
;
: <0>spi
        S0SPDR  !       
        0
        100  for
                S0SPSR  @  &80  and
                if  drop  -1  leave  then
          next
          if 
                S0SPDR  @
          else
                ."  SPI  problem"  abort
          then
;
: <0>spi.initinit  ;
: <0>spi.speed  set-speed  ;