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)

Variables

System Clock Frequencies
static pcl_freq_param_t pcl_freq_param


Define Documentation

#define FCPU_HZ   60000000

Definition at line 97 of file at24cxx_example.c.

Referenced by main().

#define FPBA_HZ   60000000

Definition at line 98 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 115 of file at24cxx_example.c.

References pcl_freq_param.

Referenced by main().

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

int main ( void   ) 

Definition at line 147 of file at24cxx_example.c.

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

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

static void twi_init ( void   )  [static]

Definition at line 121 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().

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


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 103 of file at24cxx_example.c.

Referenced by init_sys_clocks().


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