This file is the AT24cxx driver.
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 "twi.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 |
void at24cxx_init | ( | int32_t | fcpu | ) |
This function will initialize the AT24CXX serial EEPROM.
true | AT24CXX device ready to use. | |
false | Not able to initialize the AT24CXX device. |
Definition at line 62 of file at24cxx.c.
References cpu_hz.
Referenced by main().
00062 { 00063 /* Store cpu frequency locally*/ 00064 cpu_hz = fcpu; 00065 }
uint8_t at24cxx_read_byte | ( | uint16_t | byte_address | ) |
Read single byte from serial EEPROM.
[in] | byte_address | Address of byte to read. |
[out] | read_byte | Pointer to memory where the read byte will be stored. |
true | Byte read successfully. | |
false | Byte could not be read. |
Definition at line 108 of file at24cxx.c.
References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.
Referenced by main().
00108 { 00109 uint8_t data; 00110 twi_package_t twi_package; 00111 00112 twi_package.chip = AT24CXX_TWI_ADDRESS; 00113 twi_package.addr_length = 0; 00114 twi_package.buffer = &byte_address; 00115 twi_package.length = 2; 00116 while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS); 00117 00118 twi_package.chip = AT24CXX_TWI_ADDRESS; 00119 twi_package.addr_length = 0; 00120 twi_package.buffer = &data; 00121 twi_package.length = 1; 00122 while(twi_master_read(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS); 00123 00124 00125 return data; 00126 00127 }
void at24cxx_read_continuous | ( | uint16_t | start_address, | |
uint16_t | length, | |||
uint8_t * | rd_buffer | |||
) |
Read bytes continously from the serial EEPROM.
[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. |
true | Bytes read successfully. | |
false | Bytes could not be read. |
Definition at line 130 of file at24cxx.c.
References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.
00130 { 00131 twi_package_t twi_package; 00132 00133 twi_package.chip = AT24CXX_TWI_ADDRESS; 00134 twi_package.addr_length = 0; 00135 twi_package.buffer = &start_address; 00136 twi_package.length = 2; 00137 while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS); 00138 00139 twi_package.chip = AT24CXX_TWI_ADDRESS; 00140 twi_package.addr_length = 0; 00141 twi_package.buffer = rd_buffer; 00142 twi_package.length = length; 00143 while(twi_master_read(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS); 00144 00145 }
void at24cxx_write_byte | ( | uint16_t | byte_address, | |
uint8_t | byte_value | |||
) |
Write single byte to the serial EEPROM.
[in] | byte_address | Address of byte to write. |
[in] | byte_value | Value that will be written to the specified address. |
true | Byte written successfully. | |
false | Byte could not be written. |
Definition at line 68 of file at24cxx.c.
References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.
Referenced by main().
00068 { 00069 uint8_t pack[3]; 00070 twi_package_t twi_package; 00071 00072 pack[0] = (byte_address&0xFF00)>>8; 00073 pack[1] = byte_address&0xFF; 00074 pack[2] = byte_value; 00075 00076 twi_package.chip = AT24CXX_TWI_ADDRESS; 00077 twi_package.addr_length = 1; 00078 twi_package.buffer = &pack; 00079 twi_package.length = sizeof(pack); 00080 00081 while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS); 00082 00083 return; 00084 }
void at24cxx_write_continuous | ( | uint16_t | start_address, | |
uint16_t | length, | |||
uint8_t const * | wr_buffer | |||
) |
Write bytes continously to the serial EEPROM.
[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. |
true | Bytes written successfully. | |
false | Bytes could not be written. |
Definition at line 87 of file at24cxx.c.
References AT24CXX_TWI, and AT24CXX_TWI_ADDRESS.
00087 { 00088 uint8_t *pack = {0}; 00089 twi_package_t twi_package; 00090 00091 pack[0] = (start_address&0xFF00)>>8; 00092 pack[1] = start_address&0xFF; 00093 uint16_t idx; 00094 for (idx=0;idx<length;idx++) 00095 pack[2+idx] = wr_buffer[idx]; 00096 00097 twi_package.chip = AT24CXX_TWI_ADDRESS; 00098 twi_package.addr_length = 0; 00099 twi_package.buffer = &pack; 00100 twi_package.length = sizeof(pack); 00101 00102 while(twi_master_write(AT24CXX_TWI, &twi_package)!=TWI_SUCCESS); 00103 00104 return; 00105 }
uint32_t cpu_hz [static] |