SPL I2C device programming - How to start I2C device programming


1. Re-launch SPL emulator
  1. if SPL emulator is running, please terminate emulator.

  2. Press "F5" key to re-launch SPL emulator on the editor.



  3. Clear log on the log list.

  4. Check the checkbox named "Display hex format for the I2C data" on the Log tab.



2. Add "I2CDevice" command
  1. SPL MF Emulator provides 10 I2C devices.
    1. Id: i2c1 ( Address: 58 )
    2. Id: i2c2 ( Address: 60 )
    3. Id: i2c3 ( Address: 62 )
    4. Id: i2c4 ( Address: 64 )
    5. Id: i2c5 ( Address: 66 )
    6. Id: i2c6 ( Address: 68 )
    7. Id: i2c7 ( Address: 70 )
    8. Id: i2c8 ( Address: 72 )
    9. Id: i2c9 ( Address: 74 )
    10. Id: i2c10 ( Address: 76 )

  2. Double click "I2CDevice" item on the tree.



      
    I2CDevice    i2c1
    	/Address:58
    	/ClockRateKhz:100
    
      


  3. You can change the id and address of I2C device.



3. Add simple logic to send data to I2C device
  1. You can send data to device by using below method.

       devicename.Write(string text)
       devicename.Write(string text, int timeout)
       devicename.Write(byte[] buff)
       devicename.Write(byte[] buff, int timeout)

  2. Add lines to send data to device as follows.



      
    I2CDevice    i2c1
    	/Address:58
    	/ClockRateKhz:100
    
    buff = Util.CreateArrayByte(2)
    buff[0] = 0xA0
    buff[1] = 0xB0
    
    i2c1.Write(buff)
    
      


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



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




5. Read data from the I2C device
  1. Continued in the next tutorial.