MAX32665 SDK Documentation  0.2
Software Development Kit Overview and API Documentation
I2C

Modules

 I2C_Registers
 Registers, Bit Masks and Bit Positions for the I2C Peripheral Module.
 

Data Structures

struct  i2c_req_t
 

Enumerations

enum  i2c_speed_t {
  I2C_STD_MODE = 100000,
  I2C_FAST_MODE = 400000,
  I2C_FASTPLUS_MODE = 1000000,
  I2C_HS_MODE = 3400000
}
 I2C Speed Modes. More...
 
enum  i2c_state_t {
  I2C_STATE_READING = 0,
  I2C_STATE_WRITING = 1
}
 
enum  i2c_autoflush_disable_t {
  I2C_AUTOFLUSH_ENABLE = 0,
  I2C_AUTOFLUSH_DISABLE = 1
}
 

Functions

int I2C_Init (mxc_i2c_regs_t *i2c, i2c_speed_t i2cspeed, const sys_cfg_i2c_t *sys_cfg)
 Initialize and enable I2C. More...
 
int I2C_Shutdown (mxc_i2c_regs_t *i2c)
 Shutdown I2C module. More...
 
int I2C_MasterWrite (mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t *data, int len, int restart)
 Master write data. More...
 
int I2C_MasterRead (mxc_i2c_regs_t *i2c, uint8_t addr, uint8_t *data, int len, int restart)
 Master read data. More...
 
int I2C_Slave (mxc_i2c_regs_t *i2c, uint8_t addr, const uint8_t *read_data, int read_len, uint8_t *write_data, int write_len, int *tx_num, int *rx_num, i2c_autoflush_disable_t sw_autoflush_disable)
 Slave read data. More...
 
int I2C_MasterAsync (mxc_i2c_regs_t *i2c, i2c_req_t *req)
 Master Read and Write Asynchronous. More...
 
int I2C_SlaveAsync (mxc_i2c_regs_t *i2c, i2c_req_t *req)
 Slave Read and Write Asynchronous. More...
 
void I2C_Handler (mxc_i2c_regs_t *i2c)
 I2C interrupt handler. More...
 
void I2C_DrainRX (mxc_i2c_regs_t *i2c)
 Drain all of the data in the RXFIFO. More...
 
void I2C_DrainTX (mxc_i2c_regs_t *i2c)
 Drain all of the data in the TXFIFO. More...
 
int I2C_AbortAsync (i2c_req_t *req)
 Abort Async request based on the request you want to abort. More...
 
int I2C_SetTimeout (mxc_i2c_regs_t *i2c, int us)
 Enable and Set Timeout. More...
 
void I2C_ClearTimeout (mxc_i2c_regs_t *i2c)
 clear and disable timeout More...
 

Detailed Description

Enumeration Type Documentation

◆ i2c_speed_t

Enumerator
I2C_STD_MODE 

100KHz Bus Speed

I2C_FAST_MODE 

400KHz Bus Speed

I2C_FASTPLUS_MODE 

1MHz Bus Speed

I2C_HS_MODE 

3.4MHz Bus Speed

Function Documentation

◆ I2C_Init()

int I2C_Init ( mxc_i2c_regs_t i2c,
i2c_speed_t  i2cspeed,
const sys_cfg_i2c_t *  sys_cfg 
)
Parameters
i2cPointer to I2C peripheral registers.
i2cspeeddesired speed (I2C mode)
sys_cfgSystem configuration object
Returns
E_NO_ERROR if everything is successful, Error Codes if an error occurred.

◆ I2C_Shutdown()

int I2C_Shutdown ( mxc_i2c_regs_t i2c)
Parameters
i2cPointer to the I2C registers.
Returns
E_NO_ERROR I2C shutdown successfully, error if unsuccessful.

◆ I2C_MasterWrite()

int I2C_MasterWrite ( mxc_i2c_regs_t i2c,
uint8_t  addr,
const uint8_t *  data,
int  len,
int  restart 
)

Will block until transaction is complete.

Parameters
i2cPointer to I2C regs.
addrI2C 7-bit Address left aligned, bit 7 to bit 1. Only supports 7-bit addressing. LSb of the given address will be used as the read/write bit, the addr will not be shifted. Used for both master and slave transactions.
dataData to be written.
lenNumber of bytes to Write.
restart0 to send a stop bit at the end of the transaction, otherwise send a restart.
Returns
Bytes transacted if everything is successful, Error Codes if an error occurred.

◆ I2C_MasterRead()

int I2C_MasterRead ( mxc_i2c_regs_t i2c,
uint8_t  addr,
uint8_t *  data,
int  len,
int  restart 
)

Will block until transaction is complete.

Parameters
i2cPointer to I2C regs.
addrI2C 7-bit Address left aligned, bit 7 to bit 1. Only supports 7-bit addressing. LSb of the given address will be used as the read/write bit, the addr will not be shifted. Used for both master and slave transactions.
dataData to be written.
lenNumber of bytes to Write.
restart0 to send a stop bit at the end of the transaction, otherwise send a restart.
Returns
Bytes transacted if everything is successful, Error Codes if an error occurred.

◆ I2C_Slave()

int I2C_Slave ( mxc_i2c_regs_t i2c,
uint8_t  addr,
const uint8_t *  read_data,
int  read_len,
uint8_t *  write_data,
int  write_len,
int *  tx_num,
int *  rx_num,
i2c_autoflush_disable_t  sw_autoflush_disable 
)

Will block until transaction is complete.

Parameters
i2cPointer to I2C regs.
addrI2C 7-bit Address left aligned, bit 7 to bit 1. Only supports 7-bit addressing. LSb of the given address will be used as the read/write bit, the addr will not be shifted. Used for both master and slave transactions.
read_dataBuffer that the master will read from.
read_lenNumber of bytes the master can read.
write_dataBuffer that the master will write to.
write_lenNumber of bytes the master can write.
tx_numNumber of bytes transmitted by the slave.
rx_numNumber of bytes received by the slave.
sw_autoflush_disableTX Autoflush enabled by default.Set this bit to disable autoflush manually.
Returns
E_NO_ERROR if everything is successful, Error Codes if an error occurred.

◆ I2C_MasterAsync()

int I2C_MasterAsync ( mxc_i2c_regs_t i2c,
i2c_req_t *  req 
)
Parameters
i2cPointer to I2C regs.
reqRequest for an I2C transaction.
Returns
E_NO_ERROR if everything is successful, Error Codes if an error occurred.

◆ I2C_SlaveAsync()

int I2C_SlaveAsync ( mxc_i2c_regs_t i2c,
i2c_req_t *  req 
)
Parameters
i2cPointer to I2C regs.
reqRequest for an I2C transaction.
Returns
E_NO_ERROR if everything is successful, Error Codes if an error occurred.

◆ I2C_Handler()

void I2C_Handler ( mxc_i2c_regs_t i2c)

This function should be called by the application from the interrupt handler if I2C interrupts are enabled. Alternately, this function can be periodically called by the application if I2C interrupts are disabled.

Parameters
i2cBase address of the I2C module.

◆ I2C_DrainRX()

void I2C_DrainRX ( mxc_i2c_regs_t i2c)
Parameters
i2cPointer to I2C regs.

◆ I2C_DrainTX()

void I2C_DrainTX ( mxc_i2c_regs_t i2c)
Parameters
i2cPointer to I2C regs.

◆ I2C_AbortAsync()

int I2C_AbortAsync ( i2c_req_t *  req)
Parameters
reqPointer to I2C Transaction.

◆ I2C_SetTimeout()

int I2C_SetTimeout ( mxc_i2c_regs_t i2c,
int  us 
)
Parameters
i2cpointer to I2C regs
[in]usmicro seconds to delay
Returns
E_NO_ERROR or E_BAD_PARAM if delay is to long.

◆ I2C_ClearTimeout()

void I2C_ClearTimeout ( mxc_i2c_regs_t i2c)
Parameters
i2cpointer to I2C regs