Difference between revisions of "Bot test"
Line 2: | Line 2: | ||
|- | |- | ||
| width="20%" style="color:gray;" | Author | | width="20%" style="color:gray;" | Author | ||
− | | | + | | Matrix Ltd. |
|- | |- | ||
| width="20%" style="color:gray;" | Version | | width="20%" style="color:gray;" | Version | ||
− | | | + | | 1.4 |
|- | |- | ||
| width="20%" style="color:gray;" | Category | | width="20%" style="color:gray;" | Category | ||
− | | Comms: | + | | Comms: Interface |
|} | |} | ||
− | == | + | ==I2C Master component== |
− | + | Generic Two Wire I2C Communications Interface | |
+ | |||
+ | ==Detailed description== | ||
+ | |||
+ | |||
==Examples== | ==Examples== | ||
+ | |||
+ | More information on I2C can be found here, | ||
+ | |||
+ | [http://www.matrixtsl.com/blog/simplified-communications-i%c2%b2c-and-spi/ Matrix Flowcode Blog: Simplified communications I2C and SPI] | ||
+ | |||
+ | |||
+ | ===Generic I2C EEPROM=== | ||
+ | |||
+ | Example file demonstrating how to read and write bytes from a generic I2C EEPROM device. | ||
+ | {{Fcfile|I2CEEPROM.fcfx|I2CEEPROM}} | ||
+ | ===Simulated I2C devices=== | ||
+ | |||
+ | This example uses the I2C master component combined with the DS1307 injector to simulate an I2C communications bus between the target Microcontroller and the virtual DS1307 device. | ||
+ | {{Fcfile|DS1307InjectorTest.fcfx|I2C DS1307 Example}} | ||
+ | The panel displays the current time from the DS1307 RAM which is populated to match the system time. | ||
+ | |||
+ | [[File:DS1307Panel.jpg]] | ||
− | + | The I2C console shows the communications between the target microcontroller and simulated I2C device. | |
− | + | [[File:DS1307Data.jpg]] | |
− | + | The DS1307 console shows the contents of RAM memory on the simulated I2C device. | |
− | + | [[File:DS1307Ram.jpg]] | |
Line 35: | Line 56: | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveByte''' |
+ | |- | ||
+ | | colspan="2" | Receives a byte from the I²C bus. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Last | ||
+ | |- | ||
+ | | colspan="2" | Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Restart''' | ||
+ | |- | ||
+ | | colspan="2" | Outputs a restart condition onto the I²C bus. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Stop''' | ||
+ | |- | ||
+ | | colspan="2" | Outputs a stop condition onto the I²C bus. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Transaction_Write''' | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Attempt to write Length number of bytes to the I2C slave from the given Buffer. Ensure that the Buffer is large enough. Returns the number of bytes written, the caller should check that this matches requested Length |
|- | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Buffer | ||
+ | |- | ||
+ | | colspan="2" | Buffer of bytes to write to the I2C | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
− | | width="90%" | | + | | width="90%" | Length |
+ | |- | ||
+ | | colspan="2" | Number of bytes to send out, MS bit 0x8000 signifies no Stop if set | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''TransmitByte''' | ||
+ | |- | ||
+ | | colspan="2" | Sends a byte on the I²C bus. Returns the acknowledge if any. 0 represents that data was acknowledged and 1 represents no acknowledge was detected. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Data byte to send on the I²C bus. | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GenericWriteRegister''' | ||
+ | |- | ||
+ | | colspan="2" | Function to perform a generic I2C Write transaction. The 7-bit device ID is automatically shifted up by one bit to make room for the read/write bit. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Device_ID | ||
+ | |- | ||
+ | | colspan="2" | 7-bit Device Address ID | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Address | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
− | | width="90%" | | + | | width="90%" | Data |
+ | |- | ||
+ | | colspan="2" | Data Byte | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | AddressByteCount | ||
+ | |- | ||
+ | | colspan="2" | Specifies the number of address bytes, Range: 1 or 2 | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Transaction_Uninit''' | ||
+ | |- | ||
+ | | colspan="2" | Uninitialise the I2C interface | ||
|- | |- | ||
− | |||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
Line 58: | Line 187: | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GenericReadRegister''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Function to perform a generic I2C read. The 7-bit device ID is automatically shifted up by one bit to make room for the read/write bit. Returns the data from the location specified. |
|- | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
− | | width="90%" | | + | | width="90%" | Device_ID |
+ | |- | ||
+ | | colspan="2" | 7-bit Device Address ID | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Address | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | AddressByteCount | ||
+ | |- | ||
+ | | colspan="2" | Specifies the number of address bytes, Range: 1 or 2 | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Transaction_Read''' | ||
+ | |- | ||
+ | | colspan="2" | Attempt to read Length number of bytes from the I2C slave to the given Buffer. Ensure that the Buffer is large enough. Returns number of bytes read, caller should check that this matches requested Length | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Buffer | ||
+ | |- | ||
+ | | colspan="2" | Buffer to store the incoming byte data | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of bytes to read | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Start''' | ||
+ | |- | ||
+ | | colspan="2" | Outputs a start condition onto the I²C bus. | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Transaction_Initialise''' | ||
+ | |- | ||
+ | | colspan="2" | Initialise the I2C interface to communicate with a Slave device at Address Returns 0 on fail, 1 on success | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Address | ||
+ | |- | ||
+ | | colspan="2" | 7-bit I2C Address without the shift for the R/W bit | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 78: | Line 271: | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Enables the I²C hardware and performs some initialization. Should be called at the start of the program or at least before any of the other I²C functions are called. |
|- | |- | ||
|- | |- | ||
Line 99: | Line 292: | ||
| width="90%" | Channel | | width="90%" | Channel | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Channel selection |
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
− | | width="90%" | Baud | + | | width="90%" | Baud Select |
|- | |- | ||
| colspan="2" | Baud rate option selector | | colspan="2" | Baud rate option selector | ||
Line 109: | Line 302: | ||
| width="90%" | Baud Rate | | width="90%" | Baud Rate | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Baud rate to be used |
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
+ | | width="90%" | Stop Delay | ||
+ | |- | ||
+ | | colspan="2" | On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not a 10ms delay between an I2C stop event and the next I2C start event. Most modern microcontrollers will not have a problem so this property can be disabled to speed up the I2C communications. | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9-type- | + | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] |
− | | width="90%" | | + | | width="90%" | Slew Rate Control |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Slew Rate Control Enabled or Disabled |
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9-type- | + | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] |
− | | width="90%" | | + | | width="90%" | SMBus Inputs |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | When Enabled input logic thresholds are compliant with SMBus specification |
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Connections''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Connections''' | ||
|- | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-5-icon.png]] | ||
+ | | width="90%" | SDA | ||
+ | |- | ||
+ | | colspan="2" | Pin used for SDA (data signal) | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-5-icon.png]] | ||
+ | | width="90%" | SCL | ||
+ | |- | ||
+ | | colspan="2" | Pin used for SCL (clock signal) | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-conn-icon.png]] | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Simulations''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Simulations''' | ||
|- | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
+ | | width="90%" | Label | ||
+ | |- | ||
+ | | colspan="2" | Label shown on the comms flasher on the simulation panel. | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
| width="90%" | Scope Traces | | width="90%" | Scope Traces | ||
|- | |- | ||
− | | colspan="2" | Selects if the scope traces are automatically | + | | colspan="2" | Selects if the scope traces are automatically generated or not |
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
Line 138: | Line 351: | ||
|- | |- | ||
| colspan="2" | Selects if the console data is automatically generated or not | | colspan="2" | Selects if the console data is automatically generated or not | ||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
− | | width="90%" | | + | | width="90%" | API |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | |
|} | |} |
Revision as of 13:20, 31 August 2021
Author | Matrix Ltd. |
Version | 1.4 |
Category | Comms: Interface |
Contents
I2C Master component
Generic Two Wire I2C Communications Interface
Detailed description
Examples
More information on I2C can be found here,
Matrix Flowcode Blog: Simplified communications I2C and SPI
Generic I2C EEPROM
Example file demonstrating how to read and write bytes from a generic I2C EEPROM device.
I2CEEPROM
Simulated I2C devices
This example uses the I2C master component combined with the DS1307 injector to simulate an I2C communications bus between the target Microcontroller and the virtual DS1307 device.
I2C DS1307 Example
The panel displays the current time from the DS1307 RAM which is populated to match the system time.
The I2C console shows the communications between the target microcontroller and simulated I2C device.
The DS1307 console shows the contents of RAM memory on the simulated I2C device.
Downloadable macro reference
![]() |
ReceiveByte |
Receives a byte from the I²C bus. | |
![]() |
Last |
Used to signify the last byte when streaming incoming data. 0=Not last byte, 1=Last Byte | |
![]() |
Return |
![]() |
Restart |
Outputs a restart condition onto the I²C bus. | |
![]() |
Return |
![]() |
Stop |
Outputs a stop condition onto the I²C bus. | |
![]() |
Return |
![]() |
Transaction_Uninit |
Uninitialise the I2C interface | |
![]() |
Return |
![]() |
Start |
Outputs a start condition onto the I²C bus. | |
![]() |
Return |
![]() |
Initialise |
Enables the I²C hardware and performs some initialization. Should be called at the start of the program or at least before any of the other I²C functions are called. | |
![]() |
Return |