Macros | Functions
High-Speed Two-Wire Interface (TWIHS)

Macros

#define I2C_FAST_MODE_SPEED   400000
 
#define LOW_LEVEL_TIME_LIMIT   384000
 
#define TWIHS_CLK_CALC_ARGU   3
 
#define TWIHS_CLK_DIV_MAX   0xFF
 
#define TWIHS_CLK_DIV_MIN   7
 
#define TWIHS_CLK_DIVIDER   2
 

Functions

void twihs_disable_interrupt (Twihs *p_twihs, uint32_t ul_sources)
 Disable TWIHS interrupts. More...
 
void twihs_disable_master_mode (Twihs *p_twihs)
 Disable TWIHS master mode. More...
 
void twihs_disable_slave_mode (Twihs *p_twihs)
 Disable TWIHS slave mode. More...
 
void twihs_enable_interrupt (Twihs *p_twihs, uint32_t ul_sources)
 Enable TWIHS interrupts. More...
 
void twihs_enable_master_mode (Twihs *p_twihs)
 Enable TWIHS master mode. More...
 
void twihs_enable_slave_mode (Twihs *p_twihs)
 Enable TWIHS slave mode. More...
 
uint32_t twihs_get_interrupt_mask (Twihs *p_twihs)
 Read TWIHS interrupt mask. More...
 
uint32_t twihs_get_interrupt_status (Twihs *p_twihs)
 Get TWIHS interrupt status. More...
 
Pdc * twihs_get_pdc_base (Twihs *p_twihs)
 Get TWIHS PDC base address. More...
 
void twihs_mask_slave_addr (Twihs *p_twihs, uint32_t ul_mask)
 A mask can be applied on the slave device address in slave mode in order to allow multiple address answer. For each bit of the MASK field set to one the corresponding SADR bit will be masked. More...
 
uint32_t twihs_master_init (Twihs *p_twihs, const twihs_options_t *p_opt)
 Initialize TWIHS master mode. More...
 
uint32_t twihs_master_read (Twihs *p_twihs, twihs_packet_t *p_packet)
 Read multiple bytes from a TWIHS compatible slave device. More...
 
uint32_t twihs_master_write (Twihs *p_twihs, twihs_packet_t *p_packet)
 Write multiple bytes to a TWIHS compatible slave device. More...
 
static uint32_t twihs_mk_addr (const uint8_t *addr, int len)
 
uint32_t twihs_probe (Twihs *p_twihs, uint8_t uc_slave_addr)
 Test if a chip answers a given I2C address. More...
 
uint8_t twihs_read_byte (Twihs *p_twihs)
 Reads a byte from the TWIHS bus. More...
 
void twihs_read_write_protection_status (Twihs *p_twihs, uint32_t *p_status)
 Read the write protection status. More...
 
void twihs_reset (Twihs *p_twihs)
 Reset TWIHS. More...
 
void twihs_set_alternative_command (Twihs *p_twihs, uint32_t ul_alt_cmd)
 Set length/direction/PEC for alternative command mode. More...
 
void twihs_set_filter (Twihs *p_twihs, uint32_t ul_filter)
 Set the filter for TWIHS. More...
 
void twihs_set_slave_addr (Twihs *p_twihs, uint32_t ul_device_addr)
 Set TWIHS slave address. More...
 
uint32_t twihs_set_speed (Twihs *p_twihs, uint32_t ul_speed, uint32_t ul_mck)
 Set the I2C bus speed in conjunction with the clock frequency. More...
 
void twihs_set_write_protection (Twihs *p_twihs, bool flag)
 Enables/Disables write protection mode. More...
 
void twihs_slave_init (Twihs *p_twihs, uint32_t ul_device_addr)
 Initialize TWIHS slave mode. More...
 
uint32_t twihs_slave_read (Twihs *p_twihs, uint8_t *p_data)
 Read data from master. More...
 
uint32_t twihs_slave_write (Twihs *p_twihs, uint8_t *p_data)
 Write data to TWIHS bus. More...
 
void twihs_smbus_set_timing (Twihs *p_twihs, uint32_t ul_timing)
 Set the prescaler, TLOW:SEXT, TLOW:MEXT and clock high max cycles for SMBUS mode. More...
 
void twihs_write_byte (Twihs *p_twihs, uint8_t uc_byte)
 Sends a byte of data to one of the TWIHS slaves on the bus. More...
 

Detailed Description

Driver for the TWIHS (High-Speed Two-Wire Interface). This driver provides access to the main features of the TWIHS controller. The TWIHS interconnects components on a unique two-wire bus. The TWIHS is programmable as a master or a slave with sequential or single-byte access. Multiple master capability is supported. The High Speed of 3.4Mbits per second can be achieved in slave mode only.

Usage
  1. Enable the TWIHS peripheral clock in the PMC.
  2. Enable the required TWIHS PIOs (see pio.h).
  3. Enable TWIHS master mode by calling twihs_enable_master_mode if it is a master on the I2C bus.
  4. Configure the TWIHS in master mode by calling twihs_master_init.
  5. Send data to a slave device on the I2C bus by calling twihs_master_write.
  6. Receive data from a slave device on the I2C bus by calling the twihs_master_read.
  7. Enable TWIHS slave mode by calling twihs_enable_slave_mode if it is a slave on the I2C bus.
  8. Configure the TWIHS in slave mode by calling twihs_slave_init.

Macro Definition Documentation

◆ I2C_FAST_MODE_SPEED

#define I2C_FAST_MODE_SPEED   400000

Definition at line 73 of file twihs.c.

◆ LOW_LEVEL_TIME_LIMIT

#define LOW_LEVEL_TIME_LIMIT   384000

Definition at line 72 of file twihs.c.

◆ TWIHS_CLK_CALC_ARGU

#define TWIHS_CLK_CALC_ARGU   3

Definition at line 75 of file twihs.c.

◆ TWIHS_CLK_DIV_MAX

#define TWIHS_CLK_DIV_MAX   0xFF

Definition at line 76 of file twihs.c.

◆ TWIHS_CLK_DIV_MIN

#define TWIHS_CLK_DIV_MIN   7

Definition at line 77 of file twihs.c.

◆ TWIHS_CLK_DIVIDER

#define TWIHS_CLK_DIVIDER   2

Definition at line 74 of file twihs.c.

Function Documentation

◆ twihs_disable_interrupt()

void twihs_disable_interrupt ( Twihs p_twihs,
uint32_t  ul_sources 
)

Disable TWIHS interrupts.

Parameters
p_twihsPointer to a TWIHS instance.
ul_sourcesInterrupts to be disabled.

Definition at line 406 of file twihs.c.

◆ twihs_disable_master_mode()

void twihs_disable_master_mode ( Twihs p_twihs)

Disable TWIHS master mode.

Parameters
p_twihsPointer to a TWIHS instance.

Definition at line 99 of file twihs.c.

◆ twihs_disable_slave_mode()

void twihs_disable_slave_mode ( Twihs p_twihs)

Disable TWIHS slave mode.

Parameters
p_twihsPointer to a TWIHS instance.

Definition at line 481 of file twihs.c.

◆ twihs_enable_interrupt()

void twihs_enable_interrupt ( Twihs p_twihs,
uint32_t  ul_sources 
)

Enable TWIHS interrupts.

Parameters
p_twihsPointer to a TWIHS instance.
ul_sourcesInterrupts to be enabled.

Definition at line 394 of file twihs.c.

◆ twihs_enable_master_mode()

void twihs_enable_master_mode ( Twihs p_twihs)

Enable TWIHS master mode.

Parameters
p_twihsPointer to a TWIHS instance.

Definition at line 84 of file twihs.c.

◆ twihs_enable_slave_mode()

void twihs_enable_slave_mode ( Twihs p_twihs)

Enable TWIHS slave mode.

Parameters
p_twihsPointer to a TWIHS instance.

Definition at line 466 of file twihs.c.

◆ twihs_get_interrupt_mask()

uint32_t twihs_get_interrupt_mask ( Twihs p_twihs)

Read TWIHS interrupt mask.

Parameters
p_twihsPointer to a TWIHS instance.
Returns
The interrupt mask value.

Definition at line 433 of file twihs.c.

◆ twihs_get_interrupt_status()

uint32_t twihs_get_interrupt_status ( Twihs p_twihs)

Get TWIHS interrupt status.

Parameters
p_twihsPointer to a TWIHS instance.
Return values
TWIHSinterrupt status.

Definition at line 421 of file twihs.c.

◆ twihs_get_pdc_base()

Pdc* twihs_get_pdc_base ( Twihs p_twihs)

Get TWIHS PDC base address.

Parameters
p_twihsPointer to a TWIHS instance.
Returns
TWIHS PDC registers base for PDC driver to access.

Definition at line 604 of file twihs.c.

◆ twihs_mask_slave_addr()

void twihs_mask_slave_addr ( Twihs p_twihs,
uint32_t  ul_mask 
)

A mask can be applied on the slave device address in slave mode in order to allow multiple address answer. For each bit of the MASK field set to one the corresponding SADR bit will be masked.

Parameters
p_twihsBase address of the TWIHS instance.
ul_maskMask value.

Definition at line 686 of file twihs.c.

◆ twihs_master_init()

uint32_t twihs_master_init ( Twihs p_twihs,
const twihs_options_t p_opt 
)

Initialize TWIHS master mode.

Parameters
p_twihsPointer to a TWIHS instance.
p_optOptions for initializing the TWIHS module (see twihs_options_t).
Returns
TWIHS_SUCCESS if initialization is complete, error code otherwise.

Definition at line 113 of file twihs.c.

◆ twihs_master_read()

uint32_t twihs_master_read ( Twihs p_twihs,
twihs_packet_t p_packet 
)

Read multiple bytes from a TWIHS compatible slave device.

Note
This function will NOT return until all data has been read or error occurs.
Parameters
p_twihsPointer to a TWIHS instance.
p_packetPacket information and data (see twihs_packet_t).
Returns
TWIHS_SUCCESS if all bytes were read, error code otherwise.

Definition at line 270 of file twihs.c.

◆ twihs_master_write()

uint32_t twihs_master_write ( Twihs p_twihs,
twihs_packet_t p_packet 
)

Write multiple bytes to a TWIHS compatible slave device.

Note
This function will NOT return until all data has been written or error occurred.
Parameters
p_twihsPointer to a TWIHS instance.
p_packetPacket information and data (see twihs_packet_t).
Returns
TWIHS_SUCCESS if all bytes were written, error code otherwise.

Definition at line 334 of file twihs.c.

◆ twihs_mk_addr()

static uint32_t twihs_mk_addr ( const uint8_t *  addr,
int  len 
)
static

Definition at line 241 of file twihs.c.

◆ twihs_probe()

uint32_t twihs_probe ( Twihs p_twihs,
uint8_t  uc_slave_addr 
)

Test if a chip answers a given I2C address.

Parameters
p_twihsPointer to a TWIHS instance.
uc_slave_addrAddress of the remote chip to search for.
Returns
TWIHS_SUCCESS if a chip was found, error code otherwise.

Definition at line 211 of file twihs.c.

◆ twihs_read_byte()

uint8_t twihs_read_byte ( Twihs p_twihs)

Reads a byte from the TWIHS bus.

Parameters
p_twihsPointer to a TWIHS instance.
Returns
The byte read.

Definition at line 445 of file twihs.c.

◆ twihs_read_write_protection_status()

void twihs_read_write_protection_status ( Twihs p_twihs,
uint32_t *  p_status 
)

Read the write protection status.

Parameters
p_twihsPointer to a TWIHS instance.
p_statusPointer to save the status.

Definition at line 639 of file twihs.c.

◆ twihs_reset()

void twihs_reset ( Twihs p_twihs)

Reset TWIHS.

Parameters
p_twihsPointer to a TWIHS instance.

Definition at line 589 of file twihs.c.

◆ twihs_set_alternative_command()

void twihs_set_alternative_command ( Twihs p_twihs,
uint32_t  ul_alt_cmd 
)

Set length/direction/PEC for alternative command mode.

Parameters
p_twihsBase address of the TWIHS instance.
ul_alt_cmdAlternative command parameters.

Definition at line 662 of file twihs.c.

◆ twihs_set_filter()

void twihs_set_filter ( Twihs p_twihs,
uint32_t  ul_filter 
)

Set the filter for TWIHS.

Parameters
p_twihsBase address of the TWIHS instance.
ul_filterFilter value.

Definition at line 674 of file twihs.c.

◆ twihs_set_slave_addr()

void twihs_set_slave_addr ( Twihs p_twihs,
uint32_t  ul_device_addr 
)

Set TWIHS slave address.

Parameters
p_twihsPointer to a TWIHS instance.
ul_device_addrDevice address of the SAM slave device on the I2C bus.

Definition at line 515 of file twihs.c.

◆ twihs_set_speed()

uint32_t twihs_set_speed ( Twihs p_twihs,
uint32_t  ul_speed,
uint32_t  ul_mck 
)

Set the I2C bus speed in conjunction with the clock frequency.

Parameters
p_twihsPointer to a TWIHS instance.
ul_speedThe desired I2C bus speed (in Hz).
ul_mckMain clock of the device (in Hz).
Return values
PASSNew speed setting is accepted.
FAILNew speed setting is rejected.

Definition at line 147 of file twihs.c.

◆ twihs_set_write_protection()

void twihs_set_write_protection ( Twihs p_twihs,
bool  flag 
)

Enables/Disables write protection mode.

Parameters
p_twihsPointer to a TWIHS instance.
flagture for enable, false for disable.

Definition at line 624 of file twihs.c.

◆ twihs_slave_init()

void twihs_slave_init ( Twihs p_twihs,
uint32_t  ul_device_addr 
)

Initialize TWIHS slave mode.

Parameters
p_twihsPointer to a TWIHS instance.
ul_device_addrDevice address of the SAM slave device on the I2C bus.

Definition at line 493 of file twihs.c.

◆ twihs_slave_read()

uint32_t twihs_slave_read ( Twihs p_twihs,
uint8_t *  p_data 
)

Read data from master.

Note
This function will NOT return until master sends a STOP condition.
Parameters
p_twihsPointer to a TWIHS instance.
p_dataPointer to the data buffer where data received will be stored.
Returns
Number of bytes read.

Definition at line 531 of file twihs.c.

◆ twihs_slave_write()

uint32_t twihs_slave_write ( Twihs p_twihs,
uint8_t *  p_data 
)

Write data to TWIHS bus.

Note
This function will NOT return until master sends a STOP condition.
Parameters
p_twihsPointer to a TWIHS instance.
p_dataPointer to the data buffer to be sent.
Returns
Number of bytes written.

Definition at line 562 of file twihs.c.

◆ twihs_smbus_set_timing()

void twihs_smbus_set_timing ( Twihs p_twihs,
uint32_t  ul_timing 
)

Set the prescaler, TLOW:SEXT, TLOW:MEXT and clock high max cycles for SMBUS mode.

Parameters
p_twihsBase address of the TWIHS instance.
ul_timingParameter for prescaler, TLOW:SEXT, TLOW:MEXT and clock high max cycles.

Definition at line 650 of file twihs.c.

◆ twihs_write_byte()

void twihs_write_byte ( Twihs p_twihs,
uint8_t  uc_byte 
)

Sends a byte of data to one of the TWIHS slaves on the bus.

Parameters
p_twihsPointer to a TWIHS instance.
byteThe byte to send.

Definition at line 456 of file twihs.c.



inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:07