at24cxx_example.c File Reference


Detailed Description

Example for AT24CXX touch device.

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

Definition in file at24cxx_example.c.

#include <avr32/io.h>
#include "compiler.h"
#include "print_funcs.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "twim.h"
#include "flashc.h"
#include "gpio.h"
#include "cycle_counter.h"
#include "intc.h"
#include "at24cxx.h"
#include "conf_at24cxx.h"
#include <stdio.h>

Go to the source code of this file.

Defines

#define FCPU_HZ   60000000
#define FPBA_HZ   60000000

Functions

static void init_sys_clocks (void)
 Initializes the MCU system clocks.
int main (void)
static void twi_init (void)
 TWI interface initialization.

Variables

System Clock Frequencies
static pcl_freq_param_t pcl_freq_param


Define Documentation

#define FCPU_HZ   60000000

Definition at line 96 of file at24cxx_example.c.

Referenced by main().

#define FPBA_HZ   60000000

Definition at line 97 of file at24cxx_example.c.

Referenced by main(), and twi_init().


Function Documentation

static void init_sys_clocks ( void   )  [static]

Initializes the MCU system clocks.

Definition at line 113 of file at24cxx_example.c.

References pcl_freq_param.

Referenced by main().

00114 {
00115   if (pcl_configure_clocks(&pcl_freq_param) != PASS)
00116     while(1);
00117 }

int main ( void   ) 

Definition at line 144 of file at24cxx_example.c.

References at24cxx_init(), at24cxx_read_byte(), at24cxx_write_byte(), FCPU_HZ, FPBA_HZ, init_sys_clocks(), and twi_init().

00144                {
00145   init_sys_clocks();
00146   init_dbg_rs232(FPBA_HZ);
00147   print_dbg("AT24CXX Example\n");
00148 
00149   INTC_init_interrupts();
00150 
00151   // Activate LED0 & LED1 & LED2 & LED3 pins in GPIO output mode and switch them off.
00152   gpio_set_gpio_pin(LED0_GPIO);
00153   gpio_set_gpio_pin(LED1_GPIO);
00154   gpio_set_gpio_pin(LED2_GPIO);
00155   gpio_set_gpio_pin(LED3_GPIO);
00156   twi_init();
00157   
00158   /* Power up delay: This device needs a maximum of 230ms before it
00159    * can be accessed. Another method would be to wait until the the 
00160    * detect line goes low but this won't work during a debugging session
00161    * since the device is not reset.*/
00162   cpu_delay_ms(230, FCPU_HZ);
00163 
00164   at24cxx_init(FCPU_HZ);
00165   print_dbg("Write @0: 0x55 - @1: 0xAA");
00166   at24cxx_write_byte(0,0x55);
00167   at24cxx_write_byte(1,0xaa);
00168   print_dbg("- Done\n");
00169   
00170   U8 tmp1,tmp2;
00171   tmp1 = at24cxx_read_byte(0);
00172   tmp2 = at24cxx_read_byte(1);
00173   print_dbg("Read @0: 0x");
00174   print_dbg_hex(tmp1);
00175   print_dbg("- @1: 0x");
00176   print_dbg_hex(tmp2);
00177   while(TRUE);
00178 }

static void twi_init ( void   )  [static]

TWI interface initialization.

Definition at line 120 of file at24cxx_example.c.

References AT24CXX_TWI, AT24CXX_TWI_ADDRESS, AT24CXX_TWI_MASTER_SPEED, AT24CXX_TWI_SCL_FUNCTION, AT24CXX_TWI_SCL_PIN, AT24CXX_TWI_SDA_FUNCTION, AT24CXX_TWI_SDA_PIN, and FPBA_HZ.

Referenced by main().

00121 {
00122   const gpio_map_t AT24CXX_TWI_GPIO_MAP =
00123   {
00124   {AT24CXX_TWI_SCL_PIN, AT24CXX_TWI_SCL_FUNCTION},
00125   {AT24CXX_TWI_SDA_PIN, AT24CXX_TWI_SDA_FUNCTION}
00126   };
00127 
00128   const twi_options_t AT24CXX_TWI_OPTIONS =
00129   {
00130     .pba_hz = FPBA_HZ,
00131     .speed  = AT24CXX_TWI_MASTER_SPEED,
00132     .chip   = AT24CXX_TWI_ADDRESS,
00133     .smbus  = FALSE,    
00134   };
00135 
00136   // Assign I/Os to SPI.
00137   gpio_enable_module(AT24CXX_TWI_GPIO_MAP,
00138     sizeof(AT24CXX_TWI_GPIO_MAP) / sizeof(AT24CXX_TWI_GPIO_MAP[0]));
00139   // Initialize as master.
00140   twi_master_init(AT24CXX_TWI, &AT24CXX_TWI_OPTIONS);
00141 }


Variable Documentation

pcl_freq_param_t pcl_freq_param [static]

Initial value:

{
  .cpu_f        = FCPU_HZ,
  .pba_f        = FPBA_HZ,
  .osc0_f       = FOSC0,
  .osc0_startup = OSC0_STARTUP
}

Definition at line 102 of file at24cxx_example.c.

Referenced by init_sys_clocks().


Generated on Fri Feb 19 02:23:48 2010 for AVR32 UC3 - EPPROM -AT24CXX by  doxygen 1.5.5