LTlib LaurTec Library
4.0.0 Beta
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
|
#include "LTlib.h"
Go to the source code of this file.
Macros | |
#define | I2C_SLAVE_7_BIT_ADDRESS 0b00000110 |
#define | I2C_SLAVE_10_BIT_ADDRESS 0b00000111 |
#define | I2C_MASTER 0b00001000 |
#define | I2C_SLEW_ON 0b00000000 |
#define | I2C_SLEW_OFF 0b10000000 |
#define | I2C1_read_byte() (SSPBUF) |
#define | I2C1_check_data_ready() (SSPSTATbits.BF) |
#define | I2C1_check_read_write_operation() (SSPSTATbits.R_W) |
#define | I2C1_check_stop_bit() (SSPSTATbits.P) |
#define | I2C1_check_start_bit() (SSPSTATbits.S) |
#define | I2C1_check_bus_collision() (PIR2bits.BCLIF) |
#define | I2C1_check_ACK() (SSPCON2bits.ACKSTAT) |
#define | I2C1_restart_communication() SSPCON2bits.RSEN=1;while(SSPCON2bits.RSEN) |
#define | I2C1_negative_ACK() SSPCON2bits.ACKDT=1, SSPCON2bits.ACKEN=1;while(SSPCON2bits.ACKEN) |
#define | I2C1_set_master_as_receiver() SSPCON2bits.RCEN = 1;while (SSPCON2bits.RCEN) |
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) |
signed char | I2C1_write_byte (unsigned char byte_to_send) |
void | I2C1_wait_bus_IDLE (void) |
void | I2C1_start_bit (void) |
void | I2C1_stop_bit (void) |
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) |
#define I2C1_check_ACK | ( | ) | (SSPCON2bits.ACKSTAT) |
This macro checks if the ACK has been received.
void |
Definition at line 355 of file module_I2C.h.
#define I2C1_check_bus_collision | ( | ) | (PIR2bits.BCLIF) |
This macro checks if a bus collision happened.
void |
Definition at line 339 of file module_I2C.h.
#define I2C1_check_data_ready | ( | ) | (SSPSTATbits.BF) |
This macro checks if there is any data ready in the RX buffer.
void |
Definition at line 273 of file module_I2C.h.
#define I2C1_check_read_write_operation | ( | ) | (SSPSTATbits.R_W) |
This macro checks if received command is a read or write operation.
void |
Definition at line 290 of file module_I2C.h.
#define I2C1_check_start_bit | ( | ) | (SSPSTATbits.S) |
This macro checks if the stop bit has been detected.
void |
Definition at line 323 of file module_I2C.h.
#define I2C1_check_stop_bit | ( | ) | (SSPSTATbits.P) |
This macro checks if the stop bit has been detected.
void |
Definition at line 306 of file module_I2C.h.
#define I2C1_negative_ACK | ( | ) | SSPCON2bits.ACKDT=1, SSPCON2bits.ACKEN=1;while(SSPCON2bits.ACKEN) |
This macro release a negative ACK sequence NACK
void |
Definition at line 384 of file module_I2C.h.
#define I2C1_read_byte | ( | ) | (SSPBUF) |
This macro reads the input buffer.
void |
Definition at line 134 of file module_I2C.h.
#define I2C1_restart_communication | ( | ) | SSPCON2bits.RSEN=1;while(SSPCON2bits.RSEN) |
This macro restarts the I2C module
void |
Definition at line 370 of file module_I2C.h.
#define I2C1_set_master_as_receiver | ( | ) | SSPCON2bits.RCEN = 1;while (SSPCON2bits.RCEN) |
This macro set the I2C module as receiver to enable the data read (read sequence).
void |
Definition at line 398 of file module_I2C.h.
#define I2C_MASTER 0b00001000 |
Definition at line 58 of file module_I2C.h.
#define I2C_SLAVE_10_BIT_ADDRESS 0b00000111 |
Definition at line 57 of file module_I2C.h.
#define I2C_SLAVE_7_BIT_ADDRESS 0b00000110 |
Definition at line 56 of file module_I2C.h.
#define I2C_SLEW_OFF 0b10000000 |
Definition at line 64 of file module_I2C.h.
#define I2C_SLEW_ON 0b00000000 |
Definition at line 61 of file module_I2C.h.
void I2C1_baud_rate | ( | unsigned int | bus_baud_rate_KHZ | ) |
This function sets the bus baudrate in case the device is a Master device.
bus_baud_rate_KHZ | Baud Rate espressed in KHz [min: 1, max:400] |
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.
device_type | It specifies if the device is a Master or a Slave [I2C_MASTER, I2C_SLAVE_7_BIT_ADDRESS, I2C_SLAVE_10_BIT_ADDRESS] |
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.
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.
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.
device_address | Slave Address |
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).
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).
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.
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.
byte_to_send | Byte to be sent out |
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.
control_byte | Control byte of the external device register_address Address to be written within the external device data Data to be wirtten within the pointed address |
Definition at line 307 of file module_I2C.c.
References I2C1_start_bit(), I2C1_stop_bit(), I2C1_wait_bus_IDLE(), and I2C1_write_byte().