Example #1
0
void mpu_9520_init(void) {
	/* Configure SPI interrupts for Master only. */
	NVIC_ClearPendingIRQ(SPI0_IRQn);
	NVIC_DisableIRQ(SPI0_IRQn);
	NVIC_SetPriority(SPI0_IRQn, 0);
	NVIC_EnableIRQ(SPI0_IRQn);
	
	ioport_set_pin_peripheral_mode(SPI0_MISO_GPIO, SPI0_MISO_FLAGS);
	ioport_set_pin_peripheral_mode(SPI0_MOSI_GPIO, SPI0_MOSI_FLAGS);
	ioport_set_pin_peripheral_mode(SPI0_SPCK_GPIO, SPI0_SPCK_FLAGS);
	ioport_set_pin_peripheral_mode(SPI0_NPCS1_GPIO, SPI0_NPCS1_FLAGS);
	
	_spi_mpu9520 = spi_new_instance(SPI0, 1, 300000UL, 0, 16, _mpu9250_call_back);
	
	_spi_rx_fifo_desc = spi_get_rx_fifo_desc(_spi_mpu9520);
	
	_mpu9250_call_back(0,0);
}
// ----------------------------------------------------------------------------------------------------------------------
void _init_mpu9520() {
	buffer_init(&_mpu9520_rx_buffer);
	buffer_init(&_mpu9250_tx_buffer);
	_spi_mpu9520 = spi_new_instance(SPI_MODE_MASTER, SPI_CLOCK_DIVIDER_128, 3, SPI_DATA_ORDER_MSB, &PORTB, PB0, 0,	&_mpu9520_rx_buffer, &_mpu9250_tx_buffer, &_mpu9250_call_back);
	_mpu9250_call_back(0,0);
}