The help contains a lot of info about SPI. But what most people do not get is that SPI works with a master and slave. Only the master can initiate transactions. And the slave can only respond to the master.
This means that you can only tell a slave what to do. When you want to read data from a slave, you first need to inform the slave that you want to retrieve data. So you need some protocol.
But let us go one step back : the master and slave form a 16 bit shift register. this means that when you shift/send out a value from the master, you read back the value that was in the slave.
So if you want to make a slave that will increase a byte value that it receives by 1, and send that back you would do this :
Master : send byte with value of 100
Slave : contains a value for example 0 and will send this back to the master.
Master : receives the value 0 from the slave.
Slave : now has receives the value from the master with value 100. So now slave can increase this value with 1 so it becomes 101.
Master : need to send a dummy value of say 0 so it will get back the value from the slave.
Slave : send back 101 to master.
Master now has value 101.
To test things use the sendspi.bas sample from the samplesSPI and spi-slave.bas from samplesSPI.
Do take care not to use STK200. it has some internal connections that does make it fail.
When it works using the SPI hardware you could make a next step to using the soft version.
↧