Teensy 3.5 and SPI2

Status
Not open for further replies.

LuisHS

Well-known member
.

Hello

Is it possible to use SPI2 with Teensy 3.5?
I can not use SPI0 because it is connected to other hardware, and SPI1 is connected to the SD card (SDHC), so only SPI2 is free to use it (pin 43, 44, 45 and 46).

I do not know if it is possible to use SPI2, and in the same application also use SPI0. I need both, each connected to different hardware devices.

Its possible assign SPI2 with these commands, or these is only for alternative SPI0 pins ?.
SPI.setMOSI(44); // SPI2 MOSI, PTB22
SPI.setMISO(45); // SPI2 MISO, PTB23
SPI.setSCK(46); // SPI2 SCK, PTB21


Best regards
 
Last edited:
Yes, use the SPI2 object. Note SPI1 object may be available if you are using the built in sdcard reader which uses SD subsystem,not SPI

SPI2:setMOSI...
 
.

Thanks KurtE.


I have modify:

SPI.setMOSI(7);
SPI.setMISO(8);
SPI.setSCK(14);

to:

SPI2.setMOSI(44); // SPI2 MOSI, PTB22
SPI2.setMISO(45); // SPI2 MISO, PTB23
SPI2.setSCK(46); // SPI2 SCK, PTB21



And compile without errors.
But this is enough to work with SPI2 instead of with SPI0 ?

In my application I need SPI2 to access to W5500 Ethernet chip, with includes to files SPI.h, Ethernet2.h and EthernetUdp2.h.

I must also to read by SPI/DMA external signals, so I need SPI0 for this, and SPI2 to control W5500.
 
.

I have edit the source w5500.cpp and it seems that the access to the W5500 is fixed to SPI (SPI0) in the source, with no option to configure it externally to works by SPI2.

For example in this function, all is with SPI (I understand its SPI0)

uint8_t W5500Class::write(uint16_t _addr, uint8_t _cb, uint8_t _data)
{
SPI.beginTransaction(wiznet_SPI_settings);
setSS();
SPI.transfer(_addr >> 8);
SPI.transfer(_addr & 0xFF);
SPI.transfer(_cb);
SPI.transfer(_data);
resetSS();
SPI.endTransaction();

return 1;
}



If I change the SPI to SPI2, I may compile without errors. So the question is if I must modify all the SPI to SPI2 in w5500.cpp source file to may control the W5500 Ethernet chip by SPI2 instead of by SPI (SPI0).

uint8_t W5500Class::write(uint16_t _addr, uint8_t _cb, uint8_t _data)
{
SPI2.beginTransaction(wiznet_SPI_settings);
setSS();
SPI2.transfer(_addr >> 8);
SPI2.transfer(_addr & 0xFF);
SPI2.transfer(_cb);
SPI2.transfer(_data);
resetSS();
SPI2.endTransaction();

return 1;
}
 
Last edited:
Yes to use SPI2, you need to use object on all such calls. Sort of a pain.

Hopefully over time we will update libraries to be able to pass in which object to use.
 
.

Ok, thanks KurtE.

I'm going to modify all the SPI. to SPI2. in w5500.cpp and I'll verify it. I hope this works well, so that my application can work with SPI0 and SPI2, each for a different external device.

So I think I do not need to configure the SPI2 pins with SPI2.setMOSI(44), SPI2.setMISO(45) and SPI2.setSCK(46), because of in the SPI library they are already assigned correctly and I think there are no alternative pins for SPI2.

const SPIClass::SPI_Hardware_t SPIClass::spi2_hardware = {
SIM_SCGC3, SIM_SCGC3_SPI2, 1, IRQ_SPI2,
#if defined(__MK66FX1M0__)
32767, DMAMUX_SOURCE_SPI2_TX, DMAMUX_SOURCE_SPI2_RX,
#else
// T3.5 does not have good DMA support on 1 and 2
511, 0, DMAMUX_SOURCE_SPI2,
#endif
_spi_dma_rxISR2,
45, 51, 255, 255,
PORT_PCR_MUX(2), PORT_PCR_MUX(2), 0, 0,
44, 52, 255, 255,
PORT_PCR_MUX(2), PORT_PCR_MUX(2), 0, 0,
46, 53, 255,
PORT_PCR_MUX(2), PORT_PCR_MUX(2), 0,
43, 54, 55, 255, 255, 255, 255, 255, 255, 255, 255,
PORT_PCR_MUX(2), PORT_PCR_MUX(2), PORT_PCR_MUX(2), 0, 0, 0, 0, 0, 0, 0, 0,
0x1, 0x2, 0x1, 0, 0, 0, 0, 0, 0, 0, 0
}
;


I only see the need to configure the Chip Select with these instructions in my program for W5500.

#define W5500_CS 43 // PTB20
Ethernet.init (W5500_CS);
 
Last edited:
Status
Not open for further replies.
Back
Top