Example #1
0
/*
*	Initialise the SPI interface for the switch
*
*/
void spi_init(void)
{
	/* Config the USART_SPI for KSZ8795 interface */
	usart_spi_init(USART_SPI);
	usart_spi_setup_device(USART_SPI, &USART_SPI_DEVICE, SPI_MODE_3, USART_SPI_BAUDRATE, 0);
	usart_spi_enable(USART_SPI);
}
/*! \brief Main function.
 */
int main(void)
{
	sysclk_init();

	/*
	 * Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();

	/* Config the USART_SPI. */
	usart_spi_init(USART_SPI_EXAMPLE);
	usart_spi_setup_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE,
			SPI_MODE_0, USART_SPI_EXAMPLE_BAUDRATE, 0);
	usart_spi_enable(USART_SPI_EXAMPLE);

	/* Show the test result by LED. */
	if (usart_spi_at45dbx_mem_check() == false) {
#ifndef USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_1,
				IOPORT_PIN_LEVEL_HIGH);
#else
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_1,
				IOPORT_PIN_LEVEL_LOW);
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2,
				IOPORT_PIN_LEVEL_HIGH);
#endif
	} else {
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_1,
				IOPORT_PIN_LEVEL_LOW);
#ifdef USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2
		ioport_set_pin_level(USART_SPI_EXAMPLE_LED_PIN_EXAMPLE_2,
				IOPORT_PIN_LEVEL_LOW);
#endif
	}

	while (1) {
		/* Do nothing */
	}
}
Example #3
0
/*! \brief Main function.
 */
int main(void)
{
	sysclk_init();
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();

	/* Config the USART_SPI in master mode. */
	usart_spi_init(USART_SPI_EXAMPLE);
	usart_spi_setup_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE,
			SPI_MODE_0, USART_SPI_EXAMPLE_BAUDRATE, 0);
	usart_spi_enable(USART_SPI_EXAMPLE);

	/* Config the SPI module in slave mode. */
	spi_slave_init(SPI_SLAVE_EXAMPLE, SPI_MODE_0);
	spi_enable(SPI_SLAVE_EXAMPLE);

	/* Enable global interrupt */
	cpu_irq_enable();

	/* Show the test result by LED. */
	if (spi_usart_master_transfer() == true && spi_slave_transfer() ==
			true) {
		ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN,
				IOPORT_PIN_LEVEL_LOW);
	} else {
		ioport_set_pin_level(SPI_SLAVE_EXAMPLE_LED_PIN,
				IOPORT_PIN_LEVEL_HIGH);
	}

	while (1) {
		/* Do nothing */
	}
}