I2C.C API: Data Structures

  • Main Page
  • Data Structures
  • Files
  • Examples
  • Data Structures
  • Data Fields
Data Structures
Here are the data structures with brief descriptions:
C i2capi_board_t
C i2capi_boards_t
C i2capi_error_t
C i2capi_handle_t
telos Systementwicklung GmbH (http://www.telos.info) Tue Mar 17 2015


I2C.C API: i2capi_board_t Struct Reference

  • Examples
  • Data Structures
  • Data Fields
Data Fields
i2capi_board_t Struct Reference

#include <i2capi_c.h>

Data Fields

unsigned short | snr
serial number
board_type_t board_type
type of the I2C interface
char | remote_address [16]
address of the remote I2C scheduler (e.g. "test.telos.de")
unsigned short | remote_port
TCP/IP port of the I2C scheduler (e.g. "3000")
char | remote_password [10]
password of the remote I2C scheduler (e.g. "secret")
unsigned int | termination [256]
possible values for SCL/SDA termination
int | termination_cnt
number of values in the "termination" variable
unsigned char | low_level_threshold [64]
possible values for low level threshold
int | low_level_threshold_cnt
number of values in the "low_level_threshold" variable
unsigned char | high_level_threshold [64]
possible values for high level threshold
int | high_level_threshold_cnt
number of values in the "high_level_threshold" variable
unsigned int | i2c_vcc_supply [256]
possible values for I2C Vcc supply
int | i2c_vcc_supply_cnt
number of values in the "i2c_vcc_supply" variable
unsigned int | master_bitrate [7000]
possible values for the master bitrate
int | master_bitrate_cnt
number of values in the "master_bitrate" variable
unsigned int | master_bitrate_hs [100]
possible values for the master high-speed bitrate
int | master_bitrate_hs_cnt
number of values in the "master_bitrate_hs" variable
int | input_testpins
number of input testpins
int | output_testpins
number of output testpins

Detailed Description

This structure is used to store information about an I2C interface. E.g. it can be used to get information about the type of the I2C interface and its serial number.


I2C.C API: i2capi_boards_t Struct Reference

  • Data Structures
  • Data Fields
Data Fields
i2capi_boards_t Struct Reference

#include <i2capi_c.h>

Data Fields

i2capi_board_t | boards [20]
information about the found I2C interfaces
int | nr_boards
number of found I2C interfaces

Detailed Description

This structure is used to store information about the I2C interfaces, which have been found using i2capi_find_boards() or i2capi_find_boards_network().

Examples:
example_master.c.


I2C.C API: i2capi_error_t Struct Reference

  • Data Structures
  • Data Fields
Data Fields
i2capi_error_t Struct Reference

#include <i2capi_c.h>

Data Fields

int | error
error occurred (1), no error (0)
char | message [1000]
message describing the error

Detailed Description

An instance of this structure can be passed to all functions of this API. In case of an error the functions set the member variable "error" to "1" and store a string describing the error in the "message" member variable.

Examples:
example_master.c.


I2C.C API: i2capi_handle_t Struct Reference

  • Data Structures
  • Data Fields
i2capi_handle_t Struct Reference

#include <i2capi_c.h>

Detailed Description

The i2capi_open() function returns a handle of this type. This handle has to be passed to the other functions like e.g. i2capi_transmit().

Never change any member variables of this structure manually.

Examples:
example_master.c.


I2C.C API: Data Fields

  • Data Structures
  • Data Fields
  • All
  • Variables
Here is a list of all documented struct and union fields with links to the struct/union documentation for each field:
  • board_type : i2capi_board_t
  • boards : i2capi_boards_t
  • error : i2capi_error_t
  • high_level_threshold : i2capi_board_t
  • high_level_threshold_cnt : i2capi_board_t
  • i2c_vcc_supply : i2capi_board_t
  • i2c_vcc_supply_cnt : i2capi_board_t
  • input_testpins : i2capi_board_t
  • low_level_threshold : i2capi_board_t
  • low_level_threshold_cnt : i2capi_board_t
  • master_bitrate : i2capi_board_t
  • master_bitrate_cnt : i2capi_board_t
  • master_bitrate_hs : i2capi_board_t
  • master_bitrate_hs_cnt : i2capi_board_t
  • message : i2capi_error_t
  • nr_boards : i2capi_boards_t
  • output_testpins : i2capi_board_t
  • remote_address : i2capi_board_t
  • remote_password : i2capi_board_t
  • remote_port : i2capi_board_t
  • snr : i2capi_board_t
  • termination : i2capi_board_t
  • termination_cnt : i2capi_board_t


I2C.C API: Data Fields - Variables

  • Data Structures
  • Data Fields
  • All
  • Variables
  • board_type : i2capi_board_t
  • boards : i2capi_boards_t
  • error : i2capi_error_t
  • high_level_threshold : i2capi_board_t
  • high_level_threshold_cnt : i2capi_board_t
  • i2c_vcc_supply : i2capi_board_t
  • i2c_vcc_supply_cnt : i2capi_board_t
  • input_testpins : i2capi_board_t
  • low_level_threshold : i2capi_board_t
  • low_level_threshold_cnt : i2capi_board_t
  • master_bitrate : i2capi_board_t
  • master_bitrate_cnt : i2capi_board_t
  • master_bitrate_hs : i2capi_board_t
  • master_bitrate_hs_cnt : i2capi_board_t
  • message : i2capi_error_t
  • nr_boards : i2capi_boards_t
  • output_testpins : i2capi_board_t
  • remote_address : i2capi_board_t
  • remote_password : i2capi_board_t
  • remote_port : i2capi_board_t
  • snr : i2capi_board_t
  • termination : i2capi_board_t
  • termination_cnt : i2capi_board_t


I2C.C API: File List

  • File List
  • Globals
File List
Here is a list of all documented files with brief descriptions:
i2capi_c.cpp
i2capi_c.h


I2C.C API: i2capi_c.cpp File Reference

  • File List
  • Globals
Functions
i2capi_c.cpp File Reference
#include "i2capi_c.h"
#include "../cpp-api/CBoard.h"
#include "../cpp-api/CMaster.h"
#include "../cpp-api/CMasterMessage.h"
#include "../cpp-api/CSlaveRamEnhanced.h"
#include "../cpp-api/CI2cAddress.h"
#include "../cpp-api/CException.h"
#include <cstring>
#include <cstdio>

Functions

void | i2capi_find_boards (i2capi_boards_t *result, i2capi_error_t *error)
void | i2capi_find_boards_network (i2capi_boards_t *result, i2capi_error_t *error, const char *remote_address, unsigned short remote_port, const char *remote_password)
i2capi_handle_t * | i2capi_open (const i2capi_board_t *board, i2capi_error_t *error)
void | i2capi_close (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_bitrate (i2capi_handle_t *board, i2capi_error_t *error, int bitrate)
int | i2capi_get_bitrate (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_bitrate_highspeed (i2capi_handle_t *board, i2capi_error_t *error, int bitrate)
int | i2capi_get_bitrate_highspeed (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_highspeed_master_code (i2capi_handle_t *board, i2capi_error_t *error, unsigned char master_code)
unsigned char | i2capi_get_highspeed_master_code (i2capi_handle_t *board, i2capi_error_t *error)
int | i2capi_transmit (i2capi_handle_t *board, i2capi_error_t *error, unsigned char address, const unsigned char *data, int data_length)
int | i2capi_transmit_10 (i2capi_handle_t *board, i2capi_error_t *error, unsigned short address, const unsigned char *data, int data_length)
int | i2capi_receive (i2capi_handle_t *board, i2capi_error_t *error, unsigned char address, int nr_bytes, unsigned char *data, int data_length)
int | i2capi_receive_10 (i2capi_handle_t *board, i2capi_error_t *error, unsigned short address, int nr_bytes, unsigned char *data, int data_length)
int | i2capi_transmit_receive (i2capi_handle_t *board, i2capi_error_t *error, unsigned char address, const unsigned char *tx_data, int tx_data_length, int rx_nr_bytes, unsigned char *rx_data, int rx_data_length)
int | i2capi_transmit_receive_10 (i2capi_handle_t *board, i2capi_error_t *error, unsigned short address, const unsigned char *tx_data, int tx_data_length, int rx_nr_bytes, unsigned char *rx_data, int rx_data_length)
int | i2capi_scan_addresses (i2capi_handle_t *board, i2capi_error_t *error, int timeout, unsigned char *addresses, int addresses_length)
int | i2capi_scan_addresses_10 (i2capi_handle_t *board, i2capi_error_t *error, int timeout, unsigned short *addresses, int addresses_length)
void | i2capi_enable_slave (i2capi_handle_t *board, i2capi_error_t *error, unsigned char address, unsigned int memory_size, int auto_increment, unsigned short timeout_ms)
void | i2capi_enable_slave_10 (i2capi_handle_t *board, i2capi_error_t *error, unsigned short address, unsigned int memory_size, int auto_increment, unsigned short timeout_ms)
void | i2capi_disable_slave (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_slave_data (i2capi_handle_t *board, i2capi_error_t *error, const unsigned char *data, int data_length)
void | i2capi_get_slave_data (i2capi_handle_t *board, i2capi_error_t *error, unsigned char *data, int data_length)
void | i2capi_set_termination (i2capi_handle_t *board, i2capi_error_t *error, unsigned int term)
unsigned int | i2capi_get_termination (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_i2c_vcc_supply (i2capi_handle_t *board, i2capi_error_t *error, unsigned int voltage)
unsigned int | i2capi_get_i2c_vcc_supply (i2capi_handle_t *board, i2capi_error_t *error)
unsigned short | i2capi_get_i2c_vcc (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_level_threshold (i2capi_handle_t *board, i2capi_error_t *error, unsigned char low, unsigned char high)
unsigned char | i2capi_get_low_level_threshold (i2capi_handle_t *board, i2capi_error_t *error)
unsigned char | i2capi_get_high_level_threshold (i2capi_handle_t *board, i2capi_error_t *error)
unsigned char | i2capi_get_input_testpin (i2capi_handle_t *board, i2capi_error_t *error, int testpin)
void | i2capi_set_output_testpin (i2capi_handle_t *board, i2capi_error_t *error, int testpin, unsigned char value)
unsigned char | i2capi_get_output_testpin (i2capi_handle_t *board, i2capi_error_t *error, int testpin)

Function Documentation

void i2capi_close | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Destroys the given handle, which has been created using the i2capi_open() function.

Parameters
board | handle of the I2C interface
error | error message
Examples:
example_master.c.
void i2capi_disable_slave | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Disables the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
void i2capi_enable_slave | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | address,
 |  | unsigned int | memory_size,
 |  | int | auto_increment,
 |  | unsigned short | timeout_ms
 | ) |  |

Configures and enables the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (7 bit)
memory_size | size of the emulated RAM
auto_increment | auto increment: disabled (0), enabled (1)
timeout_ms | timeout [ms] or N/A (~0)
void i2capi_enable_slave_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned short | address,
 |  | unsigned int | memory_size,
 |  | int | auto_increment,
 |  | unsigned short | timeout_ms
 | ) |  |

Configures and enables the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (10 bit)
memory_size | size of the emulated RAM
auto_increment | auto increment: disabled (0), enabled (1)
timeout_ms | timeout [ms] or N/A (~0)
void i2capi_find_boards | ( | i2capi_boards_t * | result,
 |  | i2capi_error_t * | error
 | ) |  |

Requests a list of all I2C interfaces connected to the local PC.

Parameters
result | list of I2C interfaces
error | error message
Examples:
example_master.c.
void i2capi_find_boards_network | ( | i2capi_boards_t * | result,
 |  | i2capi_error_t * | error,
 |  | const char * | remote_address,
 |  | unsigned short | remote_port,
 |  | const char * | remote_password
 | ) |  |

Requests a list of all I2C interfaces connected to the specified remote PC.

Parameters
result | list of I2C interfaces
error | error message
remote_address | address of the remote PC (e.g. "192.168.1.1" or "test.telos.de")
remote_port | TCP/IP port of the remote PC (e.g. 3000)
remote_password | password of the remote PC
int i2capi_get_bitrate | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the I2C bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 100 kHz.

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C bitrate [Hz]
int i2capi_get_bitrate_highspeed | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the I2C high-speed bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 0, which disables the high-speed mode.

The high-speed master code gets sent with the I2C bitrate, which is returned by i2capi_get_bitrate().

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C high-speed bitrate [Hz]
unsigned char i2capi_get_high_level_threshold | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the high level threshold. This threshold defines the voltage range on SCL/SDA interpreted as logical "1".

Parameters
board | handle of the I2C interface
error | error message
Returns
high level threshold [percent]
Examples:
example_master.c.
unsigned char i2capi_get_highspeed_master_code | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the I2C high-speed master code.

Valid values for the high-speed master code are 0x08, 0x0a, 0x0c, and 0x0e.

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C high-speed master code
unsigned short i2capi_get_i2c_vcc | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the Vcc voltage of the I2C bus.

Parameters
board | handle of the I2C interface
error | error message
Returns
Vcc of the I2C bus [mV] or ~0 (N/A)
Examples:
example_master.c.
unsigned int i2capi_get_i2c_vcc_supply | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the current value of the I2C Vcc supply voltage.

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C Vcc supply voltage [mV]
Examples:
example_master.c.
unsigned char i2capi_get_input_testpin | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | testpin
 | ) |  |

Returns the current status of the specified input testpin. The number of available input testpins is stored in the i2capi_board_t.input_testpins.

Parameters
board | handle of the I2C interface
error | error message
testpin | testpin to be read
Returns
status of the testpin: low (0), high (1)
unsigned char i2capi_get_low_level_threshold | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the low level threshold. This threshold defines the voltage range on SCL/SDA interpreted as logical "0".

Parameters
board | handle of the I2C interface
error | error message
Returns
low level threshold [percent]
Examples:
example_master.c.
unsigned char i2capi_get_output_testpin | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | testpin
 | ) |  |

Returns the level of one of the hardware's output testpins. The number of available output testpins is stored in the i2capi_board_t.testpin_output.

Parameters
board | handle of the I2C interface
error | error message
testpin | number of the testpin to be read
Returns
status of the testpin: low (0), high (1)
Examples:
example_master.c.
void i2capi_get_slave_data | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char * | data,
 |  | int | data_length
 | ) |  |

Gets the data, which is stored in the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
data | data read from I2C slave
data_length | number of data byes to be read
unsigned int i2capi_get_termination | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the value of the current termination of SCL/SDA.

Parameters
board | handle of the I2C interface
error | error message
Returns
termination of SCL [Ohm] or N/A (~0)
Examples:
example_master.c.
i2capi_handle_t* i2capi_open | ( | const i2capi_board_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Opens the specified I2C interface. As a result this function creates a handle, which can be passed to the other functions of this API.

If the created handle is no longer needed, it has to be closed using i2capi_close().

Parameters
board | I2C interface to be opened
error | error message
Returns
handle for the I2C interface or "NULL"
Examples:
example_master.c.
int i2capi_receive | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | address,
 |  | int | nr_bytes,
 |  | unsigned char * | data,
 |  | int | data_length
 | ) |  |

Reads the specified number of bytes as master receiver from the I2C slave with the given 7-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (7 bit)
nr_bytes | number of bytes to be read
data | buffer used for the read bytes
data_length | size of the data buffer
Returns
number of bytes read from the I2C bus
Examples:
example_master.c.
int i2capi_receive_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned short | address,
 |  | int | nr_bytes,
 |  | unsigned char * | data,
 |  | int | data_length
 | ) |  |

Reads the specified number of bytes as master receiver from the I2C slave with the given 10-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (10 bit)
nr_bytes | number of bytes to be read
data | buffer used for the read bytes
data_length | size of the data buffer
Returns
number of bytes read from the I2C bus
int i2capi_scan_addresses | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | timeout,
 |  | unsigned char * | addresses,
 |  | int | addresses_length
 | ) |  |

Scans the I2C bus connected to the I2C interface for slaves. Therefor the method tries to read one byte from each I2C address. The addresses of all found slaves are returned.

Parameters
board | handle of the I2C interface
error | error message
timeout | timeout timeout for bus busy [s]
addresses | I2C addresses of found slaves
addresses_length | size of addresses buffer
Returns
number of found I2C slaves
int i2capi_scan_addresses_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | timeout,
 |  | unsigned short * | addresses,
 |  | int | addresses_length
 | ) |  |

Scans the I2C bus connected to the I2C interface for slaves. Therefor the method tries to read one byte from each I2C address. The addresses of all found slaves are returned.

Parameters
board | handle of the I2C interface
error | error message
timeout | timeout timeout for bus busy [s]
addresses | I2C addresses of found slaves
addresses_length | size of addresses buffer
Returns
number of found I2C slaves
void i2capi_set_bitrate | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | bitrate
 | ) |  |

Sets the I2C bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 100 kHz.

Valid values for the bitrate can be found in the i2capi_board_t.master_bitrate variable.

Parameters
board | handle of the I2C interface
error | error message
bitrate | I2C bitrate [Hz]
Examples:
example_master.c.
void i2capi_set_bitrate_highspeed | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | bitrate
 | ) |  |

Sets the I2C high-speed bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 0, which disables the high-speed mode.

The high-speed master code gets sent with the I2C bitrate, which has been set using i2capi_set_bitrate().

Valid values for the high-speed bitrate can be found in the i2capi_board_t.master_bitrate_hs variable.

Parameters
board | handle of the I2C interface
error | error message
bitrate | I2C high-speed bitrate [Hz]
void i2capi_set_highspeed_master_code | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | master_code
 | ) |  |

Sets the I2C high-speed master code (default is 0x08).

Valid values for the high-speed master code are 0x08, 0x0a, 0x0c, and 0x0e.

Parameters
board | handle of the I2C interface
error | error message
master_code | I2C high-speed master code
void i2capi_set_i2c_vcc_supply | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned int | voltage
 | ) |  |

Sets the I2C Vcc supply voltage.

Some I2C interfaces can supply the I2C Vcc pin. Valid values for the I2C Vcc supply voltage can be found in the i2capi_board_t.i2c_vcc_supply variable.

Parameters
board | handle of the I2C interface
error | error message
voltage | I2C Vcc supply voltage [mV]
void i2capi_set_level_threshold | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | low,
 |  | unsigned char | high
 | ) |  |

Sets the low and high level thresholds.

The low level threshold defines the voltage range on SCL/SDA interpreted as logical "0".

The high level threshold defines the voltage range on SCL/SDA interpreted as logical "1".

Valid values for the level thresholds can be found in the i2capi_board_t.low_level_threshold and i2capi_board_t.high_level_threshold variables.

Parameters
board | handle of the I2C interface
error | error message
low | low level threshold [percent]
high | high level threshold [percent]
void i2capi_set_output_testpin | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | testpin,
 |  | unsigned char | value
 | ) |  |

Sets one of the hardware's output testpins to the specified level. The number of available output testpins is stored in the i2capi_board_t.output_testpins.

Parameters
board | handle of the I2C interface
error | error message
testpin | number of the testpin to be changed
value | level to be set: low (0), high (1)
Examples:
example_master.c.
void i2capi_set_slave_data | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | const unsigned char * | data,
 |  | int | data_length
 | ) |  |

Sets the data, which is stored in the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
data | data to be set
data_length | number of data bytes
void i2capi_set_termination | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned int | term
 | ) |  |

Configures the termination of SCL/SDA.

Valid values for the termination can be found in the i2capi_board_t.termination variable.

Parameters
board | handle of the I2C interface
error | error message
term | termination of SCL/SDA [Ohm]
int i2capi_transmit | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | address,
 |  | const unsigned char * | data,
 |  | int | data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 7-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (7 bit)
data | bytes to be sent
data_length | number of bytes to be sent
Returns
number of bytes sent to the I2C bus
Examples:
example_master.c.
int i2capi_transmit_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned short | address,
 |  | const unsigned char * | data,
 |  | int | data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 10-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (10 bit)
data | bytes to be sent
data_length | number of bytes to be sent
Returns
number of bytes sent to the I2C bus
int i2capi_transmit_receive | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | address,
 |  | const unsigned char * | tx_data,
 |  | int | tx_data_length,
 |  | int | rx_nr_bytes,
 |  | unsigned char * | rx_data,
 |  | int | rx_data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 7-bit I2C address. Afterwards it reads the specified number of bytes as master receiver from the I2C slave with the given 7-bit I2C address.

This function implements the so-called combined mode (no stop condition gets sent between both transfers).

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (7 bit)
tx_data | bytes to be sent
tx_data_length | number of bytes to be sent
rx_nr_bytes | number of bytes to be read
rx_data | buffer used for the read bytes
rx_data_length | size of the data buffer
Returns
number of bytes written to and read from the I2C bus
Examples:
example_master.c.
int i2capi_transmit_receive_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned short | address,
 |  | const unsigned char * | tx_data,
 |  | int | tx_data_length,
 |  | int | rx_nr_bytes,
 |  | unsigned char * | rx_data,
 |  | int | rx_data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 10-bit I2C address. Afterwards it reads the specified number of bytes as master receiver from the I2C slave with the given 10-bit I2C address.

This function implements the so-called combined mode (no stop condition gets sent between both transfers).

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (10 bit)
tx_data | bytes to be sent
tx_data_length | number of bytes to be sent
rx_nr_bytes | number of bytes to be read
rx_data | buffer used for the read bytes
rx_data_length | size of the data buffer
Returns
number of bytes written to and read from the I2C bus


I2C.C API: i2capi_c.h File Reference

  • File List
  • Globals
Data Structures | Enumerations | Functions
i2capi_c.h File Reference

Data Structures

struct | i2capi_board_t
struct | i2capi_boards_t
struct | i2capi_handle_t
struct | i2capi_error_t

Enumerations

enum board_type_t {
TRACII_XL = 2, TRACII_XL2 = 6, CONNII = 3, CONNII_MM = 5,
CONNII_MM2 = 7, DUMMY = 4
}

Functions

void | i2capi_find_boards (i2capi_boards_t *result, i2capi_error_t *error)
void | i2capi_find_boards_network (i2capi_boards_t *result, i2capi_error_t *error, const char *remote_address, unsigned short remote_port, const char *remote_password)
i2capi_handle_t * | i2capi_open (const i2capi_board_t *board, i2capi_error_t *error)
void | i2capi_close (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_bitrate (i2capi_handle_t *board, i2capi_error_t *error, int bitrate)
int | i2capi_get_bitrate (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_bitrate_highspeed (i2capi_handle_t *board, i2capi_error_t *error, int bitrate)
int | i2capi_get_bitrate_highspeed (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_highspeed_master_code (i2capi_handle_t *board, i2capi_error_t *error, unsigned char master_code)
unsigned char | i2capi_get_highspeed_master_code (i2capi_handle_t *board, i2capi_error_t *error)
int | i2capi_transmit (i2capi_handle_t *board, i2capi_error_t *error, unsigned char address, const unsigned char *data, int data_length)
int | i2capi_transmit_10 (i2capi_handle_t *board, i2capi_error_t *error, unsigned short address, const unsigned char *data, int data_length)
int | i2capi_receive (i2capi_handle_t *board, i2capi_error_t *error, unsigned char address, int nr_bytes, unsigned char *data, int data_length)
int | i2capi_receive_10 (i2capi_handle_t *board, i2capi_error_t *error, unsigned short address, int nr_bytes, unsigned char *data, int data_length)
int | i2capi_transmit_receive (i2capi_handle_t *board, i2capi_error_t *error, unsigned char address, const unsigned char *tx_data, int tx_data_length, int rx_nr_bytes, unsigned char *rx_data, int rx_data_length)
int | i2capi_transmit_receive_10 (i2capi_handle_t *board, i2capi_error_t *error, unsigned short address, const unsigned char *tx_data, int tx_data_length, int rx_nr_bytes, unsigned char *rx_data, int rx_data_length)
int | i2capi_scan_addresses (i2capi_handle_t *board, i2capi_error_t *error, int timeout, unsigned char *addresses, int addresses_length)
int | i2capi_scan_addresses_10 (i2capi_handle_t *board, i2capi_error_t *error, int timeout, unsigned short *addresses, int addresses_length)
void | i2capi_disable_slave (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_slave_data (i2capi_handle_t *board, i2capi_error_t *error, const unsigned char *data, int data_length)
void | i2capi_get_slave_data (i2capi_handle_t *board, i2capi_error_t *error, unsigned char *data, int data_length)
void | i2capi_set_termination (i2capi_handle_t *board, i2capi_error_t *error, unsigned int term)
unsigned int | i2capi_get_termination (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_i2c_vcc_supply (i2capi_handle_t *board, i2capi_error_t *error, unsigned int voltage)
unsigned int | i2capi_get_i2c_vcc_supply (i2capi_handle_t *board, i2capi_error_t *error)
unsigned short | i2capi_get_i2c_vcc (i2capi_handle_t *board, i2capi_error_t *error)
void | i2capi_set_level_threshold (i2capi_handle_t *board, i2capi_error_t *error, unsigned char low, unsigned char high)
unsigned char | i2capi_get_low_level_threshold (i2capi_handle_t *board, i2capi_error_t *error)
unsigned char | i2capi_get_high_level_threshold (i2capi_handle_t *board, i2capi_error_t *error)
unsigned char | i2capi_get_input_testpin (i2capi_handle_t *board, i2capi_error_t *error, int testpin)
void | i2capi_set_output_testpin (i2capi_handle_t *board, i2capi_error_t *error, int testpin, unsigned char value)
unsigned char | i2capi_get_output_testpin (i2capi_handle_t *board, i2capi_error_t *error, int testpin)

Enumeration Type Documentation

enum board_type_t

Enumeration to specify the type of the I2C interface.

Enumerator
TRACII_XL | Tracii XL.
TRACII_XL2 | Tracii XL 2.0.
CONNII | Connii.
CONNII_MM | Connii MM.
CONNII_MM2 | Connii MM 2.0.
DUMMY | dummy device

Function Documentation

void i2capi_close | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Destroys the given handle, which has been created using the i2capi_open() function.

Parameters
board | handle of the I2C interface
error | error message
void i2capi_disable_slave | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Disables the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
void i2capi_find_boards | ( | i2capi_boards_t * | result,
 |  | i2capi_error_t * | error
 | ) |  |

Requests a list of all I2C interfaces connected to the local PC.

Parameters
result | list of I2C interfaces
error | error message
void i2capi_find_boards_network | ( | i2capi_boards_t * | result,
 |  | i2capi_error_t * | error,
 |  | const char * | remote_address,
 |  | unsigned short | remote_port,
 |  | const char * | remote_password
 | ) |  |

Requests a list of all I2C interfaces connected to the specified remote PC.

Parameters
result | list of I2C interfaces
error | error message
remote_address | address of the remote PC (e.g. "192.168.1.1" or "test.telos.de")
remote_port | TCP/IP port of the remote PC (e.g. 3000)
remote_password | password of the remote PC
int i2capi_get_bitrate | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the I2C bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 100 kHz.

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C bitrate [Hz]
int i2capi_get_bitrate_highspeed | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the I2C high-speed bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 0, which disables the high-speed mode.

The high-speed master code gets sent with the I2C bitrate, which is returned by i2capi_get_bitrate().

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C high-speed bitrate [Hz]
unsigned char i2capi_get_high_level_threshold | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the high level threshold. This threshold defines the voltage range on SCL/SDA interpreted as logical "1".

Parameters
board | handle of the I2C interface
error | error message
Returns
high level threshold [percent]
unsigned char i2capi_get_highspeed_master_code | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the I2C high-speed master code.

Valid values for the high-speed master code are 0x08, 0x0a, 0x0c, and 0x0e.

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C high-speed master code
unsigned short i2capi_get_i2c_vcc | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the Vcc voltage of the I2C bus.

Parameters
board | handle of the I2C interface
error | error message
Returns
Vcc of the I2C bus [mV] or ~0 (N/A)
unsigned int i2capi_get_i2c_vcc_supply | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the current value of the I2C Vcc supply voltage.

Parameters
board | handle of the I2C interface
error | error message
Returns
I2C Vcc supply voltage [mV]
unsigned char i2capi_get_input_testpin | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | testpin
 | ) |  |

Returns the current status of the specified input testpin. The number of available input testpins is stored in the i2capi_board_t.input_testpins.

Parameters
board | handle of the I2C interface
error | error message
testpin | testpin to be read
Returns
status of the testpin: low (0), high (1)
unsigned char i2capi_get_low_level_threshold | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the low level threshold. This threshold defines the voltage range on SCL/SDA interpreted as logical "0".

Parameters
board | handle of the I2C interface
error | error message
Returns
low level threshold [percent]
unsigned char i2capi_get_output_testpin | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | testpin
 | ) |  |

Returns the level of one of the hardware's output testpins. The number of available output testpins is stored in the i2capi_board_t.testpin_output.

Parameters
board | handle of the I2C interface
error | error message
testpin | number of the testpin to be read
Returns
status of the testpin: low (0), high (1)
void i2capi_get_slave_data | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char * | data,
 |  | int | data_length
 | ) |  |

Gets the data, which is stored in the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
data | data read from I2C slave
data_length | number of data byes to be read
unsigned int i2capi_get_termination | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Returns the value of the current termination of SCL/SDA.

Parameters
board | handle of the I2C interface
error | error message
Returns
termination of SCL [Ohm] or N/A (~0)
i2capi_handle_t* i2capi_open | ( | const i2capi_board_t * | board,
 |  | i2capi_error_t * | error
 | ) |  |

Opens the specified I2C interface. As a result this function creates a handle, which can be passed to the other functions of this API.

If the created handle is no longer needed, it has to be closed using i2capi_close().

Parameters
board | I2C interface to be opened
error | error message
Returns
handle for the I2C interface or "NULL"
int i2capi_receive | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | address,
 |  | int | nr_bytes,
 |  | unsigned char * | data,
 |  | int | data_length
 | ) |  |

Reads the specified number of bytes as master receiver from the I2C slave with the given 7-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (7 bit)
nr_bytes | number of bytes to be read
data | buffer used for the read bytes
data_length | size of the data buffer
Returns
number of bytes read from the I2C bus
int i2capi_receive_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned short | address,
 |  | int | nr_bytes,
 |  | unsigned char * | data,
 |  | int | data_length
 | ) |  |

Reads the specified number of bytes as master receiver from the I2C slave with the given 10-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (10 bit)
nr_bytes | number of bytes to be read
data | buffer used for the read bytes
data_length | size of the data buffer
Returns
number of bytes read from the I2C bus
int i2capi_scan_addresses | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | timeout,
 |  | unsigned char * | addresses,
 |  | int | addresses_length
 | ) |  |

Scans the I2C bus connected to the I2C interface for slaves. Therefor the method tries to read one byte from each I2C address. The addresses of all found slaves are returned.

Parameters
board | handle of the I2C interface
error | error message
timeout | timeout timeout for bus busy [s]
addresses | I2C addresses of found slaves
addresses_length | size of addresses buffer
Returns
number of found I2C slaves
int i2capi_scan_addresses_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | timeout,
 |  | unsigned short * | addresses,
 |  | int | addresses_length
 | ) |  |

Scans the I2C bus connected to the I2C interface for slaves. Therefor the method tries to read one byte from each I2C address. The addresses of all found slaves are returned.

Parameters
board | handle of the I2C interface
error | error message
timeout | timeout timeout for bus busy [s]
addresses | I2C addresses of found slaves
addresses_length | size of addresses buffer
Returns
number of found I2C slaves
void i2capi_set_bitrate | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | bitrate
 | ) |  |

Sets the I2C bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 100 kHz.

Valid values for the bitrate can be found in the i2capi_board_t.master_bitrate variable.

Parameters
board | handle of the I2C interface
error | error message
bitrate | I2C bitrate [Hz]
void i2capi_set_bitrate_highspeed | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | bitrate
 | ) |  |

Sets the I2C high-speed bitrate (SCL) used by the hardware, when the hardware generates the clock. The default bitrate is 0, which disables the high-speed mode.

The high-speed master code gets sent with the I2C bitrate, which has been set using i2capi_set_bitrate().

Valid values for the high-speed bitrate can be found in the i2capi_board_t.master_bitrate_hs variable.

Parameters
board | handle of the I2C interface
error | error message
bitrate | I2C high-speed bitrate [Hz]
void i2capi_set_highspeed_master_code | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | master_code
 | ) |  |

Sets the I2C high-speed master code (default is 0x08).

Valid values for the high-speed master code are 0x08, 0x0a, 0x0c, and 0x0e.

Parameters
board | handle of the I2C interface
error | error message
master_code | I2C high-speed master code
void i2capi_set_i2c_vcc_supply | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned int | voltage
 | ) |  |

Sets the I2C Vcc supply voltage.

Some I2C interfaces can supply the I2C Vcc pin. Valid values for the I2C Vcc supply voltage can be found in the i2capi_board_t.i2c_vcc_supply variable.

Parameters
board | handle of the I2C interface
error | error message
voltage | I2C Vcc supply voltage [mV]
void i2capi_set_level_threshold | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | low,
 |  | unsigned char | high
 | ) |  |

Sets the low and high level thresholds.

The low level threshold defines the voltage range on SCL/SDA interpreted as logical "0".

The high level threshold defines the voltage range on SCL/SDA interpreted as logical "1".

Valid values for the level thresholds can be found in the i2capi_board_t.low_level_threshold and i2capi_board_t.high_level_threshold variables.

Parameters
board | handle of the I2C interface
error | error message
low | low level threshold [percent]
high | high level threshold [percent]
void i2capi_set_output_testpin | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | int | testpin,
 |  | unsigned char | value
 | ) |  |

Sets one of the hardware's output testpins to the specified level. The number of available output testpins is stored in the i2capi_board_t.output_testpins.

Parameters
board | handle of the I2C interface
error | error message
testpin | number of the testpin to be changed
value | level to be set: low (0), high (1)
void i2capi_set_slave_data | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | const unsigned char * | data,
 |  | int | data_length
 | ) |  |

Sets the data, which is stored in the I2C slave of Tracii XL 2.0.

Parameters
board | handle of the I2C interface
error | error message
data | data to be set
data_length | number of data bytes
void i2capi_set_termination | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned int | term
 | ) |  |

Configures the termination of SCL/SDA.

Valid values for the termination can be found in the i2capi_board_t.termination variable.

Parameters
board | handle of the I2C interface
error | error message
term | termination of SCL/SDA [Ohm]
int i2capi_transmit | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | address,
 |  | const unsigned char * | data,
 |  | int | data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 7-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (7 bit)
data | bytes to be sent
data_length | number of bytes to be sent
Returns
number of bytes sent to the I2C bus
int i2capi_transmit_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned short | address,
 |  | const unsigned char * | data,
 |  | int | data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 10-bit I2C address.

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (10 bit)
data | bytes to be sent
data_length | number of bytes to be sent
Returns
number of bytes sent to the I2C bus
int i2capi_transmit_receive | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned char | address,
 |  | const unsigned char * | tx_data,
 |  | int | tx_data_length,
 |  | int | rx_nr_bytes,
 |  | unsigned char * | rx_data,
 |  | int | rx_data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 7-bit I2C address. Afterwards it reads the specified number of bytes as master receiver from the I2C slave with the given 7-bit I2C address.

This function implements the so-called combined mode (no stop condition gets sent between both transfers).

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (7 bit)
tx_data | bytes to be sent
tx_data_length | number of bytes to be sent
rx_nr_bytes | number of bytes to be read
rx_data | buffer used for the read bytes
rx_data_length | size of the data buffer
Returns
number of bytes written to and read from the I2C bus
int i2capi_transmit_receive_10 | ( | i2capi_handle_t * | board,
 |  | i2capi_error_t * | error,
 |  | unsigned short | address,
 |  | const unsigned char * | tx_data,
 |  | int | tx_data_length,
 |  | int | rx_nr_bytes,
 |  | unsigned char * | rx_data,
 |  | int | rx_data_length
 | ) |  |

Sends the given data as master transmitter to the I2C slave with the given 10-bit I2C address. Afterwards it reads the specified number of bytes as master receiver from the I2C slave with the given 10-bit I2C address.

This function implements the so-called combined mode (no stop condition gets sent between both transfers).

Parameters
board | handle of the I2C interface
error | error message
address | I2C address of the slave (10 bit)
tx_data | bytes to be sent
tx_data_length | number of bytes to be sent
rx_nr_bytes | number of bytes to be read
rx_data | buffer used for the read bytes
rx_data_length | size of the data buffer
Returns
number of bytes written to and read from the I2C bus


I2C.C API: Globals

  • File List
  • Globals
  • All
  • Functions
  • Enumerations
  • Enumerator
  • b
  • c
  • d
  • i
  • t
Here is a list of all documented functions, variables, defines, enums, and typedefs with links to the documentation:

- b -

  • board_type_t : i2capi_c.h

- c -

  • CONNII : i2capi_c.h
  • CONNII_MM : i2capi_c.h
  • CONNII_MM2 : i2capi_c.h

- d -

  • DUMMY : i2capi_c.h

- i -

  • i2capi_close() : i2capi_c.cpp , i2capi_c.h
  • i2capi_disable_slave() : i2capi_c.h , i2capi_c.cpp
  • i2capi_enable_slave() : i2capi_c.cpp
  • i2capi_enable_slave_10() : i2capi_c.cpp
  • i2capi_find_boards() : i2capi_c.h , i2capi_c.cpp
  • i2capi_find_boards_network() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_bitrate() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_bitrate_highspeed() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_high_level_threshold() : i2capi_c.h , i2capi_c.cpp
  • i2capi_get_highspeed_master_code() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_i2c_vcc() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_i2c_vcc_supply() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_input_testpin() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_low_level_threshold() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_output_testpin() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_slave_data() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_termination() : i2capi_c.h , i2capi_c.cpp
  • i2capi_open() : i2capi_c.cpp , i2capi_c.h
  • i2capi_receive() : i2capi_c.cpp , i2capi_c.h
  • i2capi_receive_10() : i2capi_c.cpp , i2capi_c.h
  • i2capi_scan_addresses() : i2capi_c.h , i2capi_c.cpp
  • i2capi_scan_addresses_10() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_bitrate() : i2capi_c.h , i2capi_c.cpp
  • i2capi_set_bitrate_highspeed() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_highspeed_master_code() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_i2c_vcc_supply() : i2capi_c.h , i2capi_c.cpp
  • i2capi_set_level_threshold() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_output_testpin() : i2capi_c.h , i2capi_c.cpp
  • i2capi_set_slave_data() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_termination() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit_10() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit_receive() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit_receive_10() : i2capi_c.h , i2capi_c.cpp

- t -

  • TRACII_XL : i2capi_c.h
  • TRACII_XL2 : i2capi_c.h


I2C.C API: Globals

  • File List
  • Globals
  • All
  • Functions
  • Enumerations
  • Enumerator
  • i

- i -

  • i2capi_close() : i2capi_c.cpp , i2capi_c.h
  • i2capi_disable_slave() : i2capi_c.h , i2capi_c.cpp
  • i2capi_enable_slave() : i2capi_c.cpp
  • i2capi_enable_slave_10() : i2capi_c.cpp
  • i2capi_find_boards() : i2capi_c.h , i2capi_c.cpp
  • i2capi_find_boards_network() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_bitrate() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_bitrate_highspeed() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_high_level_threshold() : i2capi_c.h , i2capi_c.cpp
  • i2capi_get_highspeed_master_code() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_i2c_vcc() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_i2c_vcc_supply() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_input_testpin() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_low_level_threshold() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_output_testpin() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_slave_data() : i2capi_c.cpp , i2capi_c.h
  • i2capi_get_termination() : i2capi_c.h , i2capi_c.cpp
  • i2capi_open() : i2capi_c.cpp , i2capi_c.h
  • i2capi_receive() : i2capi_c.cpp , i2capi_c.h
  • i2capi_receive_10() : i2capi_c.cpp , i2capi_c.h
  • i2capi_scan_addresses() : i2capi_c.h , i2capi_c.cpp
  • i2capi_scan_addresses_10() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_bitrate() : i2capi_c.h , i2capi_c.cpp
  • i2capi_set_bitrate_highspeed() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_highspeed_master_code() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_i2c_vcc_supply() : i2capi_c.h , i2capi_c.cpp
  • i2capi_set_level_threshold() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_output_testpin() : i2capi_c.h , i2capi_c.cpp
  • i2capi_set_slave_data() : i2capi_c.cpp , i2capi_c.h
  • i2capi_set_termination() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit_10() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit_receive() : i2capi_c.cpp , i2capi_c.h
  • i2capi_transmit_receive_10() : i2capi_c.h , i2capi_c.cpp


I2C.C API: Globals

  • File List
  • Globals
  • All
  • Functions
  • Enumerations
  • Enumerator
  • board_type_t : i2capi_c.h


I2C.C API: Globals

  • File List
  • Globals
  • All
  • Functions
  • Enumerations
  • Enumerator
  • CONNII : i2capi_c.h
  • CONNII_MM : i2capi_c.h
  • CONNII_MM2 : i2capi_c.h
  • DUMMY : i2capi_c.h
  • TRACII_XL : i2capi_c.h
  • TRACII_XL2 : i2capi_c.h


I2C.C API: Examples

Examples
Here is a list of all examples:
  • example_master.c


I2C.C API: example_master.c

example_master.c
/*************************************************************
Copyright (c) 2005-2012 telos Systementwicklung GmbH,
Hamburg (Germany)
http://www.telos.de
Name:
Author: MB
$Modtime: 29.07.08 11:21 $
This program demonstrates how to use the I2C.C API.
The executable must be linked against "i2capi_c.lib",
which contains the loader stub for "i2capi_c.dll".
*************************************************************/
#include "i2capi_c.h"
#include <stdio.h>
/***********************************************************************/
/* *
* This function demonstrates how to sent data as master transmitter *
* to an I2C device. In this example 256 bytes of data are sent to *
* a device with the slave address 0x50 (7 bit). *
* */
/***********************************************************************/
void MasterTransmitter (i2capi_handle_t *board)
{
unsigned char data[256];
i2capi_error_t error = { 0, "" };
int ret;
int i;
// Create some data to be sent
for (i=0; i < 256; i++)
data[i] = i;
// Set the bitrate to 100 kHz
i2capi_set_bitrate (board, &error, 100000);
// Transfer the data to the I2C slave.
ret = i2capi_transmit (board, &error, 0x50, data, sizeof (data));
printf ("Transmitted %i bytes sucessfully as master transmitter.\n", ret);
// Show error
if (error.error)
fprintf (stderr, "\nError: %s\n\n", error.message);
}
/***********************************************************************/
/* *
* This function demonstrates how to read data as master receiver *
* from an I2C device. In this example 256 bytes of data are read *
* from a device with the slave address 0x50 (7 bit). *
* */
/***********************************************************************/
void MasterReceiver (i2capi_handle_t *board)
{
unsigned char data[256];
i2capi_error_t error = { 0, "" };
int ret;
int i;
// Set the bitrate to 100 kHz
i2capi_set_bitrate (board, &error, 100000);
// Read the data from the I2C slave.
ret = i2capi_receive (board, &error, 0x50, 256, data, sizeof (data));
// Display the number of bytes received from the slave.
printf ("Received %i bytes sucessfully as master receiver.\n", ret);
// Display the data received from the slave.
for (i=0; i < ret; i++)
printf ("%02x ", data[i]);
printf ("\n");
// Show error
if (error.error)
fprintf (stderr, "\nError: %s\n\n", error.message);
}
/***********************************************************************/
/* *
* This function demonstrates the so-called I2C combined mode, which *
* consists of a combination of several master transmitter and *
* master receiver transfers. In this example the combined mode *
* transfer consists of one master transmitter transfer and one *
* master receiver transfer. On the I2C bus the transfer looks like *
* that: *
* *
* START, ADDR/W, DATA, START, ADDR/R, 10 * DATA, STOP *
* */
/***********************************************************************/
void MasterCombined (i2capi_handle_t *board)
{
unsigned char data_tx[] = { 0 };
unsigned char data_rx[10];
i2capi_error_t error = { 0, "" };
int ret;
// Set the bitrate to 400 kHz
i2capi_set_bitrate (board, &error, 400000);
// Transfer the data to the I2C slave.
ret = i2capi_transmit_receive (board, &error, 0x50,
data_tx, sizeof (data_tx),
10, data_rx, sizeof (data_rx));
// Display the number of bytes received from the slave.
printf ("Transfered data bytes: %i.\n", ret);
// Display error
if (error.error)
fprintf (stderr, "\nError: %s\n\n", error.message);
}
/***********************************************************************/
/* *
* Demonstrates how to use the output testpins. *
* */
/***********************************************************************/
void OutputTestpins (i2capi_handle_t *board, int number_of_testpins)
{
i2capi_error_t error = { 0, "" };
unsigned char status;
int i;
for (i=0; i < number_of_testpins; i++)
{
printf ("Testpin %i\n", i);
// show current status of testpin
status = i2capi_get_output_testpin (board, &error, i);
if (error.error)
break;
printf (" Current Value: %u\n", status);
// set testpin to high
printf (" Going To High Level\n");
i2capi_set_output_testpin (board, &error, i, 1);
if (error.error)
break;
// set testpin to low
printf (" Going To Low Level\n");
i2capi_set_output_testpin (board, &error, i, 0);
if (error.error)
break;
}
// Display error
if (error.error)
fprintf (stderr, "\nError: %s\n\n", error.message);
}
int main (void)
{
i2capi_boards_t boards;
i2capi_error_t error = { 0, "" };
i2capi_handle_t *hd;
unsigned int i2c_vcc_supply;
// Find available I2C interfaces.
i2capi_find_boards (&boards, &error);
if (error.error)
{
fprintf (stderr, "Error: %s\n\n", error.message);
return (1);
}
// There should be at least one real I2C interface.
if (boards.nr_boards <= 1)
{
fprintf (stderr, "Error: No I2C interfaces have been found.\n\n");
return (1);
}
// Open the first real I2C interface.
hd = i2capi_open (&(boards.boards[1]), &error);
if (error.error)
{
fprintf (stderr, "Error: %s\n\n", error.message);
return (1);
}
// Show some informations about the opened I2C interface.
printf ("\n------------------------------------------------------------\n");
printf ("Serial number: 0x%04x\n", boards.boards[1].snr);
if (i2capi_get_i2c_vcc (hd, &error) != (unsigned short) (~0))
printf ("I2C Vcc: %.2f V\n", i2capi_get_i2c_vcc (hd, &error) / 1000.0);
i2c_vcc_supply = i2capi_get_i2c_vcc_supply (hd, &error);
if (i2c_vcc_supply > 0)
printf ("I2C Vcc Supply: %.2f V\n", i2c_vcc_supply / 1000.0);
else
printf ("I2C Vcc Supply: Off\n");
printf ("Termination: %d Ohm\n", i2capi_get_termination (hd, &error));
printf ("Low Threshold: %d %%\n", i2capi_get_low_level_threshold (hd, &error));
printf ("High Threshold: %d %%\n", i2capi_get_high_level_threshold (hd, &error));
printf ("------------------------------------------------------------\n\n");
// Demonstrate a master transmitter transfer.
MasterTransmitter (hd);
// Demonstrate a master receiver transfer.
MasterReceiver (hd);
// Demonstrate a combined mode transfer.
MasterCombined (hd);
// Demonstrate the output testpins.
OutputTestpins (hd, boards.boards[1].output_testpins);
// Close opened I2C interface.
i2capi_close (hd, &error);
// Show errors if available.
if (error.error)
{
fprintf (stderr, "Error: %s\n", error.message);
return (1);
}
return (0);
}


I2C.C API: Data Structure Index

  • Data Structures
  • Data Fields
Data Structure Index
I
i
i2capi_boards_t i2capi_handle_t
i2capi_error_t
i2capi_board_t
I


I2C.C API: Main Page

I2C.C API Documentation