From b095dc3c746fd6e2f9bbe35094ee4f4b4f78a06b Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Mon, 8 Jan 2024 17:50:54 -0800 Subject: [PATCH] Fix SPI startup on Teensy 4.1 --- software/o_c_REV/OC_DAC.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/software/o_c_REV/OC_DAC.cpp b/software/o_c_REV/OC_DAC.cpp index 1d09e5c32..6f405b21d 100644 --- a/software/o_c_REV/OC_DAC.cpp +++ b/software/o_c_REV/OC_DAC.cpp @@ -85,11 +85,18 @@ void DAC::Init(CalibrationData *calibration_data) { SPIFIFO.begin(DAC_CS, SPICLOCK_30MHz, SPI_MODE0); #elif defined(__IMXRT1062__) + #if defined(ARDUINO_TEENSY40) SPI.begin(); IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_00 = 3; // DAC CS pin controlled by SPI - #if defined(ARDUINO_TEENSY41) - // if (DAC8568_Uses_SPI), assume DAC8568_Vref_enable() already called by - // main program startup, so we don't need to do any more hardware init + #elif defined(ARDUINO_TEENSY41) + if (DAC8568_Uses_SPI) { + // Assume DAC8568_Vref_enable() already called by main program startup, + // so we don't need to do any more hardware init, and calling SPI.begin() + // again could cause problems. + } else { + SPI.begin(); + IOMUXC_SW_MUX_CTL_PAD_GPIO_B0_00 = 3; // DAC CS pin controlled by SPI + } if (ADC33131D_Uses_FlexIO) { // ADC33131D wants pin 12 for data input, but SPI.begin() takes it away // reconfigure pin mux to return pin 12 control to FlexIO