reaper7 67 Posted May 1, 2013 Share Posted May 1, 2013 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 Quote Link to post Share on other sites
OzGrant 22 Posted May 20, 2013 Share Posted May 20, 2013 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. Quote Link to post Share on other sites
reaper7 67 Posted May 20, 2013 Author Share Posted May 20, 2013 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 Quote Link to post Share on other sites
reaper7 67 Posted June 12, 2013 Author Share Posted June 12, 2013 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. Rei Vilo 1 Quote Link to post Share on other sites
Rei Vilo 695 Posted June 13, 2013 Share Posted June 13, 2013 Thanks a lot! Now, I can manage the screen SPI(2) mode(3) and the SRAM SPI(0) mode(0). The SPI, SPI0, SPI1, SPI3 names are consistent with Serial, Serial1... May I suggest you to push a request to Energia GitHub repository? Quote Link to post Share on other sites
reaper7 67 Posted June 13, 2013 Author Share Posted June 13, 2013 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: sq7bti and Rei Vilo 2 Quote Link to post Share on other sites
Rei Vilo 695 Posted June 13, 2013 Share Posted June 13, 2013 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. Quote Link to post Share on other sites
Rei Vilo 695 Posted July 7, 2013 Share Posted July 7, 2013 SOLVED Please have a look at the thread LaunchPad Stellaris on Energia — MISO Erratic Behaviour on SPI0 and SPI3 Thanks Quote Link to post Share on other sites
Rei Vilo 695 Posted July 8, 2013 Share Posted July 8, 2013 The second release works fine for all the 4 SPI ports. I added a fast digitalWrite library. See [sOLVED] LaunchPad Stellaris on Energia - MISO Erratic Behaviour on SPI0 and SPI3 Many thanks, @@reaper7 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.