| |
SPL I2C device programming - How to start I2C device programming
1. Re-launch SPL emulator
- if SPL emulator is running, please terminate emulator.
- Press "F5" key to re-launch SPL emulator on the editor.
- Clear log on the log list.
- Check the checkbox named "Display hex format for the I2C data" on the Log tab.
2. Add "I2CDevice" command
- SPL MF Emulator provides 10 I2C devices.
- Id: i2c1 ( Address: 58 )
- Id: i2c2 ( Address: 60 )
- Id: i2c3 ( Address: 62 )
- Id: i2c4 ( Address: 64 )
- Id: i2c5 ( Address: 66 )
- Id: i2c6 ( Address: 68 )
- Id: i2c7 ( Address: 70 )
- Id: i2c8 ( Address: 72 )
- Id: i2c9 ( Address: 74 )
- Id: i2c10 ( Address: 76 )
- Double click "I2CDevice" item on the tree.
| |
I2CDevice i2c1
/Address:58
/ClockRateKhz:100
| |
|
- You can change the id and address of I2C device.
3. Add simple logic to send data to I2C device
- 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)
- 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)
| |
|
- Click "Send Script" button to send SPL script to emulator.
4. Executed result
- Executed result will be shown as follows.
5. Read data from the I2C device
- Continued in the next tutorial.
|