I2C SPI USB CAN eSPI Cable Testing View All Videos Quick Start Guides Software Downloads App Notes White Papers User Manuals Knowledge Base Sales Support About Us
Products Blog Sales Support Contact Search
How Do I Set Up Data Logging to Record I2C Bus Data Correctly Using the Aardvark I2C/SPI Host Adapter?
Rena Ayeras

Image by SaadiaAMYii via Pixabay

Question from the Customer:

I am working on an I2C system with the Aardvark I2C/SPI Host Adapter. In addition to running tests, I am using the Aardvark Software API for data logging . I enabled aa_log with level=4 for STDOUT, and these are the results I get:

aa_i2c_write: slave = 0x020, flags = 0x00, status = 0x00, bytes = 6

WRITE:

0000:  00 00 e0 36 aa 02

aa_i2c_write: slave = 0x020, flags = 0x00, status = 0x00, bytes = 11

WRITE:

0000:  02 f8 7f 00 00 f0 27 b2  f3 ad 01

aa_i2c_write: slave = 0x020, flags = 0x00, status = 0x00, bytes = 11

WRITE:

0000:  02 f8 7f 00 00 c0 2d b2  f3 ad 01

Are those supposed to be the data bytes that I provided to aa_i2c_write function? I compare the results to the information that was provided to the function, and they do not match. Is there a better way to record and interpret the results? Is logging set up correctly?

Response from Technical Support:

Thank you for your questions! We need more information to fully analyze your output, but we can provide details about calling the API command aa_log.

How the aa_log function logs transactions is similar to the Control Center Serial Software transaction log. This API function enables logging and appending the data to file. Here is an example of code:

// Enable logging

logfile = fopen("log.txt", "a+");

if (logfile != 0)

{ aa_log(handle, 3, fileno(logfile)); }

File mode “a+” opens the file for reading as well as writing, which enables appending to an existing file.

How Data Logging Works

Here is a summary of the command aa_log. For a full description of the syntax, please refer to API Documentation, sub-section 5.4 General Information in the Aardvark I2C/SPI Host Adapter User Manual.

int aa_log (Aardvark aardvark, int level, int handle);

  • Enables logging to a file.

Arguments

  • The Aardvark handle of an Aardvark adapter. Note that if the handle is invalid, the application can crash during a logging operation.

Return Value

  • An Aardvark status code is returned with AA_OK on success. No specific error codes.

 

Using the Logging Command

The handle must be a standard file descriptor. In the C programming language, a file descriptor can be obtained by using the ANSI C function open or by using the function fileno on a FILE* stream. A FILE* stream obtained using fopen can correspond to the common stdout or stderr available when stdlib.h is included.

Here are the options of logging levels:

0 – none

1 – error

2 – warning

3 – info

4 – debug

Known Limitations and Solutions

Due to inconsistencies that occur through the Microsoft operating software handling linkage to the C runtime library, logging to a file may not work in Windows. However, logging to stdout and stderr are  supported. One of the following two defined constants can be passed as the handle argument:

AA_LOG_STDOUT

AA_LOG_STDERR

To implement this correction, add the following line in your code:

aa_log(handle, 4, AA_LOG_STDOUT)

Note - modify the level and handle parameters for your requirement.

Examples of Data Logging Levels

Listed below are examples of applying various levels of logging:

For level = 0 (same as no logging enabled) the output consists only of print statements issued by the user:

For level = 3 (info), the output provides additional information:

For level = 4 (debug), the output includes debug logs, which are outlined in the red box:

How to Disable Errors and Warnings

Errors and warnings are logged with level 1 and level 2. The logging can be disabled by using level=0, or with handle=0 (standard in handle). Here are the steps to do so:

  1. Change the file handle parameter to "AA_LOG_STDOUT" instead of "fileno(logfile)".
  2. Open command window from the executable path.
  3. Pass the command as [exe] [port no] >> [filename].

Here is an example:

We hope this answers your questions. 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.