Using a Teensy 4, I am using SPI and SPI1 (independent from each other) to interact with two separate remote devices. I do the exact same thing with each device: send a command, and receive a response using one wire (SPI:MOSI and SPI1:MOSI1). The remote devices receive their 16-bit command, and reply with a 21 bit response. I can see both the send and receive signals on my scope for both MOSI and MOSI1; both the send and receive signals on both pins are correctly formed. Also, the remote devices are both following the commands based on their behavior.
SPI works great. SPI1 sends, but does not receive.
The general flow is this:
(1) A timer is used to trigger sending commands out the SPI peripherals at the desired frequency;
(1b) The data is written to the transmit FIFO, and
(1c) the Frame Complete interrupt is set to trigger when done.
(2) The SPI interrupt for Frame Complete is triggered, and we setup the SPI to receive (slave mode) using the MOSI to receive.
(2b) We configure it to read in the expected number of bytes as necessary to capture all the data.
(2c) We setup the "Receive Data Interrupt" to trigger when the data has been read in.
(2d) We "prime the pump" by putting some data into the transmit FIFO.
(3) The SPI's "Receive Data Interrupt" triggers, and we read in the data. And make the SPI inactive.
(4) The process repeats when the timer triggers again (back to #1).
As I indicated above, the sends are working, SPI receives, but SPI1 never gets the "Receive Data Interrupt".
In this situation, both SPI and SPI1 are in SLAVE mode, and need to see the CS pin driven low. I set pin 3 to output, drive it low. Pin 3 is connected to both pin 0 (SPI1:CS1) and pin 10 (SPI:CS).
Also, both SPI and SPI1 need a clock signal; I use another pin to supply a clock and connect that to pins 27 (SPI1:SCK1) and 13 (SPI:SCK).
I can see these signals behaving correctly on the scope.
It appears to me as though the SPI1 peripheral is not reading in the CS0 (pin 0). Like the pin muxing isn't setup correctly.
I have tried so many things:
* calling SPI1.setCS(0) in the setup, in the interrupt, both... doesn't improve the situation, sometimes disrupts SPI.
* Using another pin (e.g pin 2), connecting to pin 0, and driving pin 0 LOW
* Setting pin 0 as an output and setting it LOW
* Setting pin 0 as an input and connecting to pin 2.
I put some serial.print statements in the SPI library to see what was being set in setCS():
//SPI: i=0 hardware().cs_pin=10 hardware().sck_mux=13 ... *(portConfigRegister(pin)) = hardware().sck_mux;
//SPI1: i=0 hardware().cs_pin=0 hardware().sck_mux=12 ... *(portConfigRegister(pin)) = hardware().sck_mux;
Unfortunately, the code is long and complex, and the setup is not easily emulated. Hence, I don't think anyone would want to sift through it. Also, I am coming up on a deadline, and don't have time to externalize a clean example of the problem (my apologies).
I guess what I am looking for would be this: What are the hardware commands to configure the pin muxing so that pin 0 is operating as SPI1:CS1 (and bonus points for the best mechanism to toggle it HIGH to LOW)?
SPI works great. SPI1 sends, but does not receive.
The general flow is this:
(1) A timer is used to trigger sending commands out the SPI peripherals at the desired frequency;
(1b) The data is written to the transmit FIFO, and
(1c) the Frame Complete interrupt is set to trigger when done.
(2) The SPI interrupt for Frame Complete is triggered, and we setup the SPI to receive (slave mode) using the MOSI to receive.
(2b) We configure it to read in the expected number of bytes as necessary to capture all the data.
(2c) We setup the "Receive Data Interrupt" to trigger when the data has been read in.
(2d) We "prime the pump" by putting some data into the transmit FIFO.
(3) The SPI's "Receive Data Interrupt" triggers, and we read in the data. And make the SPI inactive.
(4) The process repeats when the timer triggers again (back to #1).
As I indicated above, the sends are working, SPI receives, but SPI1 never gets the "Receive Data Interrupt".
In this situation, both SPI and SPI1 are in SLAVE mode, and need to see the CS pin driven low. I set pin 3 to output, drive it low. Pin 3 is connected to both pin 0 (SPI1:CS1) and pin 10 (SPI:CS).
Also, both SPI and SPI1 need a clock signal; I use another pin to supply a clock and connect that to pins 27 (SPI1:SCK1) and 13 (SPI:SCK).
I can see these signals behaving correctly on the scope.
It appears to me as though the SPI1 peripheral is not reading in the CS0 (pin 0). Like the pin muxing isn't setup correctly.
I have tried so many things:
* calling SPI1.setCS(0) in the setup, in the interrupt, both... doesn't improve the situation, sometimes disrupts SPI.
* Using another pin (e.g pin 2), connecting to pin 0, and driving pin 0 LOW
* Setting pin 0 as an output and setting it LOW
* Setting pin 0 as an input and connecting to pin 2.
I put some serial.print statements in the SPI library to see what was being set in setCS():
//SPI: i=0 hardware().cs_pin=10 hardware().sck_mux=13 ... *(portConfigRegister(pin)) = hardware().sck_mux;
//SPI1: i=0 hardware().cs_pin=0 hardware().sck_mux=12 ... *(portConfigRegister(pin)) = hardware().sck_mux;
Unfortunately, the code is long and complex, and the setup is not easily emulated. Hence, I don't think anyone would want to sift through it. Also, I am coming up on a deadline, and don't have time to externalize a clean example of the problem (my apologies).
I guess what I am looking for would be this: What are the hardware commands to configure the pin muxing so that pin 0 is operating as SPI1:CS1 (and bonus points for the best mechanism to toggle it HIGH to LOW)?