Microchip® Advanced Software Framework

twis_example.c File Reference
#include "print_funcs.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "twis.h"
#include "gpio.h"
#include <stdint.h>
#include <stdio.h>

Macros

System Clock Frequencies

Information about Clock configuration and TWIM Module configuration

#define DFLL_FREQ_HZ   96000000
 
TWIM Module Configuration

Information about TWIM Module

#define TWIS   (&AVR32_TWIS0)
 
#define SLAVE_ADDRESS   0x05
 
#define SLAVE_ADDR_LGT   3
 
#define VIRTUALMEM_ADDR_START   0x123456
 
#define TWI_SPEED   50000
 
Virtual Memory Management

Defines to manage a virtual TWI memory

#define TWI_MEM_SIZE   20
 
#define TWI_MEM_IDLE   0
 
#define TWI_MEM_ADDR   1
 
#define TWI_MEM_DATA   2
 

Functions

void twis_slave_rx (uint8_t u8_value)
 Manage the received data on TWI. More...
 
uint8_t twis_slave_tx (void)
 Transmit a data on TWIS. More...
 
void twis_slave_stop ()
 Manage stop transfer reception on TWIS. More...
 
static void init_sys_clocks (void)
 Initializes the MCU system clocks. More...
 
void twis_init (void)
 TWIS interface initialization. More...
 
int main (void)
 Main function. More...
 

Variables

uint8_t s_memory [TWI_MEM_SIZE] = { 0 }
 Content of the Virtual mem. More...
 
uint8_t s_status_cmd = TWI_MEM_IDLE
 State variable. More...
 
uint32_t s_u32_addr
 The current address in the virtual mem. More...
 
uint8_t s_u8_addr_pos
 Offset in the address value (because we receive the address one Byte at a time) More...
 

System Clock Frequencies

Information about Clock configuration and TWIM Module configuration

#define FCPU_HZ   12000000
 
#define FPBA_HZ   12000000
 
#define TEST_TWIS_TWCK_PIN   AVR32_TWIMS0_TWCK_0_0_PIN
 
#define TEST_TWIS_TWCK_FUNCTION   AVR32_TWIMS0_TWCK_0_0_FUNCTION
 
#define TEST_TWIS_TWD_PIN   AVR32_TWIMS0_TWD_0_2_PIN
 
#define TEST_TWIS_TWD_FUNCTION   AVR32_TWIMS0_TWD_0_2_FUNCTION
 
static scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, false}
 
static pcl_freq_param_t pcl_freq_param
 

#define DFLL_FREQ_HZ   96000000
#define FCPU_HZ   12000000
#define FPBA_HZ   12000000
#define SLAVE_ADDR_LGT   3
#define SLAVE_ADDRESS   0x05
#define TEST_TWIS_TWCK_FUNCTION   AVR32_TWIMS0_TWCK_0_0_FUNCTION
#define TEST_TWIS_TWCK_PIN   AVR32_TWIMS0_TWCK_0_0_PIN
#define TEST_TWIS_TWD_FUNCTION   AVR32_TWIMS0_TWD_0_2_FUNCTION
#define TEST_TWIS_TWD_PIN   AVR32_TWIMS0_TWD_0_2_PIN

PIN 1 & 2 in Header J44 can be used in UC3L_EK

#define TWI_MEM_ADDR   1
#define TWI_MEM_DATA   2
#define TWI_MEM_IDLE   0
#define TWI_MEM_SIZE   20
#define TWI_SPEED   50000
#define TWIS   (&AVR32_TWIS0)
#define VIRTUALMEM_ADDR_START   0x123456

static void init_sys_clocks ( void  )
static

Initializes the MCU system clocks.

Remarks
System clock configuration
int main ( void  )

Main function.

Remarks
Main Function
void twis_init ( void  )

TWIS interface initialization.

Remarks
TWIS Module Configuration

For UC3L devices, TWI default pins are, TWIMS0 -> PB05,PA21 TWIMS1 -> PB04 To enable TWI clock/data in another pin, these have to be assigned to other peripherals or as GPIO.

void twis_slave_rx ( uint8_t  u8_value)

Manage the received data on TWI.

Remarks
User defined operations after reception
void twis_slave_stop ( )

Manage stop transfer reception on TWIS.

Remarks
User defined operations on Stop condition
uint8_t twis_slave_tx ( void  )

Transmit a data on TWIS.

Remarks
User defined operations during transmission

scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, false}
static
pcl_freq_param_t pcl_freq_param
static
Initial value:
=
{
.main_clk_src = PCL_MC_DFLL0,
.cpu_f = FCPU_HZ,
.pba_f = FPBA_HZ,
.dfll_f = DFLL_FREQ_HZ,
.pextra_params = &gc_dfllif_ref_opt
}
#define DFLL_FREQ_HZ
Definition: twim_example.c:105
Definition: power_clocks_lib.h:106
#define FCPU_HZ
Definition: twis_example.c:89
static scif_gclk_opt_t gc_dfllif_ref_opt
Definition: twis_example.c:93
#define FPBA_HZ
Definition: twis_example.c:90
uint8_t s_memory[TWI_MEM_SIZE] = { 0 }

Content of the Virtual mem.

uint8_t s_status_cmd = TWI_MEM_IDLE

State variable.

uint32_t s_u32_addr

The current address in the virtual mem.

uint8_t s_u8_addr_pos

Offset in the address value (because we receive the address one Byte at a time)