0

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.

Trying to get CC3000 and sd shield to work together over SPI

by toegap on Thu Aug 22, 2013 12:34 am

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
toegap
 
Posts: 14
Joined: Sun Aug 18, 2013 3:23 am

Re: Trying to get CC3000 and sd shield to work together over SPI

by technobly on Thu Aug 22, 2013 2:25 am

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.
Best Regards,
Brett W.
Technobly.com | @Technobly | technobly@gmail.com

technobly
 
Posts: 113
Joined: Mon Oct 31, 2011 11:06 am
Location: Chicago, IL

Re: Trying to get CC3000 and sd shield to work together over SPI

by adafruit_support_rick on Thu Aug 22, 2013 9:57 am

toegap wrote:However when I try to open the file the code/arduino stalls.

That sounds a lot like a memory issue. You probably want to have a look at our Arduino Memories tutorial:
http://learn.adafruit.com/memories-of-an-arduino

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Trying to get CC3000 and sd shield to work together over SPI

by toegap on Fri Aug 23, 2013 1:42 pm

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.
toegap
 
Posts: 14
Joined: Sun Aug 18, 2013 3:23 am

Re: Trying to get CC3000 and sd shield to work together over SPI

by adafruit_support_rick on Fri Aug 23, 2013 2:56 pm

toegap wrote:Any other ideas?

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.

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.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Trying to get CC3000 and sd shield to work together over SPI

by toegap on Tue Aug 27, 2013 12:32 am

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
toegap
 
Posts: 14
Joined: Sun Aug 18, 2013 3:23 am

Re: Trying to get CC3000 and sd shield to work together over SPI

by adafruit_support_rick on Tue Aug 27, 2013 8:13 am

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?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Trying to get CC3000 and sd shield to work together over SPI

by brianwong3 on Wed Sep 25, 2013 10:00 am

toegap, I am having the same issues but with the PN532 and the CC3000. Mind explaining the solution?
brianwong3
 
Posts: 4
Joined: Tue Sep 17, 2013 9:19 am

Re: Trying to get CC3000 and sd shield to work together over SPI

by adafruit_support_rick on Wed Sep 25, 2013 10:45 am

You're using the PN532 in SPI mode?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Trying to get CC3000 and sd shield to work together over SPI

by brianwong3 on Wed Sep 25, 2013 10:48 am

Yeap....Rick, any ideas?
brianwong3
 
Posts: 4
Joined: Tue Sep 17, 2013 9:19 am

Re: Trying to get CC3000 and sd shield to work together over SPI

by adafruit_support_rick on Wed Sep 25, 2013 11:53 am

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?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Trying to get CC3000 and sd shield to work together over SPI

by brianwong3 on Thu Sep 26, 2013 3:47 am

tried to debug..got sick of it and decided to move to I2C...

problem now is the CC3000 library is killing the RAM...
brianwong3
 
Posts: 4
Joined: Tue Sep 17, 2013 9:19 am

Re: Trying to get CC3000 and sd shield to work together over SPI

by adafruit_support_rick on Thu Sep 26, 2013 9:33 am

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

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Trying to get CC3000 and sd shield to work together over

by kanderek on Mon Nov 25, 2013 3:47 pm

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.

webClientRFID.txt
(9.84 KiB) Downloaded 36 times
kanderek
 
Posts: 4
Joined: Mon Nov 25, 2013 3:34 pm

Re: Trying to get CC3000 and sd shield to work together over

by adafruit_support_rick on Mon Nov 25, 2013 5:48 pm

Where have you routed the chip selects for each breakout?

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Please be positive and constructive with your questions and comments.