| |
SPL SPI programming - Read data from the SPI bus
This tutorial is continued from the previous tutorial.
5. 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.
- Add below script on the emulator's 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 "Send Script" button to send SPL script to emulator.
6. Read data from the SPI bus
- You can read data from bus by using below method.
spiname.WriteRead(byte wdata, byte[] rbuff)
spiname.WriteRead(ushort wdata, ushort[] rbuff)
spiname.WriteRead(byte[] wbuff, byte[] rbuff)
spiname.WriteRead(ushort[] wbuff, ushort[] rbuff)
- Add below script to read data from the bus on the MF Application's editor panel.
| |
wdata = Util.ToUShort(0x4040)
rBuff = Util.CreateArrayUShort(1)
spi1.WriteRead(wdata, rBuff)
print "SPI Read Data -> " + Util.UShortsToHex(rBuff)
| |
|
- Click "Send Script" button to send SPL script to emulator.
7. Executed result
- Executed result will be shown as follows.
|