SPI programming - Write data to SPI


1. Add a new SPI
  1. Select "Application" tab.

  2. Add script as follows in order to add a new SPI.

      
    clear
    
    SPI    spi1
    	/ChipSelect_Port:11
    	/ChipSelect_ActiveState:false
    	/ChipSelect_SetupTime:1
    	/ChipSelect_HoldTime:1
    	/Clock_IdleState:true
    	/Clock_Edge:false
    	/Clock_RateKhz:15000
    	/SPI_Module:SPI1
    
      
 

  1. Click "Send to MF Application" button or Press "F5" key.

  2. Executed result:




2. Write ushort data to SPI
  1. Use "Write(ushort data)" method to send ushort data to SPI.

  2. In order to create ushort typed variable, use "Util.ToUShort(object)" method.

  3. Select "Log" tab.

  4. Check "Display hex format for the SPI data"



  5. Select "Application" tab.

  6. Add script as follows.

      
    data = Util.ToUShort(0xB0A0)
    
    spi1.Write(data)
    
      


  7. Click "Send to MF Application" button or Press "F5" key.



  8. Emulator will log received data through SPI into log list. You can check this log from the Log tab.

  9. Select "Log" tab.

  10. Executed result:




3. Write byte data to SPI
  1. Use "Write(byte data)" method to send byte data to SPI.

  2. In order to create byte typed variable, use "Util.ToByte(object)" method.

  3. Select "Application" tab.

  4. Add script as follows.

      
    data = Util.ToByte(0xA0)
    
    spi1.Write(data)
    
      


  5. Click "Send to MF Application" button or Press "F5" key.



  6. Emulator will log received data through SPI into log list. You can check this log from the Log tab.

  7. Select "Log" tab.

  8. Executed result: