setMOSI (et. al) on Teensy 3.6?

Status
Not open for further replies.

rhyde

Active member
I'm trying to move the SPI calls to the MOSI2, MISO2, and SCK2 pins on the Teensy 3.6:

#define SPICS 43
#define MOSI 44
#define MISO 45
#define SCK 46

SPISettings WeensySPI( 2000000, MSBFIRST, SPI_MODE0 );

In setup:

pinMode( SPICS, OUTPUT );
digitalWrite( SPICS, 1 );
SPI.begin();
SPI.setMOSI( MOSI );
SPI.setMISO( MISO );
SPI.setSCK( SCK );

In Loop:
SPI.beginTransaction( WeensySPI );
digitalWrite( SPICS, 0 );

// Only writing, incoming data is ignored:

SPI.transfer( bits >> 8 );
SPI.transfer( bits & 0xff );

digitalWrite( SPICS, 1 );
SPI.endTransaction();


It's still accessing the SPI 0 pins.
Am I doing something wrong here?
Thanks,
Randy Hyde
 
to add to Frank's suggestion:
when using Begin/EndTransactions, don't set CS manually but use "setCS(pin)". The transaction functions handles then everything for you.
I could be completely out to lunch, but does that work when using standard functions like SPI2.transfer?

For example as far as I know endTransaction only does something if you are using InterruptMode....

My understanding and usage of setCS is, yes it does switch that pin into a SPI cs pin and it returns a mask for the channel that the CS that pin is on.

You can encode which of the CS channels to use when you push a command onto the FIFO queue.

Example with ILI9341_t3 library, we have code that at init time calls setCS twice, once for the CS and another for the DC.

Code:
	if (SPI.pinIsChipSelect(_cs, _dc)) {
		pcs_data = SPI.setCS(_cs);
		pcs_command = pcs_data | SPI.setCS(_dc);
	} else {
Later when we push a command that will also keep CS asserted, and touches both CS and DC, the code generates the command like:
Code:
		KINETISK_SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT;
Where "c" is the command byte, pcs_command has the encoding for both CS and DC, and the SPI_... are defines in the kinetis.h file.

Again as far as I know there is nothing in begin/endTransaction that uses these? But again I may be missing it.
 
Someone ought to update this page: https://www.pjrc.com/teensy/td_libs_SPI.html to reflect reality.

On a similar topic, what's the trick to accessing different I2C ports? Wire3.begin() doesn't work and the Teensy I2C page doesn't mention anything.
(also, is i2c_t3-master really limited to using the extra I2C ports as slaves?)


**Edit**
Nevermind, I loaded i2c_t3 and despite what I read it seems to work.
 
Last edited:
Status
Not open for further replies.
Back
Top