For a Preliminary Design Simulation, What Do I Need to Set Up the Aardvark I2C/SPI Host Adapter as a Slave for Responding to Requests from the Master Device? Is Polling Needed?
Rena Ayeras

Question from the Customer:

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:

  • For Step 1 – the request from Master can happen at any time. If that is the case, should I iteratively poll for 'Slave Read' function continuously?
  • For Step 2 - based on the data received from 'Slave Read' I would logically decide what to be sent out and then call 'Slave Set Response' with the appropriate response (ex: 01 01 01). Is this assumption correct?
  • Also, are steps in the correct sequence for this implementation?
Scenario 2:

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:

  • Please confirm if the above steps will work. My understanding is the response buffer is 64 bytes – is that correct?

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:

  • If the Master request is 01 01, I would simulate the slave response 01 01 01. In this case, if I have read "Slave Read" and the outcome of  "Slave Read" is 01 01, only then will I set the "Slave Response" to 01 01 01.

For “Set Slave Response”, the Aardvark I2C/SPI Host Adapter User Manual  describes the following:

  • Set the slave response in the event the Aardvark adapter is put into slave mode and contacted by a master
My questions:

  • In my scenario, as the Master request is already there on bus (from Slave Read), will the Slave set the “Slave Response”, as master will not send a new request of 01 01?
  • Or will the Slave response be pushed on to I2C bus, irrespective of a new master request for 01 01?
Response from Technical Support:

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:

aa_i2c_slave_read // reads 01 01/ 02 02/ 03 03 from master and stores it in buffer "data_from_master" variable.set slave response buffer "slave_resp" according to data_from_master :

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.

Request a Demo