I plan to run a simulation using the Aardvark I2C/SPI Host Adapter in Slave mode. Before I get started, I would like some information about the Master request. I have two simulation scenarios.
Scenario 1:Step 1 - Master sends a request to Slave (ex: 01 01)
Step 2 - Slave responds to Master (ex: 01 01 01)
The hardware setup: the Master is a real device; the Slave is the Aardvark adapter; they communicate at the rate of 400 kHz. The purpose of the simulation: write a DLL with .Net platform for doing the logic behind the read request, and then output data using the slave response. My questions:
Step 1 - Master sends a request to Slave (ex: 02 01)
Step 2 - Slave responds to master (ex: 02 01 xx yy zz aa bb cc dd ee ff gg hh ii etc (36 bytes))
My questions:
I have additional questions that could apply to both scenarios about polling and slave response:
There could be multiple master requests, and some could be different (01 01 or 02 01 or 04 33 etc.). I need to simulate a unique response for each request. Example:
For “Set Slave Response”, the Aardvark I2C/SPI Host Adapter User Manual describes the following:
Thanks for your questions! The response buffer space is 64 bytes. Here are details about running the commands you described:
The API command aa_i2c_slave_read checks the Master's message asynchronously; you do not need to poll to check incoming messages indefinitely (the default timeout is 500 ms). You can change the timeout with aa_async_poll.
For setting the slave response, aa_i2c_slave_set_response sends the response set by the Aardvark slave automatically on the event of contact by master. The Slave response is set only when the Master invokes a "read from slave" command.
Here is an example of such a flow:
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;
}
In summary:
Call aa_i2c_slave_set_response, then issue the master_read_from_slave command. Once the Master contacts the Slave to read data, data from slave_resp is sent.
For more information, please refer to the API Documentation section of the Aardvark I2C/SPI Host Adapter User Manual.
Additional resources that you may find helpful include the following:
We hope this answers your question. Looking for more information? You can contact us and request a demo that applies to your application, as well as ask about our Total Phase products.