EVE 1.0
nRF52 I2C bus master driver
Collaboration diagram for nRF52 I2C bus master driver:

Data Structures

struct  i2c_state_t
 
struct  i2c_t
 

Typedefs

typedef void(* i2c_completion_callback_t) (const struct i2c_t *I2c, uint8_t ErrorMask, void *Data)
 

Functions called from application programs

void I2cMasterInit (const struct i2c_t *I2cMaster)
 Name: I2cMasterInit
Initialize the driver. Function must be called before driver use. More...
 
void I2cBusReset (const struct i2c_t *I2cMaster)
 Name: I2cBusReset
Reset the bus (clock through a bus hung) More...
 
bool I2cMasterAsync (const struct i2c_t *I2cMaster, uint8_t SlaveAddress, const void *SrcBuffer, uint8_t SrcCount, void *DstBuffer, uint8_t DstCount, i2c_completion_callback_t Callback, void *CallbackData)
 Name: I2cMasterAsync
Setup the microcontroller to I2C master based on the i2c_t structure (slave not supported). Then the driver does: More...
 
void I2cMasterSchedule (const struct i2c_t *I2cMaster, struct work_t *Work)
 Name: I2cMasterSchedule
Schedule work when I2C bus becomes available.
In case the bus is already free, the work is scheduled immediately. More...
 
bool I2cMasterAsyncWait (const struct i2c_t *I2cMaster, uint8_t SlaveAddress, const void *SrcBuffer, uint8_t SrcCount, void *DstBuffer, uint8_t DstCount, i2c_completion_callback_t Callback, void *CallbackData, struct work_t *Work)
 Name: I2cMasterAsyncWait
Setup the microcontroller to I2C master based on the i2c_t structure (slave not supported). Then the driver does: More...
 
bool I2cMaster (const struct i2c_t *I2cMaster, uint8_t SlaveAddress, const void *SrcBuffer, uint16_t SrcCount, void *DstBuffer, uint16_t DstCount)
 Name: I2cMaster
Setup the microcontroller to I2C master based on the i2c_t structure (slave not supported). Then the driver does: More...
 
void I2cMasterInterruptHandler (const struct i2c_t *I2cMaster)
 Name: I2cInterruptHandler
I2C master interrupt handler Called from board.c at hardware interrupt context. More...
 

Detailed Description

This I2C driver can be used for I2C0 and I2C1.

First the driver setup the microcontroller to I2C master based on the i2c_t structure. Then the driver does:

The driver returns true if communication OK, else false.

While the I2C communication is in progress, the clock is locked and energy mode EM1 is minimum required.

Typedef Documentation

typedef void(* i2c_completion_callback_t) (const struct i2c_t *I2c, uint8_t ErrorMask, void *Data)

Asynchronous callback type

Parameters
I2cPointer to the I2C master instance object
ErrorMaskBitmap of the possible bus error types, see enum i2c_error_t
DataUser data passed as I2cMasterAsync function parameter

Definition at line 82 of file i2c-master.h.

Function Documentation

void I2cMasterInit ( const struct i2c_t I2cMaster)

Name: I2cMasterInit
Initialize the driver. Function must be called before driver use.

Parameters
I2cMasterPointer to I2C module
void I2cBusReset ( const struct i2c_t I2cMaster)

Name: I2cBusReset
Reset the bus (clock through a bus hung)

Parameters
I2cMasterPointer to I2C module
bool I2cMasterAsync ( const struct i2c_t I2cMaster,
uint8_t  SlaveAddress,
const void *  SrcBuffer,
uint8_t  SrcCount,
void *  DstBuffer,
uint8_t  DstCount,
i2c_completion_callback_t  Callback,
void *  CallbackData 
)

Name: I2cMasterAsync
Setup the microcontroller to I2C master based on the i2c_t structure (slave not supported). Then the driver does:

  • Generates start condition
  • Transmits slave address
  • Transmits from 0 til SrcCount bytes from the buffer SrcBuffer
  • Generates restart condition if bytes should be received (DstCount > 0), then receives DstCount bytes to the buffer DstBuffer
  • ACK is sent for each received byte except for the last on where NACK is sent.
  • Generates stop condition The transfer duration (number of bytes to transfer) must not exceed 50 ms.
Parameters
I2cMasterPointer to I2C module
SlaveAddressIIC slave address
SrcBufferPointer to data to be written
SrcCountNumber of bytes to write
DstBufferPointer to buffer to place read data
DstCountNumber of bytes to read
CallbackCompletion callback
CallbackDataCompletion callback data
Returns
true if communication started, else false

Referenced by I2cMasterAsyncWait().

void I2cMasterSchedule ( const struct i2c_t I2cMaster,
struct work_t Work 
)

Name: I2cMasterSchedule
Schedule work when I2C bus becomes available.
In case the bus is already free, the work is scheduled immediately.

Parameters
I2cMasterPointer to I2C module
WorkWork to be scheduled immediately if I2C is free, otherwise after I2C becomes free.

Referenced by I2cMasterAsyncWait().

bool I2cMasterAsyncWait ( const struct i2c_t I2cMaster,
uint8_t  SlaveAddress,
const void *  SrcBuffer,
uint8_t  SrcCount,
void *  DstBuffer,
uint8_t  DstCount,
i2c_completion_callback_t  Callback,
void *  CallbackData,
struct work_t Work 
)
inline

Name: I2cMasterAsyncWait
Setup the microcontroller to I2C master based on the i2c_t structure (slave not supported). Then the driver does:

  • Generates start condition
  • Transmits slave address
  • Transmits from 0 til SrcCount bytes from the buffer SrcBuffer
  • Generates restart condition if bytes should be received (DstCount > 0), then receives DstCount bytes to the buffer DstBuffer
  • ACK is sent for each received byte except for the last on where NACK is sent.
  • Generates stop condition The transfer duration (number of bytes to transfer) must not exceed 50 ms.
Parameters
I2cMasterPointer to I2C module
SlaveAddressIIC slave address
SrcBufferPointer to data to be written
SrcCountNumber of bytes to write
DstBufferPointer to buffer to place read data
DstCountNumber of bytes to read
CallbackCompletion callback
CallbackDataCompletion callback data
WorkIf I2C is busy, the Work to be scheduled after I2C is free again.
Returns
true if communication started, false if work will be scheduled.

Definition at line 218 of file i2c-master.h.

References I2cMaster(), I2cMasterAsync(), I2cMasterInterruptHandler(), and I2cMasterSchedule().

bool I2cMaster ( const struct i2c_t I2cMaster,
uint8_t  SlaveAddress,
const void *  SrcBuffer,
uint16_t  SrcCount,
void *  DstBuffer,
uint16_t  DstCount 
)

Name: I2cMaster
Setup the microcontroller to I2C master based on the i2c_t structure (slave not supported). Then the driver does:

  • Generates start condition
  • Transmits slave address
  • Transmits from 0 til SrcCount bytes from the buffer SrcBuffer
  • Generates restart condition if bytes should be received (DstCount > 0), then receives DstCount bytes to the buffer DstBuffer
  • ACK is sent for each received byte except for the last on where NACK is sent.
  • Generates stop condition The transfer duration (number of bytes to transfer) must not exceed 50 ms.
Parameters
I2cMasterPointer to I2C module
SlaveAddressIIC slave address
SrcBufferPointer to data to be written
SrcCountNumber of bytes to write
DstBufferPointer to buffer to place read data
DstCountNumber of bytes to read
Returns
true if communication OK, else false

Referenced by I2cMasterAsyncWait().

void I2cMasterInterruptHandler ( const struct i2c_t I2cMaster)

Name: I2cInterruptHandler
I2C master interrupt handler Called from board.c at hardware interrupt context.

Parameters
I2cMasterI2C parameters to be used

Referenced by I2cMasterAsyncWait().