'------------------------------------------------------------------
'                           SENDSPI.BAS
'                          (c) MCS Electronics
' sample shows how to create a SPI MASTER
'Use together with spi-slave.bas
'------------------------------------------------------------------
' Tested on the STK500. The STK200 will NOT work.
' Use the STK500 or another circuit
' connect MISO, PB6(pin 7) to slave MISO
'         MOSI, PB5(pin 6) to slave MOSI
'         CLOCK,PB7(pin 8) to slave CLOCK
'         SS,   PB4(pin 5) to slave SS


$regfile = "8515def.dat"
$crystal = 3680000
$baud = 19200

'config the SPI in master mode.The clock must be a quarter of the slave cpu
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 128

'init the spi pins
Spiinit

Dim B As Byte , Bfromslave As Byte

Do
  'send 1 byte
  Bfromslave = Spimove(b)
  Print Bfromslave ; " received from slave"
  'as an alternative you can send data and display the last received value
  '  Spiout B , 1
  '  Print Spdr ; " received from slave"
  Wait 1
  B = B + 1
Loop
End