/**
 * \brief De-select the given device on the SPI bus.
 *
 * \param p_usart Base address of the USART instance.
 * \param device  SPI device.
 */
void usart_spi_deselect_device(volatile avr32_usart_t *p_usart, 
	struct usart_spi_device *device)
{
	/* avoid Cppcheck Warning */
	UNUSED(device);

	usart_spi_unselectChip(p_usart);
}
Esempio n. 2
0
/*! \brief This is an example demonstrating the SPI mode of USART IP
 *         functionalities using the USART driver.
 */
int main(void)
{
#if BOARD == STK600_RCUC3D
	// Configure OSC0 in crystal mode, external crystal with a FOSC0 Hz frequency.
	scif_configure_osc_crystalmode(SCIF_OSC0, FOSC0);

	// Enable the OSC0
	scif_enable_osc(SCIF_OSC0, OSC0_STARTUP, true);

	// Set the main clock source as being OSC0.
	pm_set_mclk_source(PM_CLK_SRC_OSC0);
#else
	// Switch main clock to external oscillator 0 (crystal).
	pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
#endif

	static const gpio_map_t USART_GPIO_MAP =
	{
		{EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
		{EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
	};

	static const usart_options_t USART_OPTIONS =
	{
		.baudrate     = 57600,
		.charlength   = 8,
		.paritytype   = USART_NO_PARITY,
		.stopbits     = USART_1_STOPBIT,
		.channelmode  = USART_NORMAL_CHMODE
	};

	// Assign GPIO to USART.
	gpio_enable_module(USART_GPIO_MAP,
		sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

	// Initialize USART in RS232 mode.
	usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, FOSC0);

	static const gpio_map_t USART_SPI_GPIO_MAP =
	{
		{EXAMPLE_USART_SPI_SCK_PIN,  EXAMPLE_USART_SPI_SCK_FUNCTION },
		{EXAMPLE_USART_SPI_MISO_PIN, EXAMPLE_USART_SPI_MISO_FUNCTION},
		{EXAMPLE_USART_SPI_MOSI_PIN, EXAMPLE_USART_SPI_MOSI_FUNCTION},
		{EXAMPLE_USART_SPI_NSS_PIN,  EXAMPLE_USART_SPI_NSS_FUNCTION }
	};

	static const usart_spi_options_t USART_SPI_OPTIONS =
	{
		.baudrate     = 60000,
		.charlength   = 8,
		.spimode      = 0,
		.channelmode  = USART_NORMAL_CHMODE
	};

	// Assign GPIO to SPI.
	gpio_enable_module(USART_SPI_GPIO_MAP,
		sizeof(USART_SPI_GPIO_MAP) / sizeof(USART_SPI_GPIO_MAP[0]));

	// Initialize USART in SPI mode.
	usart_init_spi_master(EXAMPLE_USART_SPI, &USART_SPI_OPTIONS, FOSC0);

	// Show startup message
	usart_write_line(EXAMPLE_USART, "Basic write in USART SPI Mode (press enter)\r\n");

	// Press enter to continue.
	while (usart_get_echo_line(EXAMPLE_USART) == USART_FAILURE);  // Get and echo characters until end of line.

	usart_write_line(EXAMPLE_USART, "Writing SPI test pattern.\r\n");

	while (true)
	{
		usart_spi_selectChip(EXAMPLE_USART_SPI);
		usart_putchar(EXAMPLE_USART_SPI, 0x55);
		usart_putchar(EXAMPLE_USART_SPI, 0xAA);
		usart_spi_unselectChip(EXAMPLE_USART_SPI);
	}
}