diff --git a/cores/arduino/SERCOM.cpp b/cores/arduino/SERCOM.cpp index 2cc41741ba07ada73724aa9a6b4e2b4ad94bc552..41840873164390403fcbb640f40149977137f36b 100644 --- a/cores/arduino/SERCOM.cpp +++ b/cores/arduino/SERCOM.cpp @@ -266,9 +266,9 @@ void SERCOM::writeDataSPI(uint8_t data) sercom->SPI.DATA.bit.DATA = data; } -uint8_t SERCOM::readDataSPI() +uint16_t SERCOM::readDataSPI() { - return sercom->SPI.DATA.bit.DATA; + return sercom->SPI.DATA.reg; } bool SERCOM::isBufferOverflowErrorSPI() diff --git a/cores/arduino/SERCOM.h b/cores/arduino/SERCOM.h index 9ad35ee965bfc0d32cb474dbebbbf96d744b642c..82b953ae103532448fbbdf3e14f30dac3a4fb95a 100644 --- a/cores/arduino/SERCOM.h +++ b/cores/arduino/SERCOM.h @@ -157,7 +157,7 @@ class SERCOM void setBaudrateSPI(uint8_t divider); void setClockModeSPI(SercomSpiClockMode clockMode); void writeDataSPI(uint8_t data); - uint8_t readDataSPI(); + uint16_t readDataSPI(); bool isBufferOverflowErrorSPI(); bool isDataRegisterEmptySPI(); bool isTransmitCompleteSPI(); diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index 0685952fcc812925cf2be02280c13c10661e4e14..8eb5ac2976e3deb1ade58553c7a296b823cc5a85 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -10,18 +10,20 @@ #include "SPI.h" #include "wiring_digital.h" +#include "assert.h" SPIClass::SPIClass(SERCOM *s) { + assert(s != NULL ); sercom = s; - - pinPeripheral(18, g_APinDescription[18].ulPinType); - pinPeripheral(20, g_APinDescription[20].ulPinType); - pinPeripheral(21, g_APinDescription[21].ulPinType); } void SPIClass::begin() { + // PIO init + pinPeripheral(18, g_APinDescription[18].ulPinType); + pinPeripheral(20, g_APinDescription[20].ulPinType); + pinPeripheral(21, g_APinDescription[21].ulPinType); // Default speed set to 4Mhz, SPI mode set to MODE 0 and Bit order set to MSB first. sercom->initSPI(SPI_PAD_2_SCK_3, SERCOM_RX_PAD_0, SPI_CHAR_SIZE_8_BITS, MSB_FIRST); sercom->initSPIClock(SERCOM_SPI_MODE_0, 4000000); diff --git a/variants/arduino_zero/variant.cpp b/variants/arduino_zero/variant.cpp index de7498f8a05981f40933339b6b6589e997487765..34595a7529979528e8dd53c1fcc3dbe3fa18c308 100644 --- a/variants/arduino_zero/variant.cpp +++ b/variants/arduino_zero/variant.cpp @@ -138,7 +138,7 @@ const PinDescription g_APinDescription[]= { PORTA, 23, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCL: SERCOM3/PAD[1] // 18..23 SPI (ICSP:MISO,SCK,MOSI) - { PORTA, 12, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MISO: SERCOM4/PAD[0] + { PORTA, 12, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MISO: SERCOM4/PAD[0] { NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // 5V0 { PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // SCK: SERCOM4/PAD[3] { PORTB, 10, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER }, // MOSI: SERCOM4/PAD[2]