at24c32 access library
Macros | Functions
at24c32.h File Reference

include file to be used in conjuction of the at24c32 library More...

#include <stdio.h>
#include <sys/ioctl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <linux/fs.h>
#include <fcntl.h>
#include <errno.h>
#include <smbus_access.h>
#include <stdbool.h>
Include dependency graph for at24c32.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define I2C_DRIVER   "/dev/i2c-1"
 
#define AT24C32   0x50
 
#define AT24C32_SUCCESS   0
 
#define AT24C32_SIZE   4096
 

Functions

int at24c32Open (void)
 
int at24c32Close (int)
 closes the i2c driver More...
 
int at24c32ByteWrite (int, unsigned short, unsigned char)
 writes a byte to the EEPROM More...
 
unsigned char at24c32ByteRead (int, unsigned short)
 reads a byte from the EEPROM More...
 
int at24c32BlockWrite (int, unsigned short, unsigned short, unsigned char *)
 writes a block of data to the EEPROM More...
 
unsigned char * at24c32BlockRead (int, unsigned short, unsigned short)
 reads a block of data from the EEPROM More...
 
unsigned char at24c32CurrentAddressRead (int)
 
void at24c32SetDebug (bool)
 switches debug mode on or off More...
 

Detailed Description

include file to be used in conjuction of the at24c32 library

Copyright U. Raich Dec. 2016

This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2017
It is released under the GNU Public License For details please see https://www.gnu.org/licenses/gpl.html

Function Documentation

unsigned char* at24c32BlockRead ( int  fd,
unsigned short  address,
unsigned short  length 
)

reads a block of data from the EEPROM

Parameters
intfd: the file descriptor returned by a24c32Open
unsignedshort address: the memory address to read from
unsignedshort length: the number of bytes to be read
Returns
the data are put into a unsigned char array
int at24c32BlockWrite ( int  fd,
unsigned short  address,
unsigned short  length,
unsigned char *  data 
)

writes a block of data to the EEPROM

Parameters
intfd: the file descriptor returned by a24c32Open
unsignedshort address: the memory address to write to
unsignedshort length: the length of the data array
unsignedchar *data: a pointer to the data that must be written
Returns
0 if successful
a negative error code otherwise
unsigned char at24c32ByteRead ( int  fd,
unsigned short  address 
)

reads a byte from the EEPROM

Parameters
intfd: the file descriptor returned by a24c32Open
unsignedshort address: the memory address to read from
Returns
the data byte read
int at24c32ByteWrite ( int  fd,
unsigned short  address,
unsigned char  data 
)

writes a byte to the EEPROM

Parameters
intfd: the file descriptor returned by a24c32Open
unsignedshort address: the memory address to write to
unsignedchar data: the data word to be written
Returns
0 if successful
a negative error code otherwise
int at24c32Close ( int  fd)

closes the i2c driver

Parameters
thefile descriptor to be close
Returns
0 if successful a negative error code otherwise
int at24c32Open ( void  )

opens the i2c driver

Returns
a file descriptor to be used as input parameter for all subsequent calls
void at24c32SetDebug ( bool  onOff)

switches debug mode on or off

Parameters
onOfftrue: switches debug mode on
false: switches debug mode off