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

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_0_PIN
 
#define TEST_TWIS_TWD_FUNCTION   AVR32_TWIMS0_TWD_0_0_FUNCTION
 
static pcl_freq_param_t pcl_freq_param
 

#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_0_FUNCTION
#define TEST_TWIS_TWD_PIN   AVR32_TWIMS0_TWD_0_0_PIN

PIN 2 & 3 in Header J24 can be used in EVK1104 PIN 1 & 2 in Header J44 can be used in UC3C_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
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

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
}
#define FCPU_HZ
Definition: twis_example.c:89
#define FOSC0
Osc0 frequency: Hz.
Definition: uc3c_ek.h:70
#define FPBA_HZ
Definition: twis_example.c:90
#define OSC0_STARTUP
Osc0 startup time: RCOsc periods.
Definition: uc3c_ek.h:71
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)