LTlib LaurTec Library  4.0.0 Beta
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
module_I2C.c File Reference
#include "module_I2C.h"

Go to the source code of this file.

Functions

void I2C1_open (unsigned char device_type)
 
void I2C1_baud_rate (unsigned int bus_baud_rate_KHZ)
 
void I2C1_set_slave_address (unsigned int device_address)
 
void I2C1_wait_bus_IDLE (void)
 
void I2C1_start_bit (void)
 
void I2C1_stop_bit (void)
 
signed char I2C1_write_byte (unsigned char byte_to_send)
 
void I2C1_reset_write_collision_flag (void)
 
signed char I2C1_write_byte_to_external_device (unsigned char control_byte, unsigned char register_address, unsigned char data)
 
signed char I2C1_read_byte_from_external_device (unsigned char control_byte, unsigned char register_address)
 

Function Documentation

void I2C1_baud_rate ( unsigned int  bus_baud_rate_KHZ)

This function sets the bus baudrate in case the device is a Master device.

Parameters
bus_baud_rate_KHZBaud Rate espressed in KHz [min: 1, max:400]
Returns
void

You must not set the buadrate for a slave device. Doing so may change the slave address.

Definition at line 107 of file module_I2C.c.

References I2C_CLOCK.

void I2C1_open ( unsigned char  device_type)

This function Opens the I2C module enabling SCL and SDA lines.

Parameters
device_typeIt specifies if the device is a Master or a Slave [I2C_MASTER, I2C_SLAVE_7_BIT_ADDRESS, I2C_SLAVE_10_BIT_ADDRESS]
Returns
void

You must use the constants I2C_MASTER, I2C_SLAVE_7_BIT_ADDRESS, I2C_SLAVE_10_BIT_ADDRESS. By default the slew rate is turned on to support communications up to 400KHz.

Definition at line 47 of file module_I2C.c.

References I2C1_read_byte, I2C_SLEW_ON, and PIN_AS_INPUT.

signed char I2C1_read_byte_from_external_device ( unsigned char  control_byte,
unsigned char  register_address 
)

This function read a byte from an external device made of 1 control byte, 1 addres byte.

Returns
error Communication error or data byte 0: No communication error -1: Bus Collision error -2: Not ACK Error -3: Write Collision
void

Definition at line 412 of file module_I2C.c.

References I2C1_negative_ACK, I2C1_restart_communication, I2C1_start_bit(), I2C1_stop_bit(), I2C1_wait_bus_IDLE(), and I2C1_write_byte().

void I2C1_reset_write_collision_flag ( void  )

This function resets the write collision bit.

Parameters
void
Returns
void

Definition at line 293 of file module_I2C.c.

void I2C1_set_slave_address ( unsigned int  device_address)

This function sets I2C slave address.

Parameters
device_addressSlave Address
Returns
void

Definition at line 121 of file module_I2C.c.

void I2C1_start_bit ( void  )

This function releases the start bit and waits until Start bit is out (idle).

Parameters
void
Returns
void

This is a blocking function.

Definition at line 152 of file module_I2C.c.

void I2C1_stop_bit ( void  )

This function releases the stop bit and waits until Stop bit is out (idle).

Parameters
void
Returns
void

This is a blocking function.

Definition at line 173 of file module_I2C.c.

void I2C1_wait_bus_IDLE ( void  )

This function waits for the bus to be Idle before continuing.

Parameters
void
Returns
void

Definition at line 137 of file module_I2C.c.

signed char I2C1_write_byte ( unsigned char  byte_to_send)

This function writes a byte to the output buffer and performs several error tests.

Parameters
byte_to_sendByte to be sent out
Returns
error 0: ACK received for the byte sent out -1: Bus Conflict occurs -2: NACK has been received -3: Unkown Error

Definition at line 190 of file module_I2C.c.

References I2C1_wait_bus_IDLE().

signed char I2C1_write_byte_to_external_device ( unsigned char  control_byte,
unsigned char  register_address,
unsigned char  data 
)

This function write a byte to an external device made of 1 control byte, 1 addres byte and 1 byte data.

Parameters
control_byteControl byte of the external device register_address Address to be written within the external device data Data to be wirtten within the pointed address
Returns
error Communication error 0: No communication error -1: Bus Collision error -2: Not ACK Error -3: Write Collision

Definition at line 307 of file module_I2C.c.

References I2C1_start_bit(), I2C1_stop_bit(), I2C1_wait_bus_IDLE(), and I2C1_write_byte().