-
Notifications
You must be signed in to change notification settings - Fork 0
I2C Functions
This page contains information describing the use of functions relating to the I2C SUBLIBinal peripheral library. Please refer to the list below to be redirected to the appropriate documentation.
Definition
I2C_Data* initialize_I2C(I2C_Config config);
Description
The initialize_I2C()
function is used for configuring and initializing an I2C channel. This function will configure the I2C hardware for single-master mode, talking at 100 kHz. In addition, it will configure and initialize the given memory buffers.
Parameters
-
config: This parameter is an
I2C_Config
structure. The user should fill out all elements of the structure before callinginitialize_I2C()
.
Return Value
This function returns a pointer to an I2C_Data
structure. This structure is described in the I2C Structures documentation. This is meant to hand a pointer to the structure for querying I2C status. This structure should not be modified by the user. It is acceptable to not maintain a pointer to the structure in your main program. If you do not keep the pointer returned by this function, the I2C will still function normally.
Definition
Error send_I2C(I2C_Channel channel, I2C_Node node);
Description
The send_I2C()
function will place an I2C Node on the work queue of the I2C for processing. When a node is placed on the queue, it will check if the I2C ISR is idle, and force-start the transaction if necessary. Otherwise, the transaction will begin after the bus has completed any current transactions. This function will copy all contents specified in the node
parameter, so it may leave scope in user defined functions, with the exception of the data_buffer
, this memory location must remain valid for the remainder of the transaction.
Parameters
-
channel: This parameter specifies which channel will be used for the I2C communication contained within the
node
parameter. -
node: This function accepts a completely filled out
I2C_Node
structure. All parameters of the structure should be filled out. The callback function specified within this node should accept a single I2C_Node data type as an input parameter and should returnvoid
. This function will be called when a node has finished processing and will be called from the background process. When the ISR completes a transaction for the node, it is moved from the work buffer to the result buffer.
Return
This function will return an ERROR
enumeration based upon a node insertion into the work queue. The only case that this will return an error is if the queue does not have sufficient space for copying the node into it.
Definition
void bg_process_I2C(void);
Description
The I2C background process should be placed in the main embedded system loop so that processing of completed I2C transactions can occur when the processor is not busy. The reason behind doing processing in a background process is to ensure that the microcontroller can successfully handle interrupts during processing of individual node elements. The function of the background process is to simply dequeue nodes from the I2C results queue and then call those nodes' callback functions. These callback functions are unique in that the background process will call them with a single input parameter. Nodes callback functions will be called and provided a I2C_Data
data type that is the node itself. This is so that user can access the data and do something with it.
Parameters
This function accepts no parameters and returns no parameters. This function must be placed within the main embedded loop if the I2C bus is used.
SUBLIBinal was created by the Palouse Robosub Club.