Loading...
 
Skip to main content

System Workbench for STM32


switch case statement within SPI interface

Given that the slave only exchanges values with the master when the master says so, the process is along the lines of:
- wait until the master sends the command (this might require sending back a "no value" value such as 0 or 0xff or something that the protocol you define says "ignore this value")
- read the command value that the master has sent you - you can then use 'if' or 'switch' statements depending on how many commands there are
- get the appropriate value and load it into the SPI buffer
- wait again until the master does another exchange
- throw away the received value or interpret it as the next command (whatever the protocol you have devices says)
- repeat the above
Of course you need to do all of this before the master requests the 2nd exchange. If this is not possible, then you can either use additional GPIO lines to let the master know when the data is ready or load up the SPI buffer with the "ignore this value" value so that the master knows that the slave has not yet completed and that it will keep trying until it does get a valid value.
This is all part of the protocol you need to define.
Susan