at24cxx.c File Reference


Detailed Description

AT24cxx driver for AVR32 UC3.

This file is the AT24cxx driver.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file at24cxx.c.

#include "board.h"
#include "compiler.h"
#include "gpio.h"
#include "conf_at24cxx.h"
#include "at24cxx.h"
#include "cycle_counter.h"
#include "twim.h"

Go to the source code of this file.

Functions

void at24cxx_init (int32_t fcpu)
 This function will initialize the AT24CXX serial EEPROM.
uint8_t at24cxx_read_byte (uint16_t byte_address)
 Read single byte from serial EEPROM.
void at24cxx_read_continuous (uint16_t start_address, uint16_t length, uint8_t *rd_buffer)
 Read bytes continously from the serial EEPROM.
void at24cxx_write_byte (uint16_t byte_address, uint8_t byte_value)
 Write single byte to the serial EEPROM.
void at24cxx_write_continuous (uint16_t start_address, uint16_t length, uint8_t const *wr_buffer)
 Write bytes continously to the serial EEPROM.

Variables

static uint32_t cpu_hz


Function Documentation

void at24cxx_init ( int32_t  fcpu  ) 

This function will initialize the AT24CXX serial EEPROM.

Note:
Must be called before any of the access functions.
Return values:
true AT24CXX device ready to use.
false Not able to initialize the AT24CXX device.

Definition at line 63 of file at24cxx.c.

References cpu_hz.

Referenced by main().

00063                                 {
00064         /* Store cpu frequency locally*/
00065         cpu_hz = fcpu;
00066 }

uint8_t at24cxx_read_byte ( uint16_t  byte_address  ) 

Read single byte from serial EEPROM.

Parameters:
[in] byte_address Address of byte to read.
[out] read_byte Pointer to memory where the read byte will be stored.
Return values:
true Byte read successfully.
false Byte could not be read.

Definition at line 109 of file at24cxx.c.

References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.

Referenced by main().

00109                                                  {
00110   uint8_t data;
00111   twi_package_t twi_package;
00112 
00113   twi_package.chip = AT24CXX_TWI_ADDRESS;
00114   twi_package.addr_length = 0;
00115   twi_package.buffer = &byte_address;
00116   twi_package.length = 2;
00117   while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
00118 
00119   twi_package.chip = AT24CXX_TWI_ADDRESS;
00120   twi_package.addr_length = 0;
00121   twi_package.buffer = &data;
00122   twi_package.length = 1;
00123   while(twi_master_read(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
00124 
00125 
00126   return data;
00127 
00128 }

void at24cxx_read_continuous ( uint16_t  start_address,
uint16_t  length,
uint8_t *  rd_buffer 
)

Read bytes continously from the serial EEPROM.

Parameters:
[in] start_address Address of first byte to read.
[in] length Number of bytes to read.
[out] rd_buffer Pointer to memory where the read bytes will be stored.
Return values:
true Bytes read successfully.
false Bytes could not be read.

Definition at line 131 of file at24cxx.c.

References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.

00131                                                                                           {
00132   twi_package_t twi_package;
00133 
00134   twi_package.chip = AT24CXX_TWI_ADDRESS;
00135   twi_package.addr_length = 0;
00136   twi_package.buffer = &start_address;
00137   twi_package.length = 2;
00138   while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
00139 
00140   twi_package.chip = AT24CXX_TWI_ADDRESS;
00141   twi_package.addr_length = 0;
00142   twi_package.buffer = rd_buffer;
00143   twi_package.length = length;
00144   while(twi_master_read(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
00145 
00146 }

void at24cxx_write_byte ( uint16_t  byte_address,
uint8_t  byte_value 
)

Write single byte to the serial EEPROM.

Parameters:
[in] byte_address Address of byte to write.
[in] byte_value Value that will be written to the specified address.
Return values:
true Byte written successfully.
false Byte could not be written.

Definition at line 69 of file at24cxx.c.

References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.

Referenced by main().

00069                                                                    {
00070   uint8_t pack[3];
00071   twi_package_t twi_package;
00072 
00073   pack[0] = (byte_address&0xFF00)>>8;
00074   pack[1] = byte_address&0xFF;
00075   pack[2] = byte_value;
00076 
00077   twi_package.chip = AT24CXX_TWI_ADDRESS;
00078   twi_package.addr_length = 1;
00079   twi_package.buffer = &pack;
00080   twi_package.length = sizeof(pack);
00081 
00082   while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
00083 
00084   return;
00085 }

void at24cxx_write_continuous ( uint16_t  start_address,
uint16_t  length,
uint8_t const *  wr_buffer 
)

Write bytes continously to the serial EEPROM.

Parameters:
[in] start_address Address of first byte in transaction.
[in] length Number of bytes to write.
[in] wr_buffer Pointer to array where the bytes to be written are stored.
Return values:
true Bytes written successfully.
false Bytes could not be written.

Definition at line 88 of file at24cxx.c.

References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.

00088                                                                                                  {
00089   uint8_t *pack = {0};
00090   twi_package_t twi_package;
00091 
00092   pack[0] = (start_address&0xFF00)>>8;
00093   pack[1] = start_address&0xFF;
00094   uint16_t idx;
00095   for (idx=0;idx<length;idx++)
00096     pack[2+idx] = wr_buffer[idx]; 
00097 
00098   twi_package.chip = AT24CXX_TWI_ADDRESS;
00099   twi_package.addr_length = 0;
00100   twi_package.buffer = &pack;
00101   twi_package.length = sizeof(pack);
00102 
00103   while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS);
00104 
00105   return;
00106 }


Variable Documentation

uint32_t cpu_hz [static]

Definition at line 61 of file at24cxx.c.

Referenced by at24cxx_init().


Generated on Thu Dec 17 19:57:41 2009 for AVR32 UC3 - EPPROM -AT24CXX by  doxygen 1.5.5