/* * SPI3.cpp - SPI library using UART3 for Ardupilot Mega * Code by Randy Mackay, DIYDrones.com * but mostly based on standard Arduino SPI class by Cristian Maglie * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * */ #include "pins_arduino.h" #include "SPI3.h" SPI3Class SPI3; bool SPI3Class::_initialised = false; void SPI3Class::begin() { // check if begin has been run already if( _initialised ) { return; } // Set direction register for SCK and MOSI pin. pinMode(SPI3_SCK, OUTPUT); pinMode(SPI3_MOSI, OUTPUT); pinMode(SPI3_MISO, INPUT); // Setup Serial Port3 in SPI mode (MSPI), Mode 0, Clock: 8Mhz UBRR3 = 0; DDRJ |= (1<