Jump to content
reaper7

Two SPI modules

Recommended Posts

It is possible to work with two SPI modules at the same time?

 

eg:

SPIClass myFirstSPI;
SPIClass mySecondSPI;

myFirstSPI.setModule(3);
myFirstSPI.begin();
myFirstSPI.setClockDivider(SPI_CLOCK_DIV2);
myFirstSPI.setBitOrder(MSBFIRST);
myFirstSPI.setDataMode(SPI_MODE0);

mySecondSPI.setModule(2);
mySecondSPI.begin();
mySecondSPI.setClockDivider(SPI_CLOCK_DIV2);
mySecondSPI.setBitOrder(MSBFIRST);
mySecondSPI.setDataMode(SPI_MODE3);

when only second SPI (mySecondSPI) is declared all on it works ok

but when I trying set myFirstSPI.setModule(3); then second SPI stops work and first don't working too :(

Share this post


Link to post
Share on other sites

Reaper7,

Yup I'm in the same boat, want to use one SPIi for updatng the SD card, but at the same time use another SPI for the RF transceiver.  I know I can put some code in to check the activity on the selected SPI, but that would be the same as using one SPI anyway. As your post was over 20 days ago, think it might be better to post elsewhere, as this problem not confined to Energia.

Share this post


Link to post
Share on other sites

Generally I use a single SPI bus for multiple devices (SD, ENC(ether), Mirf) and it works fine,

but the problem occurred when I tried to connect the display ILI9320 with different SPI mode (2 or 3)

in this case I need a second SPI bus.

 

I don't know if this is the problem with Energia SPI lib or generally with LM4F120.

 

BTW. At this moment for my display I use arduino lib mod by Rei Vilo with FAST SOFT SPI instead HARD SPI (inspired by jscrane version of UTFT lib )

and this solution is much faster than hardware SPI!

Display filling with different colors 11 times: HARD SPI=9618ms, FAST SOFT SPI=7293ms

Share this post


Link to post
Share on other sites

I need Your help

I modified SPI library to solve the topic problem

Please test and comment

 

1. setModule is removed from this mod because

all SPI bus are defined - see SPI.h (lines 59-62)

You can use in code SPI (default SPI bus 2),SPI0,SPI1,SPI3 or define your own name eg:

#define MYSPIBUS0 SPI0

 

but maybe this function must stay for backward compatibility and must be added new SPI2

 

2. default SELECT pins are defined in SPI.cpp,

use  SPI  or SPI0 or SPI 1 or SPI3 automatically determines which SELECT pin is used,

so if you are using default SELECT pins command SPI.begin(); for SPI bus 2 or SPI0.begin(); for SPI bus 0 is OK

but when other pins are used for SELECT we need command eg SPI.begin(PB_0); in this case SELECT pin on PB_0

 

SPI.zip

 

P.S. I tested this mod with SCREEN HY28 on SPI0 (spi mode3) and SCREENTOUCH + ENC28j60 ETH on SPI2 (spi mode0) and seems ok.

Share this post


Link to post
Share on other sites

Thanks a lot!

 

Now, I can manage the screen SPI(2) mode(3) and the SRAM SPI(0) mode(0).

 

The SPISPI0SPI1SPI3 names are consistent with Serial, Serial1...

 

May I suggest you to push a request to Energia GitHub repository?

Share this post


Link to post
Share on other sites

indeed, inspired by HardwareSerial

You can manage touch to hardwarespi too :)

 

P.S. yes, I push to energia git

but we have to perform some tests

 

Here is the next one

with setModule(module) and setModule(module, ssPin) for "universal" SPI which can be set to (0),(1),(2),(3)

or, of course, still exists SPI0, SPI1, new SPI2, SPI3 as a "hard" defined

 

SPI2.zip

 

we also need to speed up CS inside lib, digitalWrite(ssPin... is not too fast :(

 

this is sample code from spi2 and spi0, 8 data bits and many many time to disable CS:

post-574-14264605286935_thumb.jpg

Share this post


Link to post
Share on other sites

I'm going to use the second hardware fast SPI port for the SRAM.

 

The slow software SPI is going to manage touch.

 

The same logic used for SPI can be applied to I2C ports.

 

I agree with you about the need for a faster digitalWrite(ssPin, LOW); and digitalWrite(ssPin, HIGH); for SPI purposes.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...