I2C device programming - Write data to I2C device


1. Add a new I2C device
  1. Select "Application" tab.

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

      
    clear
    
    I2CDevice    i2c1
    	/Address:58
    	/ClockRateKhz:100
    
      
 

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

  2. Executed result:




2. Write byte[] data to I2C device
  1. Use "Write(byte[] buff)" method to send byte array data to I2C device.

  2. In order to create byte array, use "Util.CreateArrayByte(length)" method.

  3. Select "Log" tab.

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



  5. Select "Application" tab.

  6. Type script as follows.

      
    buff = Util.CreateArrayByte(4)
    buff[0] = 0xA0
    buff[1] = 0xA1
    buff[2] = 0xA2
    buff[3] = 0xA3
    
    i2c1.Write(buff)
    
      


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



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

  9. Select "Log" tab.

  10. Executed result: