Microchip® Advanced Software Framework

twim_example.c File Reference

TWIM Master Example for SAM.

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

#include <asf.h>
#include "conf_example.h"
#include "sleepmgr.h"

Macros

#define PATTERN_TEST_LENGTH   (sizeof(write_data)/sizeof(uint8_t))
 

Functions

static void configure_console (void)
 Configure serial console. More...
 
static status_code_t init_test (void)
 Initialize the TWIM module. More...
 
static status_code_t read_test (void)
 Read the data pattern from the target. More...
 
static status_code_t write_test (void)
 Write the data pattern to the target. More...
 
int main (void)
 

Variables

uint32_t cpu_speed = 0
 
twi_package_t packet_rx
 
twi_package_t packet_tx
 TWI data package. More...
 
uint8_t read_data [PATTERN_TEST_LENGTH]
 Array to store the received test data. More...
 
const uint8_t write_data []
 Array to store the test data for sending. More...
 

#define PATTERN_TEST_LENGTH   (sizeof(write_data)/sizeof(uint8_t))

Referenced by main(), read_test(), and write_test().

static void configure_console ( void  )
static
static status_code_t init_test ( void  )
static

Initialize the TWIM module.

Returns
STATUS_OK if the initialization succeeds, error code otherwise.

References cpu_speed, EXAMPLE_TWIM, sysclk_get_peripheral_bus_hz(), twim_config::twim_clk, twim_default_callback(), TWIM_MASTER_SPEED, twim_set_callback(), and twim_set_config().

Referenced by main().

static status_code_t read_test ( void  )
static

Read the data pattern from the target.

Returns
STATUS_OK If all bytes were read, error code otherwise

References EXAMPLE_TWIM, packet_rx, PATTERN_TEST_LENGTH, read_data, TARGET_ADDR_LGT, TARGET_ADDRESS, twi_master_read(), and VIRTUALMEM_ADDR.

Referenced by main().

static status_code_t write_test ( void  )
static

Write the data pattern to the target.

Returns
STATUS_OK if all bytes were written, error code otherwise.

References EXAMPLE_TWIM, packet_tx, PATTERN_TEST_LENGTH, TARGET_ADDR_LGT, TARGET_ADDRESS, twi_master_write(), VIRTUALMEM_ADDR, and write_data.

Referenced by main().

uint32_t cpu_speed = 0

Referenced by init_test().

twi_package_t packet_rx

Referenced by read_test().

twi_package_t packet_tx

TWI data package.

Referenced by write_test().

uint8_t read_data[PATTERN_TEST_LENGTH]

Array to store the received test data.

Referenced by main(), and read_test().

const uint8_t write_data[]
Initial value:
= {
'S', 'A', 'M', '4', 'L', ' ', 'T', 'W', 'I', 'M', ' ', 'M',
'a', 's', 't', 'e', 'r', ' ', 'E', 'x', 'a', 'm', 'p', 'l', 'e'
}

Array to store the test data for sending.

Referenced by main(), and write_test().