PIC18 LaurTec Library  3.3.1
Open Source C Library for PIC18 Microcontrollers based on C18 - XC8 Compilers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
i2cEEPROM.h File Reference
#include <i2c.h>
#include <delay.h>

Go to the source code of this file.

Macros

#define initialize_I2C_EEPROM   I2C_EEPROM_initialize
 
#define write_I2C_EEPROM   I2C_EEPROM_write
 
#define write_I2C_EEPROM_check   I2C_EEPROM_write_check
 
#define read_I2C_EEPROM   I2C_EEPROM_read
 

Functions

void I2C_EEPROM_initialize (unsigned char crystal_frequency_MHz, unsigned int baud_rate_KHz)
 
signed char I2C_EEPROM_write (unsigned char control, unsigned int address, unsigned char data)
 
signed char I2C_EEPROM_write_check (unsigned char control, unsigned int address, unsigned char data)
 
signed char I2C_EEPROM_read (unsigned char control, unsigned int address, unsigned char *data)
 

Macro Definition Documentation

#define initialize_I2C_EEPROM   I2C_EEPROM_initialize

Definition at line 75 of file i2cEEPROM.h.

#define read_I2C_EEPROM   I2C_EEPROM_read

Definition at line 143 of file i2cEEPROM.h.

#define write_I2C_EEPROM   I2C_EEPROM_write

Definition at line 96 of file i2cEEPROM.h.

#define write_I2C_EEPROM_check   I2C_EEPROM_write_check

Definition at line 120 of file i2cEEPROM.h.

Function Documentation

void I2C_EEPROM_initialize ( unsigned char  crystal_frequency_MHz,
unsigned int  baud_rate_KHz 
)

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

Parameters
crystal_frequency_MHzClock frequency expressed in MHz
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 56 of file i2cEEPROM.c.

References setQuartz.

signed char I2C_EEPROM_read ( 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. (i.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 1: 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 233 of file i2cEEPROM.c.

signed char I2C_EEPROM_write ( 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. (i.g 0xA0)
Returns
status 1: 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 72 of file i2cEEPROM.c.

signed char I2C_EEPROM_write_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. (i.g 0xA0)
Returns
status 1: 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 201 of file i2cEEPROM.c.

References delay_ms(), read_I2C_EEPROM, and write_I2C_EEPROM.