This section describes the programming interface of the LPI2C HAL driver.
LPI2C ICR Table
ICR (hex) | SCL divider | SDA hold value | SCL start hold value | SCL stop hold value |
00 | 20 | 7 | 6 | 11 |
01 | 22 | 7 | 7 | 12 |
02 | 24 | 8 | 8 | 13 |
03 | 26 | 8 | 9 | 14 |
04 | 28 | 9 | 10 | 15 |
05 | 30 | 9 | 11 | 16 |
06 | 34 | 10 | 13 | 18 |
07 | 40 | 10 | 16 | 21 |
I2C Clock rate formulas
I2C baud rate = bus_clock_Hz / (mult * SCL_divider)
SDA hold time = bus_clock_period_s * mult * SDA_hold_value
SCL start hold time = bus_clock_period_s * mult * SCL_start_hold_value
SCL stop hold time = bus_clock_period_s * mult * SCL_stop_hold_value
|
enum | lpi2c_status_t {
kStatus_LPI2C_Success = 0x0U,
kStatus_LPI2C_Initialized = 0x1U,
kStatus_LPI2C_Fail = 0x2U,
kStatus_LPI2C_Busy = 0x3U,
kStatus_LPI2C_Timeout = 0x4U,
kStatus_LPI2C_ReceivedNak = 0x5U,
kStatus_LPI2C_SlaveTxUnderrun = 0x6U,
kStatus_LPI2C_SlaveRxOverrun = 0x7U,
kStatus_LPI2C_AribtrationLost = 0x8U,
kStatus_LPI2C_StopSignalFail = 0x9U,
kStatus_LPI2C_Idle = 0xAU,
kStatus_LPI2C_NoReceiveInProgress = 0xBU,
kStatus_LPI2C_NoSendInProgress = 0xCU
} |
| LPI2C status return codes. More...
|
|
enum | lpi2c_master_status_t |
| LPI2C master status. More...
|
|
enum | lpi2c_master_interrupt_t |
| LPI2C interrupts. More...
|
|
enum | lpi2c_slave_status_t |
| LPI2C slave status. More...
|
|
enum | lpi2c_slave_interrupt_t |
| LPI2C interrupts. More...
|
|
enum | lpi2c_direction_t { kLPI2CWrite
} |
| Direction of master and slave transfers. More...
|
|
|
void | LPI2C_HAL_SetBaudRate (LPI2C_Type *base, uint32_t sourceClockInHz, uint32_t kbps) |
| Sets the LPI2C bus frequency for master transactions. More...
|
|
|
static uint8_t | LPI2C_HAL_MasterReadByte (LPI2C_Type *base) |
| Returns the last byte of data read from the bus and initiate another read. More...
|
|
static void | LPI2C_HAL_MasterWriteByte (LPI2C_Type *base, uint8_t byte) |
| Writes one byte of data to the LPI2C bus. More...
|
|
static uint8_t | LPI2C_HAL_SlaveReadByte (LPI2C_Type *base) |
| Returns the last byte of data read from the slave. More...
|
|
static void | LPI2C_HAL_SlaveWriteByte (LPI2C_Type *base, uint8_t byte) |
| Writes one byte of data to the LPI2C slave transmit FIFO. More...
|
|
bool | LPI2C_HAL_SlaveWriteByteBlocking (LPI2C_Type *base, uint8_t byte) |
| Writes one byte of data to the LPI2C bus and waits till that byte is transferred successfully. More...
|
|
uint8_t | LPI2C_HAL_MasterReadByteBlocking (LPI2C_Type *base) |
| Waits until there is a receive ready flag and reads one byte from the receive FIFO. More...
|
|
bool | LPI2C_HAL_MasterWriteByteBlocking (LPI2C_Type *base, uint8_t byte) |
| Waits till a transmit request flag is set and writes one byte of data to the transmit FIFO, then waits till that byte is transferred successfully. More...
|
|
lpi2c_status_t | LPI2C_HAL_MasterReceiveDataPolling (LPI2C_Type *base, uint16_t slaveAddr, const uint8_t *cmdBuff, uint32_t cmdSize, uint8_t *rxBuff, uint32_t rxSize) |
| Performs a polling receive transaction on the LPI2C bus. More...
|
|
lpi2c_status_t | LPI2C_HAL_MasterSendDataPolling (LPI2C_Type *base, uint16_t slaveAddr, const uint8_t *cmdBuff, uint32_t cmdSize, const uint8_t *txBuff, uint32_t txSize) |
| Performs a polling send transaction on the LPI2C bus. More...
|
|
lpi2c_status_t | LPI2C_HAL_SlaveSendDataPolling (LPI2C_Type *base, const uint8_t *txBuff, uint32_t txSize) |
| Sends out multiple bytes of data using the polling method. More...
|
|
lpi2c_status_t | LPI2C_HAL_SlaveReceiveDataPolling (LPI2C_Type *base, uint8_t *rxBuff, uint32_t rxSize) |
| Receives multiple bytes of data using the polling method. More...
|
|
Enumerator |
---|
kStatus_LPI2C_Success |
LPI2C operation has no error.
|
kStatus_LPI2C_Initialized |
Current LPI2C is already initialized by one task.
|
kStatus_LPI2C_Fail |
LPI2C operation failed.
|
kStatus_LPI2C_Busy |
The master is already performing a transfer.
|
kStatus_LPI2C_Timeout |
The transfer timed out.
|
kStatus_LPI2C_ReceivedNak |
The slave device sent a NAK in response to a byte.
|
kStatus_LPI2C_SlaveTxUnderrun |
LPI2C Slave TX Underrun error.
|
kStatus_LPI2C_SlaveRxOverrun |
LPI2C Slave RX Overrun error.
|
kStatus_LPI2C_AribtrationLost |
LPI2C Arbitration Lost error.
|
kStatus_LPI2C_StopSignalFail |
LPI2C STOP signal could not release bus.
|
kStatus_LPI2C_Idle |
LPI2C Slave Bus is Idle.
|
kStatus_LPI2C_NoReceiveInProgress |
Attempt to abort a receiving when no transfer was in progress.
|
kStatus_LPI2C_NoSendInProgress |
Attempt to abort a sending when no transfer was in progress.
|
Enumerator |
---|
kLPI2CWrite |
Master transmit.
Master receive.
|
void LPI2C_HAL_Init |
( |
LPI2C_Type * |
base | ) |
|
- Parameters
-
base | The LPI2C peripheral base pointer |
static void LPI2C_HAL_SetMasterCmd |
( |
LPI2C_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | The LPI2C peripheral base pointer |
enable | Enable(true) or disable(false) current LPI2C as master. |
static void LPI2C_HAL_SetSlaveCmd |
( |
LPI2C_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | The LPI2C peripheral base pointer |
enable | Enable(true) or disable(false) current LPI2C as slave. |
- Parameters
-
base | The LPI2C peripheral base pointer. |
statusFlag | The status flag, defined in type lpi2c_status_flag_t. |
- Returns
- State of the status flag: asserted (true) or not-asserted (false).
- true: related status flag is being set.
- false: related status flag is not set.
- Parameters
-
base | The LPI2C peripheral base pointer. |
statusFlag | The status flag, defined in type lpi2c_status_flag_t. |
- Parameters
-
base | The LPI2C peripheral base pointer. |
statusFlag | The status flag, defined in type lpi2c_status_flag_t. |
- Returns
- State of the status flag: asserted (true) or not-asserted (false).
- true: related status flag is being set.
- false: related status flag is not set.
- Parameters
-
base | The LPI2C peripheral base pointer. |
statusFlag | The status flag, defined in type lpi2c_status_flag_t. |
This function only enable/disable one specific interrupt. If you need to enable/disable multiple interrupt in one function call, it's better to use the entire register write operation.
- Parameters
-
base | The LPI2C peripheral base pointer |
interrupt | Interrupt name. |
enable | Pass true to enable interrupt, false to disable. |
- Parameters
-
base | The LPI2C peripheral base pointer |
- Returns
- Whethr LPI2C master interrupts are enabled(true) or not(false).
This function only enables/disables one specific interrupt. To enable/disable multiple interrupts in one function call, use the entire register write operation.
- Parameters
-
base | The LPI2C peripheral base pointer |
interrupt | Interrupt name. |
enable | Pass true to enable interrupt, false to disable. |
- Parameters
-
base | The LPI2C peripheral base pointer |
- Returns
- Whether LPI2C slave interrupts are enabled.
void LPI2C_HAL_SetBaudRate |
( |
LPI2C_Type * |
base, |
|
|
uint32_t |
sourceClockInHz, |
|
|
uint32_t |
kbps |
|
) |
| |
- Parameters
-
base | The LPI2C peripheral base pointer |
sourceClockInHz | LPI2C source input clock in Hertz |
kbps | Requested bus frequency in kilohertz. Common values are either 100 or 400. |
void LPI2C_HAL_SendStart |
( |
LPI2C_Type * |
base, |
|
|
uint8_t |
address, |
|
|
lpi2c_direction_t |
dir |
|
) |
| |
This function initiates a new master mode transfer by sending the start signal. It is also sends a repeated start signal when a transfer is already in progress.
- Parameters
-
base | The LPI2C peripheral base pointer |
address | 7-bit slave device address. |
dir | Master transfer directions(transmit/receive). |
- Parameters
-
base | The LPI2C peripheral base pointer |
- Returns
- Whether the sending of STOP single is success or not.
static void LPI2C_HAL_SlaveSendAck |
( |
LPI2C_Type * |
base | ) |
|
|
inlinestatic |
This function specifies that an ACK signal is sent in response to the next received byte.
Note that the behaviour of this function is changed when the LPI2C peripheral is placed in the fast ACK mode. In this case, this function causes an ACK signal to be sent in response to the current byte, rather than the next received byte.
- Parameters
-
base | The LPI2C peripheral base pointer |
static void LPI2C_HAL_SlaveSendNak |
( |
LPI2C_Type * |
base | ) |
|
|
inlinestatic |
This function specifies that a NAK signal is sent in response to the next received byte.
Note that the behaviour of this function is changed when the LPI2C peripheral is placed in the fast ACK mode. In this case, this function causes an NAK signal to be sent in response to the current byte, rather than the next received byte.
- Parameters
-
base | The LPI2C peripheral base pointer |
static void LPI2C_HAL_MasterSetRxMode |
( |
LPI2C_Type * |
base, |
|
|
uint8_t |
rxSize |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | The LPI2C peripheral base pointer. |
rxSize | Initialize receiving "rxSize" of bytes. |
void LPI2C_HAL_SetAddress7bit |
( |
LPI2C_Type * |
base, |
|
|
uint8_t |
address |
|
) |
| |
- Parameters
-
base | The LPI2C peripheral base pointer |
address | The slave address is in the upper 7 bits. |
void LPI2C_HAL_SetAddress10bit |
( |
LPI2C_Type * |
base, |
|
|
uint16_t |
address |
|
) |
| |
- Parameters
-
base | The LPI2C peripheral base pointer |
address | The 10-bit slave address, in bits [9:0] of the value. |
static uint8_t LPI2C_HAL_MasterReadByte |
( |
LPI2C_Type * |
base | ) |
|
|
inlinestatic |
In a master receive mode, calling this function initiates receiving the next byte of data.
- Parameters
-
base | The LPI2C peripheral base pointer |
- Returns
- This function returns the last byte received while the LPI2C module is configured in master receive or slave receive mode.
static void LPI2C_HAL_MasterWriteByte |
( |
LPI2C_Type * |
base, |
|
|
uint8_t |
byte |
|
) |
| |
|
inlinestatic |
When this function is called in the master transmit mode, a data transfer is initiated. In slave mode, the same function is available after an address match occurs.
In a master transmit mode, the first byte of data written following the start bit or repeated start bit is used for the address transfer and must consist of the slave address (in bits 7-1) concatenated with the required R/#W bit (in position bit 0).
- Parameters
-
base | The LPI2C peripheral base pointer. |
byte | The byte of data to transmit. |
static uint8_t LPI2C_HAL_SlaveReadByte |
( |
LPI2C_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | The LPI2C peripheral base pointer |
- Returns
- This function returns the last byte received while the LPI2C module is configured in slave receive mode.
static void LPI2C_HAL_SlaveWriteByte |
( |
LPI2C_Type * |
base, |
|
|
uint8_t |
byte |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | The LPI2C peripheral base pointer. |
byte | The byte of data to transmit. |
bool LPI2C_HAL_SlaveWriteByteBlocking |
( |
LPI2C_Type * |
base, |
|
|
uint8_t |
byte |
|
) |
| |
- Parameters
-
base | The LPI2C peripheral base pointer. |
byte | The byte of data to transmit. |
- Returns
- Whether ACK is received(TRUE) or not(FALSE).
uint8_t LPI2C_HAL_MasterReadByteBlocking |
( |
LPI2C_Type * |
base | ) |
|
- Parameters
-
base | The LPI2C peripheral base pointer |
- Returns
- Returns the last byte received
bool LPI2C_HAL_MasterWriteByteBlocking |
( |
LPI2C_Type * |
base, |
|
|
uint8_t |
byte |
|
) |
| |
- Parameters
-
base | The LPI2C peripheral base pointer. |
byte | The byte of data to transmit. |
- Returns
- Whether ACK is received(TRUE) or not(FALSE).
lpi2c_status_t LPI2C_HAL_MasterReceiveDataPolling |
( |
LPI2C_Type * |
base, |
|
|
uint16_t |
slaveAddr, |
|
|
const uint8_t * |
cmdBuff, |
|
|
uint32_t |
cmdSize, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize |
|
) |
| |
- Parameters
-
base | The LPI2C peripheral base pointer. |
salveAddr | The slave address to communicate. |
cmdBuff | The pointer to the commands to be transferred. |
cmdSize | The length in bytes of the commands to be transferred. |
rxBuff | The pointer to the data to be transferred. |
rxSize | The length in bytes of the data to be transferred. |
- Returns
- Error or success status returned by API.
lpi2c_status_t LPI2C_HAL_MasterSendDataPolling |
( |
LPI2C_Type * |
base, |
|
|
uint16_t |
slaveAddr, |
|
|
const uint8_t * |
cmdBuff, |
|
|
uint32_t |
cmdSize, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize |
|
) |
| |
- Parameters
-
base | The LPI2C peripheral base pointer. |
salveAddr | The slave address to communicate. |
cmdBuff | The pointer to the commands to be transferred. |
cmdSize | The length in bytes of the commands to be transferred. |
txBuff | The pointer to the data to be transferred. |
txSize | The length in bytes of the data to be transferred. |
- Returns
- Error or success status returned by API.
lpi2c_status_t LPI2C_HAL_SlaveSendDataPolling |
( |
LPI2C_Type * |
base, |
|
|
const uint8_t * |
txBuff, |
|
|
uint32_t |
txSize |
|
) |
| |
- Parameters
-
base | LPI2C module base pointer. |
txBuff | The buffer pointer which saves the data to be sent. |
txSize | Size of data to be sent in unit of byte. |
- Returns
- Error or success status returned by API.
lpi2c_status_t LPI2C_HAL_SlaveReceiveDataPolling |
( |
LPI2C_Type * |
base, |
|
|
uint8_t * |
rxBuff, |
|
|
uint32_t |
rxSize |
|
) |
| |
- Parameters
-
base | LPI2C module base pointer. |
rxBuff | The buffer pointer which saves the data to be received. |
rxSize | Size of data need to be received in unit of byte. |
- Returns
- Error or success status returned by API.