Microchip® Advanced Software Framework

twi_slave_example.c File Reference

TWI SLAVE Example for SAM.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "conf_example.h"

Macros

#define STRING_EOL   "\r"
 
#define STRING_HEADER
 
#define SLAVE_ADDRESS   0x50 /** Target's TWI address */
 Information about TWIS Module. More...
 
#define SLAVE_ADDR_LGT   2 /** Address length of virtual mem */
 
#define VIRTUALMEM_ADDR_START   0 /** Address of virtual mem */
 
#define TWI_MEM_SIZE   50 /** The size of the virtual mem */
 Defines to manage a virtual TWI memory. More...
 
#define TWI_MEM_IDLE   0 /** Idle state */
 
#define TWI_MEM_ADDR   1 /** Address state */
 
#define TWI_MEM_DATA   2 /** Data state */
 

Functions

static void configure_console (void)
 Configure serial console. More...
 
int main (void)
 Application entry point for TWI Slave example. More...
 
static void twis_slave_error (void)
 Manage Error on TWIS. More...
 
static void twis_slave_rx (uint8_t value)
 Manage the received data on TWI. More...
 
static void twis_slave_stop (void)
 Manage stop transfer reception on TWIS. More...
 
static uint8_t twis_slave_tx (void)
 Transmit a data on TWIS. More...
 

Variables

uint32_t addr
 The current address in the virtual mem. More...
 
uint8_t addr_pos
 Offset in the address value. More...
 
uint8_t memory [TWI_MEM_SIZE]
 Content of the Virtual mem. More...
 
uint8_t status_cmd = TWI_MEM_IDLE
 State variable. More...
 
struct twis_dev_inst twis_device
 

#define SLAVE_ADDR_LGT   2 /** Address length of virtual mem */

Referenced by twis_slave_rx().

#define SLAVE_ADDRESS   0x50 /** Target's TWI address */

Information about TWIS Module.

Referenced by main().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"--TWI SLAVE Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Definition: inc/app_init.h:140
#define STRING_EOL
Definition: twi_slave_example.c:100

Referenced by main().

#define TWI_MEM_ADDR   1 /** Address state */

Referenced by twis_slave_rx().

#define TWI_MEM_DATA   2 /** Data state */

Referenced by twis_slave_rx().

#define TWI_MEM_IDLE   0 /** Idle state */
#define TWI_MEM_SIZE   50 /** The size of the virtual mem */

Defines to manage a virtual TWI memory.

Referenced by twis_slave_rx(), and twis_slave_tx().

#define VIRTUALMEM_ADDR_START   0 /** Address of virtual mem */

Referenced by twis_slave_rx(), and twis_slave_tx().

static void configure_console ( void  )
static

Configure serial console.

References uart_rs232_options::baudrate, and stdio_serial_init().

Referenced by main().

static void twis_slave_error ( void  )
static

Manage Error on TWIS.

Remarks
User defined operations on Error condition

Referenced by main().

static void twis_slave_rx ( uint8_t  value)
static

Manage the received data on TWI.

Remarks
User defined operations after reception

References SLAVE_ADDR_LGT, TWI_MEM_ADDR, TWI_MEM_DATA, TWI_MEM_IDLE, TWI_MEM_SIZE, and VIRTUALMEM_ADDR_START.

Referenced by main().

static void twis_slave_stop ( void  )
static

Manage stop transfer reception on TWIS.

Remarks
User defined operations on Stop condition

References TWI_MEM_IDLE.

Referenced by main().

static uint8_t twis_slave_tx ( void  )
static

Transmit a data on TWIS.

Remarks
User defined operations during transmission

References TWI_MEM_IDLE, TWI_MEM_SIZE, and VIRTUALMEM_ADDR_START.

Referenced by main().

uint8_t addr_pos

Offset in the address value.

uint8_t memory[TWI_MEM_SIZE]

Content of the Virtual mem.

uint8_t status_cmd = TWI_MEM_IDLE

State variable.

struct twis_dev_inst twis_device

Referenced by main().