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
  1. 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.

  2. "WriteRead" method of SPI will request to device (or emulator) to read data so you need to define correspond procedure on the emulator.

  3. First, add some logic on the emulator side.

  4. 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
    
      


  5. Above procedure will return ushort data (0xA1A2) to application when it receives "Read" request from application.

  6. Click "Send Script" button to send SPL script to emulator.




6. Read data from the SPI bus
  1. 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)

  2. 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)
    
      


  3. Click "Send Script" button to send SPL script to emulator.



7. Executed result
  1. Executed result will be shown as follows.