Hello,
I am trying to get the sd shield, cc3000 breakout board, and the Arduino to work together over SPI. I am using the sdfat library, select pin has been routed to pin 4, and the speed set to SPI_FULL_SPEED. I can init the card prior to going into the cc3000 wifi startup code. However when I try to open the file the code/arduino stalls. I tried placing SpiPauseSpi(); and SpiResumeSpi(); around the file open, read, close block, but it seems rather slow. Are there any pointers you can give me? Is there something else I should be doing?
Thanks
Trying to get CC3000 and sd shield to work together over SPI
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 14
- Joined: Sun Aug 18, 2013 3:23 am
- technobly
- Posts: 118
- Joined: Mon Oct 31, 2011 11:06 am
Re: Trying to get CC3000 and sd shield to work together over SPI
Toegap, please post your code and I'll try to work this out with you. I need to do similar things, but my first issue is read speed. Without read speed, there is no need to have 2GB of SD card Even so I need to start poking sticks at all the problems.
Last edited by technobly on Thu Aug 22, 2013 11:05 am, edited 1 time in total.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Trying to get CC3000 and sd shield to work together over SPI
That sounds a lot like a memory issue. You probably want to have a look at our Arduino Memories tutorial:toegap wrote:However when I try to open the file the code/arduino stalls.
http://learn.adafruit.com/memories-of-an-arduino
-
- Posts: 14
- Joined: Sun Aug 18, 2013 3:23 am
Re: Trying to get CC3000 and sd shield to work together over SPI
In this case it is not a memory issue, because I am using an Arduino Mega 1280. I have changed the select pin to 53 your code. Any other ideas? Perhaps you could update the library to have an example of this(using another device via SPI at the same the cc3000 is in use)? I think many people would benefit from it.
Fightcube, I will post the code when I get a chance, but don't have much to it. I am just trying to open a file, read into a buffer, write the buffer to a socket.
Fightcube, I will post the code when I get a chance, but don't have much to it. I am just trying to open a file, read into a buffer, write the buffer to a socket.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Trying to get CC3000 and sd shield to work together over SPI
Yuck. This is a problem with SD. We have the same issue with the 2.8" TFT. SD sets up the SPI control register once when you call begin(), and expects it to be correct forever after. Well-behaved SPI drivers should save SPCR, reconfigure it for their own purposes, and then restore SPCR on the way out.toegap wrote:Any other ideas?
ccspi in the CC3000 library does this, but perhaps there's a hole in the logic. I'm thinking it may be in the initialization.
In what order are you doing things? Are you calling SD.begin before cc3000.begin()? If so, try doing it the other way - call cc3000.begin() first.
-
- Posts: 14
- Joined: Sun Aug 18, 2013 3:23 am
Re: Trying to get CC3000 and sd shield to work together over SPI
Rick,
You are right about the SPCR. That needs be different for each of the libraries. If both libraries are set to SPI_CLOCK_DIV2, the only difference is that cc3000 uses SPI.setDataMode(SPI_MODE1) while sdfat(sd card) uses SPI.setDataMode(SPI_MODE0). Both of these effect the state of the SPCR variable. So you need to toggle the SPCR back and forth when you are using these libraries. I know you said the cc3000 library behaves nicely in that it saves the state before and after spi operations, but I saw at least one hole in that, on the init function.
So, I got the libraries working together, however it is still slow, mostly due to packet write limitation of (240 bytes - header) and also due to complexity of the interrupt routines(not to mention management of the additional buffer). If it would be possible to update this library to poll, I think it would help speed things up.
Thanks
You are right about the SPCR. That needs be different for each of the libraries. If both libraries are set to SPI_CLOCK_DIV2, the only difference is that cc3000 uses SPI.setDataMode(SPI_MODE1) while sdfat(sd card) uses SPI.setDataMode(SPI_MODE0). Both of these effect the state of the SPCR variable. So you need to toggle the SPCR back and forth when you are using these libraries. I know you said the cc3000 library behaves nicely in that it saves the state before and after spi operations, but I saw at least one hole in that, on the init function.
So, I got the libraries working together, however it is still slow, mostly due to packet write limitation of (240 bytes - header) and also due to complexity of the interrupt routines(not to mention management of the additional buffer). If it would be possible to update this library to poll, I think it would help speed things up.
Thanks
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Trying to get CC3000 and sd shield to work together over SPI
What exactly did you have to do to make the libraries play together nicely?
I'm not sure I understand how polling would speed it up. Can you elaborate?
I'm not sure I understand how polling would speed it up. Can you elaborate?
-
- Posts: 4
- Joined: Tue Sep 17, 2013 9:19 am
Re: Trying to get CC3000 and sd shield to work together over SPI
toegap, I am having the same issues but with the PN532 and the CC3000. Mind explaining the solution?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Trying to get CC3000 and sd shield to work together over SPI
You're using the PN532 in SPI mode?
-
- Posts: 4
- Joined: Tue Sep 17, 2013 9:19 am
Re: Trying to get CC3000 and sd shield to work together over SPI
Yeap....Rick, any ideas?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Trying to get CC3000 and sd shield to work together over SPI
Well, the shield is really designed to use I2C - if you can switch to that, you shouldn't have any trouble at all.
Otherwise, what pins have you configured for MOSI, MISO, SCK, and CS?
Otherwise, what pins have you configured for MOSI, MISO, SCK, and CS?
-
- Posts: 4
- Joined: Tue Sep 17, 2013 9:19 am
Re: Trying to get CC3000 and sd shield to work together over SPI
tried to debug..got sick of it and decided to move to I2C...
problem now is the CC3000 library is killing the RAM...
problem now is the CC3000 library is killing the RAM...
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Trying to get CC3000 and sd shield to work together over SPI
The CC3000 library is not hugely memory hungry. Perhaps you can save some space in your sketch. Have a look at our Memories tutorial for some tips:
http://learn.adafruit.com/memories-of-an-arduino
http://learn.adafruit.com/memories-of-an-arduino
-
- Posts: 4
- Joined: Mon Nov 25, 2013 3:34 pm
Re: Trying to get CC3000 and sd shield to work together over
I have a very similar challenge as toegap. (I'm actually a bit disappointed that he didn't share his breakthrough.) Anyways, I'm trying to toggle select between the CC3000 breakout board and the adafruit SD breakout board. I have validated that both work alone but I'm not clear how to get switch data control via the chip select based on the libraries as they are. I've attached my code which is based on the webclient example. All help is appreciated.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Trying to get CC3000 and sd shield to work together over
Where have you routed the chip selects for each breakout?
Please be positive and constructive with your questions and comments.