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

Configure serial console.

References uart_rs232_options::baudrate, and stdio_serial_init().

Referenced by main().

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, sysclk_get_peripheral_bus_hz(), twim_config::twim_clk, twim_default_callback(), 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 packet_rx, PATTERN_TEST_LENGTH, read_data, and twi_master_read().

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 packet_tx, PATTERN_TEST_LENGTH, twi_master_write(), and write_data.

Referenced by main().

uint32_t cpu_speed = 0

Referenced by init_test().

twi_package_t packet_rx

Referenced by read_test(), and read_test_pdca().

twi_package_t packet_tx

TWI data package.

Referenced by write_test(), and write_test_pdca().

uint8_t read_data[PATTERN_TEST_LENGTH]

Array to store the received test data.

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

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 flash_rw_example(), main(), write_test(), and write_test_pdca().