I am planning to use the Aardvark I2C/SPI Host Adapter to simulate an SPI peripheral; the Aardvark adapter will be acting as an SPI “slave” device. Looking at the specifications, it seems the Aardvark adapter could send specific responses to specific host/controller read requests. Instead of your GUI software tools, I am planning to create a script. I could use either the Python or C programming languages.
Here is an example of how I want the Aardvark adapter in slave mode to respond:
If read from address 0x0000, reply with 0x00000000
If read from address 0x0004, reply with 0x76543210
If read from address 0x1000, reply with 0x7FFFFFFF
Do you have any sample scripts that I could use for this?
Response from Technical Support:Thanks for your question! You can create pre-defined responses with Aardvark Software API. The slave device can send responses, which are set before running the simulation. Please note that slave responses cannot be changed on the fly for dynamic transactions. Also, the space of the Aardvark response buffer is 64 bytes.
Here is a description of the script that you could create with our API software. The aa_spi_slave_read API command checks for master device message asynchronously. This way, there is no need to poll for checking incoming messages indefinitely. There is a default timeout of 500ms, which can be configured with the command aa_async_poll.
With the command, aa_i2c_slave_set_response, the Aardvark slave device automatically responds to the master device that invokes the “read from slave” command. For more information, please refer to the API Documentation section of the Aardvark I2C/SPI Host Adapter User Manual.
Here is an example in pseudo code:
Step 1: aa_spi_slave_read // reads 01 01/ 02 02/ 03 03 from master and stores it in buffer variable data_from_master. Step 2: Set the slave response buffer slave_resp according to data_from_master. In this example, if the request from the master device is 01 01, the slave response is set for 01 01 01. Two other responses are set up as shown below.u08 slave_resp[3];
if (data_from_master[0] == 01 && data_from_master[1] == 01)
{
slave_resp[0] = 01;
slave_resp[1] = 01;
slave_resp[2] = 01;
}
else if (data_from_master[0] == 02 && data_from_master[1] == 02)
{
slave_resp[0] = 02;
slave_resp[1] = 02;
slave_resp[2] = 02;
}
else if (data_from_master[0] == 03 && data_from_master[1] == 03)
{
slave_resp[0] = 03;
slave_resp[1] = 03;
slave_resp[2] = 03;
}
Step 3: Call the aa_i2c_slave_set_response. Step 4: Issue the master_read_from_slave command. When the master device contacts the slave device to read data, data from "slave_resp" is sent.Functional programs are provided in the Aardvark Software API package. Two programs, exa aaspi_file and aaspi_slave can be used together for setting up the slave mode of the Aardvark adapter. This setup will require two Aardvark adapters.
Of course, the API examples can be modified as needed for your setup, or you can write an original program.
Should you choose to use the GUI software, here is an overview of using the Control Center Serial Software with the Aardvark adapter set up as a slave device: How Do I Send Data to the I2C Master Device when the Aardvark I2C/SPI Host Adapter is Set Up as the Slave Device?
For greater flexibility, we suggest taking a look at the Promira Serial Platform, which can improve the production, test, design, as well as the development, emulation, and debugging complex embedded I2C and SPI applications.
We hope this answers your question. Additional resources that you may find helpful include the following:
If you want more information, feel free to contact us with your questions, or request a demo that applies to your application.