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

Go to the source code of this file.

Macros

#define EEPROM_I2C_MODULE_1
 
#define EEPROM_I2C_open   I2C1_open
 
#define EEPROM_I2C_baud_rate   I2C1_baud_rate
 
#define EEPROM_I2C_wait_bus_IDLE   I2C1_wait_bus_IDLE
 
#define EEPROM_I2C_start_bit   I2C1_start_bit
 
#define EEPROM_I2C_stop_bit   I2C1_stop_bit
 
#define EEPROM_I2C_write_byte   I2C1_write_byte
 
#define EEPROM_I2C_check_bus_collision   I2C1_check_bus_collision
 
#define EEPROM_I2C_check_ACK   I2C1_check_ACK
 
#define EEPROM_I2C_negative_ACK   I2C1_negative_ACK
 
#define EEPROM_I2C_set_master_as_receiver   I2C1_set_master_as_receiver
 
#define EEPROM_I2C_read_byte   I2C1_read_byte
 
#define EEPROM_I2C_restart_communication   I2C1_restart_communication
 
#define initialize_I2C_EEPROM   I2C_EEPROM_initialize
 
#define write_I2C_EEPROM   I2C_EEPROM_write_byte
 
#define I2C_EEPROM_write   I2C_EEPROM_write_byte
 
#define write_I2C_EEPROM_check   I2C_EEPROM_write_byte_check
 
#define I2C_EEPROM_write_check   I2C_EEPROM_write_byte_check
 
#define read_I2C_EEPROM   I2C_EEPROM_read_byte
 
#define I2C_EEPROM_read   I2C_EEPROM_read_byte
 

Functions

void I2C_EEPROM_initialize (unsigned int baud_rate_KHz)
 
signed char I2C_EEPROM_write_byte (unsigned char control, unsigned int address, unsigned char data)
 
signed char I2C_EEPROM_write_byte_check (unsigned char control, unsigned int address, unsigned char data)
 
signed char I2C_EEPROM_read_byte (unsigned char control, unsigned int address, unsigned char *data)
 

Macro Definition Documentation

#define EEPROM_I2C_baud_rate   I2C1_baud_rate

Definition at line 74 of file I2C_EEPROM.h.

#define EEPROM_I2C_check_ACK   I2C1_check_ACK

Definition at line 80 of file I2C_EEPROM.h.

#define EEPROM_I2C_check_bus_collision   I2C1_check_bus_collision

Definition at line 79 of file I2C_EEPROM.h.

#define EEPROM_I2C_MODULE_1

Definition at line 69 of file I2C_EEPROM.h.

#define EEPROM_I2C_negative_ACK   I2C1_negative_ACK

Definition at line 81 of file I2C_EEPROM.h.

#define EEPROM_I2C_open   I2C1_open

Definition at line 73 of file I2C_EEPROM.h.

#define EEPROM_I2C_read_byte   I2C1_read_byte

Definition at line 83 of file I2C_EEPROM.h.

#define EEPROM_I2C_restart_communication   I2C1_restart_communication

Definition at line 84 of file I2C_EEPROM.h.

#define EEPROM_I2C_set_master_as_receiver   I2C1_set_master_as_receiver

Definition at line 82 of file I2C_EEPROM.h.

#define EEPROM_I2C_start_bit   I2C1_start_bit

Definition at line 76 of file I2C_EEPROM.h.

#define EEPROM_I2C_stop_bit   I2C1_stop_bit

Definition at line 77 of file I2C_EEPROM.h.

#define EEPROM_I2C_wait_bus_IDLE   I2C1_wait_bus_IDLE

Definition at line 75 of file I2C_EEPROM.h.

#define EEPROM_I2C_write_byte   I2C1_write_byte

Definition at line 78 of file I2C_EEPROM.h.

#define I2C_EEPROM_read   I2C_EEPROM_read_byte

Definition at line 186 of file I2C_EEPROM.h.

#define I2C_EEPROM_write   I2C_EEPROM_write_byte

Definition at line 138 of file I2C_EEPROM.h.

#define I2C_EEPROM_write_check   I2C_EEPROM_write_byte_check

Definition at line 163 of file I2C_EEPROM.h.

#define initialize_I2C_EEPROM   I2C_EEPROM_initialize

Definition at line 116 of file I2C_EEPROM.h.

#define read_I2C_EEPROM   I2C_EEPROM_read_byte

Definition at line 185 of file I2C_EEPROM.h.

#define write_I2C_EEPROM   I2C_EEPROM_write_byte

Definition at line 137 of file I2C_EEPROM.h.

#define write_I2C_EEPROM_check   I2C_EEPROM_write_byte_check

Definition at line 162 of file I2C_EEPROM.h.

Function Documentation

void I2C_EEPROM_initialize ( unsigned int  baud_rate_KHz)

This function initialize the I2C module accordingly to the clock and baud rate.

Parameters
baud_rate_KHzBaud rate expressed in KHz
Returns
Note
If other devices are connected on the I2C bus the baud rate would be changed by the function. Among several calls from different device initializations, only the last one will be reflected in the I2C module configuration.

Definition at line 54 of file I2C_EEPROM.c.

References EEPROM_I2C_baud_rate, EEPROM_I2C_open, and I2C_MASTER.

signed char I2C_EEPROM_read_byte ( unsigned char  control,
unsigned int  address,
unsigned char *  data 
)

This function reads a byte from an external I2C EEPROM.

Parameters
controlIs the address of the EEPROM set with the external address pins and the internal one. The bit R/'W set to 0. (e.g 0xA0)
addressAddress where the byte must be read out [min: 0, max: depends on the EEPROM]
*dataAddress of the variable where the read data will be written into.
Returns
status 0: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
This function only supports EEPROM which have two bytes for the address [min EEPROM is 25L32].

Definition at line 205 of file I2C_EEPROM.c.

References EEPROM_I2C_check_ACK, EEPROM_I2C_check_bus_collision, EEPROM_I2C_negative_ACK, EEPROM_I2C_read_byte, EEPROM_I2C_restart_communication, EEPROM_I2C_set_master_as_receiver, EEPROM_I2C_start_bit, EEPROM_I2C_stop_bit, EEPROM_I2C_wait_bus_IDLE, and EEPROM_I2C_write_byte.

signed char I2C_EEPROM_write_byte ( unsigned char  control,
unsigned int  address,
unsigned char  data 
)

This function writes a byte inside an I2C external EEPROM.

Parameters
dataByte to write [min: 0, max: 255]
addressAddress where the byte must be written [min: 0, max: depends on the EEPROM]
controlIs the address of the EEPROM set with the external address pins and the internal one. The bit R/'W set to 0. (e.g 0xA0)
Returns
status 0: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision
Note
This function only supports EEPROM which have two bytes for the address [min EEPROM is 25L32].

Definition at line 66 of file I2C_EEPROM.c.

References EEPROM_I2C_check_ACK, EEPROM_I2C_check_bus_collision, EEPROM_I2C_start_bit, EEPROM_I2C_stop_bit, EEPROM_I2C_wait_bus_IDLE, and EEPROM_I2C_write_byte.

signed char I2C_EEPROM_write_byte_check ( unsigned char  control,
unsigned int  address,
unsigned char  data 
)

This function writes a byte inside the EEPROM but it reads back the value to make sure that it has been properly written. It's slower than the other one due to this feature.

Parameters
dataByte to write [min: 0, max: 255]
addressAddress where the byte must be written [min: 0, max: depends on the EEPROM]
controlIs the address of the EEPROM set with the external address pins and the internal one. The bit R/'W set to 0. (e.g 0xA0)
Returns
status 0: The byte has been properly written -1: Bus Collision error -2: Not Ack error condition -3: Write collision -4: Readback error
Note
This function only supports EEPROM which have two bytes for the address [min EEPROM is 25L32].
To make this library works you need to include the delay library as well.

Definition at line 173 of file I2C_EEPROM.c.

References delay_ms(), I2C_EEPROM_read_byte(), and I2C_EEPROM_write_byte().