//! @{ void twis_init (void) { twis_slave_fct_t twis_slave_fct; #if BOARD == UC3L_EK /** * \internal 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. * \endinternal */ gpio_enable_gpio_pin(AVR32_PIN_PB05); gpio_enable_gpio_pin(AVR32_PIN_PA21); #endif const gpio_map_t TWIS_GPIO_MAP = { {TEST_TWIS_TWCK_PIN, TEST_TWIS_TWCK_FUNCTION}, {TEST_TWIS_TWD_PIN, TEST_TWIS_TWD_FUNCTION} }; const twis_options_t TWIS_OPTIONS = { .pba_hz = FPBA_HZ, .speed = TWI_SPEED, .chip = SLAVE_ADDRESS, .smbus = false, }; // Assign I/Os to SPI. gpio_enable_module (TWIS_GPIO_MAP, sizeof (TWIS_GPIO_MAP) / sizeof (TWIS_GPIO_MAP[0])); // Set pointer to user specific application routines twis_slave_fct.rx = &twis_slave_rx; twis_slave_fct.tx = &twis_slave_tx; twis_slave_fct.stop = &twis_slave_stop; // Initialize as master. twis_slave_init (TWIS, &TWIS_OPTIONS, &twis_slave_fct); } //! @} /*! \brief Main function. */ /*! \remarks Main Function */ //! @{ int main (void) { // Configure the system clock init_sys_clocks (); // Init debug serial line init_dbg_rs232 (FPBA_HZ); // Display a header to user print_dbg ("Slave Example\r\n"); print_dbg ("Slave Started\r\n"); // Initialize and enable interrupt irq_initialize_vectors(); cpu_irq_enable(); // Initialize the TWIS Module twis_init (); while (true); }
void TwoWireUB::begin(void) { if (irqpin >= 0) ACTIVELOW_INIT(irqpin); reg_iir = IS7x0_IIR_INTSTAT; twis_init(); }
/** * \brief Application entry point for TWI Slave example. * * \return Unused (ANSI-C compatibility). */ int main(void) { twis_callback_t slave_callbacks; /* Initialize the SAM system */ sysclk_init(); /* Initialize the board */ board_init(); /* Initialize the console UART */ configure_console(); /* Output example information */ puts(STRING_HEADER); /* Configure TWI as slave */ struct twis_config config; twis_get_config_defaults(&config); config.chip = SLAVE_ADDRESS; if (twis_init(&twis_device, BOARD_BASE_TWI_SLAVE, &config) == STATUS_OK) { /* Set pointer to user specific application routines */ slave_callbacks.rx = &twis_slave_rx; slave_callbacks.tx = &twis_slave_tx; slave_callbacks.stop = &twis_slave_stop; slave_callbacks.error = &twis_slave_error; twis_set_callback(&twis_device, TWIS_INTERRUPT_SLAVEADR_MATCH, slave_callbacks, 1); /* Enable the TWIS module */ twis_enable(&twis_device); } else { puts("-E- Initialization failed!\r\n"); } while (1) { } }