Flowcode has many components to allow for different forms of communication such as UART, SPI, I2C, CAN, LIN, etc.
For each of these communications components you ideally need something at the other end to listen out for incoming messages and to respond with appropriate responses. An example of this would be a I2C device such as an EEPROM, you can write values to the device and then the values read back should then relate to the values that were written.
Flowcode can simulate remote devices by using an injector component which is currently built into most of the communications components. To do this first we add the communications component we want to use to the Flowcode panel. Next we add the injector component we want to use from the Simulation component category. Selecting the communications component there is an Injector property which if you click it should list the injector component we have just added.
In the example shown we have added the I2C Master component and the DS1307 Injector component which is designed to mimic the popular DS1307 device which is a Real time clock and EEPROM.
This example program demonstrates how to talk to the DS1307 device using standard I2C macros and also demonstrates the operation of the Injector component. The console window is handy as it has been setup to show the data memory of the DS1307 device as well as the I2C transactions as they are executed.
I2C Transaction Data
DS1307 Simulated Memory
The injector component was created using Flowcode itself just like any other component. There are a number of macros required to be a proper injector component meaning the component will be compatible with the InjectorBase component.
ChangeState (Byte NewState) – Useful for switching bus states, e.g. I2C start/stop or SPI CS high/low
ObjectHandle GetRxConsoleHandle () – Used to get the handle to the Received data console
ObjectHandle GetTxConsoleHandle () – Used to get the handle to the Transmitted data console
Byte RxByte () – Used to transfer a byte from the remote device
TxByte (Byte) – Used to transfer a byte to the remote device
The source code to create the DS1307 Injector component is available from here as a demonstration of how to program Injector components.
Here is a break down of some of the macros and their function in the component.
The WriteByteToConsole and ReadByteFromConsole functions allow a single byte value from the console to be read and written. This is the backbone of the simulation as the time and EE data is all based on the values in the console window.
The ChangeState macro is used to control what is being received so if the module is in the wrong mode then we can throw away any non necessary data just like the real device would.
The AddReturnByte and AddReturnString macros allow data to be added to the circular buffer reply queue waiting to be sent back to the main component.
The ParseCommand macro performs the command action.
Here is another injector component source, namely the AT Injector component which waits for a carriage return and then echoes back all the data that was sent to it to allow for basic AT type external components to be simulated. This could be taken further and have specific AT commands processed in a different way.
There is a forum topic detailing Injector creation available from here.
20,439 total views, 4 views today