| |
SPI programming - WriteRead data to SPI
1. Define procedure on the emulator's side
- In order to read data from SPL, you should call "WriteRead()" method. This method send data to SPL and read data at the same time.
- "WriteRead" method of SPI will request to device (or emulator) to read data so you need to define correspond procedure on the emulator.
- First, add some logic on the emulator side.
- Select "Emulator" tab.
- Add below script on the editor box.
| |
BindSPIComponent
/Id:spi1
/Procedure_OnWrite:proc1
procedure proc1
print "OnReadRequested: " + value.Length + " bytes"
data = Util.ToUShort(0xA1A2)
spi1.SetReadBuffer(data)
end
| |
|
|
|
|
- Above procedure will return ushort data (0xA1A2) to application when it receives "Read" request from application.
- Click "Execute Script on the Emulator" button or Press "F5" key.
- Executed result:
2. WriteRead ushort data from SPI
- Use "WriteRead(ushort wdata, ushort[] rbuff)" method to read ushort data from SPI.
- "WriteRead" method will request to device (or emulator) to read data so you need to define correspond procedure on the emulator.
- Select "Application" tab.
- Add below script on the editor box.
| |
wdata = Util.ToUShort(0x00A0)
rbuff = Util.CreateArrayUShort(1)
spi1.WriteRead(wdata, rbuff)
data = rbuff[0]
print data
print Util.UShortToHex(data)
| |
|
- Util.UShortToHex(ushort) method was used to convert ushort data into string of hex format.
- Click "Send to MF Application" button or Press "F5" key.
- Executed result:
|