discussion on supporting the TI CC3000 WiFi module

I'm still working on it but so far no real news to report. I have the CC3000 evaluation module but so far I've been unable to get an Arduino to get the CC3000 to do WiFi-ish things.

I thought I'd have better luck getting TI's MSP430 board (it's only about $35 from DigiKey - http://processors.wiki.ti.com/index.php/CC3000_Wi-Fi_Platforms) and reverse engineering a working copy, but I've been unable to install their IDE on my Windows 8 laptop (yet another reason to not get a Windows 8 laptop...but I digress...)...hopefully some night this week or this weekend I'll be able to try again with a Windows 7 or XP box.

Howdy,

I may have made some progress.

Initially I was never able to get the CC3000 to respond to any SPI commands from either a Nano or a Teensy, so I bought TI's MP430 board (their version of Arduino) to make sure it even works. I finally got their IDE installed and got some of their sample apps compiled and uploaded yesterday. I was able to configure it with the iPhone app, ping it, etc.

So now I'm back to making the CC3000 work with Arduino and port TI's CC3000HostDriverLibrary. The biggest obstacle is their code spi.c and spi.h, which does all the SPI work but is all TI-specific. It's semi-documented here:

http://processors.wiki.ti.com/index.php/CC3000_Host_Driver_Porting_Guide

but I didn't find that guide to be very complete or useful, so I copied their version, renamed the files to ArduinoCC3000SPI so they can work with Arduino's standard SPI.h, then commented out all the TI hardware-specific code until it compiled. It doesn't do anything yet but I believe just compiling is a good sign.

I'm currently slogging through their code and trying to figure how to rewrite the TI code for Arduino. Here's an example:

//*****************************************************************************
//
//! This function enter point for write flow
//!
//!  \param  SpiPauseSpi
//!
//!  \return none
//!
//!  \brief  The function triggers a user provided callback for 
//
//*****************************************************************************

void 
SpiPauseSpi(void)
{
//	todo: code this
// SPI_IRQ_PORT &= ~SPI_IRQ_PIN;
}

I'm not sure how you pause SPI on Arduino, if it's necessary, if removing it will break something else, etc., but I'm working on it.

If I ever get anything useful working I will post this on github or some place, but for now it's just commented out code and a bunch of Serial.println()s.

Chris

Welcome to the world of porting code.


Rob

I'd love to see this ported.

Some similar qustions being discussed here: AWR2243: new mmwave dfp supported devices - Sensors forum - Sensors - TI E2E support forums

void SpiPauseSpi(void)
{
SPI_IRQ_PORT &= ~SPI_IRQ_PIN;
}
void SpiResumeSpi(void)
{
SPI_IRQ_PORT |= SPI_IRQ_PIN;
}
As far I understand these functions enable or disabled the IRQ_SPI Line in your Microcontroller, and in case of CC3000 produce a falling edge in the IRQ Pin it would not be treated

I do the same using a Flag
void SpiPauseSpi(void)
{
irq_flag=0;
}
void SpiResumeSpi(void)
{
irq_flag=1;
}

Well I have bad news, good news, and bad news.

I finished porting the library's SPI routines but the init routine locks, I traced that down to it waiting and never receiving an init reply from the CC3000.

I put the library to the side and went back to trying to communicate with it directly by bit-banging the handshake pins and manually sending the init string via SPI, and it's failing the same way the library fails. I wanted to rule out the Teensy so I swapped it for a Nano + some voltage dividers (Arduino pin -> 5.6K R -> CC3000 pin + 10K R -> GND).

I'm now able to do the initial handshaking, send the SPI init string, and get the SPI init response. (I'm not sure why the Teensy wasn't working but I'll come back to that later)

The problem now is the data I'm getting back is 1 bit off. Both the received bytes in the init string, and the bytes in the init response, have a leading 1 bit:

First string:
02 00 FF 00 00 00 00 00 00 00 (expected)
81 00 7F 80 00 00 00 00 00 00 (observed)

Second string:
02 00 00 00 05 04 00 40 01 00 (expected)
81 00 00 00 02 82 00 20 00 80 (observed)

TI's documentation (http://processors.wiki.ti.com/index.php/CC3000_Host_Programming_Guide) says:

The SPI protocol is used to communicate with the CC3000 device from the host MCU that is acting as the SPI master while the CC3000 device is the SPI slave. The protocol is an extension of the existing standard SPI. The endianness on transport is assumed to be most-significant bit (MSB) first.
The clock and phase settings for the SPI are configured such that the data is sampled on the falling edge of the clock cycle. Note that different MCU may use different naming conventions in order to configure SPI clock phase and polarity, For example, MSP430 uses UCCKPL and UCCKPH for clock polarity and phase respectively. Both are set to 0, indicating that the data is sampled on the falling edge of the clock cycle. The more generic convention is CPOL and CPHA, however, in order to configure sampling on the falling edge of the clock cycle, CPHA is set to 1.

I take this as CPOL=0 CPHA=1, which for Arduino is SPI.setDataMode(1), but that isn't working. I've tried modes 0, 2, and 3 as well, and get the exact same results. I've also tried changing the SPI clock with DIV2, DIV4, DIV8 with no changes.

Short of bit-banging the SPI protocol to the CC3000, does anyone have any ideas on how to fix this?

I'm attaching my useless code, maybe I'm overlooking something obvious here?

cc3000.ino (3.62 KB)

I would find it difficult to believe that the TI module is incompatible with AVR's SPI...

It looks like SPI.setDataMode() is:

void SPIClass::setDataMode(uint8_t mode)
{
  SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
}

Which means that you should be calling it with: SPI.setDataMode(1<<CPHA); instead of SPI.setDataMode(1)

There are a lot of complaints on the TI forums about the state of the CC3000 documentation (or lack thereof.) :frowning:

I apologize for that error. I caught that a while ago. I've tried using the built in constants, e.g. SPI_MODE1, but get the same results no matter what option I pick.

There are a lot of complaints on the TI forums about the state of the CC3000 documentation (or lack thereof.) :frowning:

Yes...it hasn't been as much fun as I'd hoped...

I caught that a while ago

Can we see the actual code that you have now?

	SPI.begin();
	SPI.setDataMode(3);
	SPI.setBitOrder(MSBFIRST);
	SPI.setClockDivider(SPI_CLOCK_DIV8);

I'd feel better if the SPI.begin() was last instead of first.

I'm pleased to report that works! No idea why, but it's definitely working now with the Nano. I'm getting exactly what I expect:

First packet data: 2 0 FF 0 0 0 0 0 0 0 (HCI_CMND_SIMPLE_LINK_START ack)
Wlan sent me: 2 0 0 0 5 4 0 40 1 0 (HCI_CMND_SIMPLE_LINK_START command complete)

I'm still unable to get it working with the Teensy -- even with dc42's suggestion of resistors on the IO lines all I get back is FFs. I'll work on that later.

In the meantime, back to porting the library to Arduino.

Thanks for your help.

Keep us posted on your progress! I too am working on getting a CC3000 working with an arduino...

I've got good news to report. I'm now able to get the TI library to compile for Arduino and execute basic commands (show version, start config, connect to a WiFi network, get a DHCP address, etc.). I'm still experimenting with the API but it looks like everything is there and functional.

I found the problem between the Teensy and the CC3000 -- the TI module is very unforgiving about what it expects in SPI timing and/or the Teensy 3.0 SPI implementation has a bug about how it handles SPI mode 1 (CPOL=0 CPHA=1) so I'm bit banging everything for now. The nice thing about the Teensy is it has (relatively) lots of Flash and RAM so I didn't have to worry about buffer sizes etc.

The code currently compiles for the ATMega328 but crashes/reboots when I call the init routine on my Nano...my guess is it's running out of RAM. There's a 'small memory' compiler option ("#define CC3000_TINY_DRIVER" - http://processors.wiki.ti.com/index.php/Tiny_Driver_Support) which is supposed to limit the library to about 200 bytes of memory but that doesn't work for me...I probably broke something while porting the code but I'll get back to that soon.

Once I know everything's working I'm going to remove all my debugging etc. then do a diff between the TI reference library and my code, document the changes, and post things on github or Google code.

In the meantime I hope someone's working on a hardware implementation...currently I'm using the CC3000EM (http://www.ti.com/lit/ug/swru326/swru326.pdf) but it's got a weird pinout, is expensive, and seems to be perpetually on backorder everywhere.

Glad to see that someone is also working on this! I also have a CC3000 evaluation board, and would like to communicate it with my arduino micro at 3.3 to make some tests. I started to port the example library for the TI chip, but it is in a very preliminary stage. What is your compiled sketch size in the Arduino environment? Are you compiling with CC3000_TINY_DRIVER definition enabled?.

How many pins are you using to communicate with the chip? I need 6, one to drive wifi enabled/disabled, one to detect chip IRQs, and the typical 4 for SS, CS, MISO and MOSI.

Hope to see some library or reference software to test with the Arduino =D

Keep us updated!

Just writing our posts at the same time! :slight_smile:

I have the Type-VK module from Murata, seems to be very similar to yours from TI:

http://www.murata-ws.com/type-vk.htm

I think that is ease to do a breakout module for this chip with an easy interface. I though that I read that is necessary a four layer PCB with a whole GND layer. There are some layouts already from the internet that can be a good starting point:

Something I have seen with my first IRQ tests, is that when powering the CC3000 from the Arduino 3v3 ( board is at 3v3 ), all stop working and cannot receive any IRQ or communicate with serial port with PC, when driving WIFI_ENABLED on. However, powering the CC3000 module from an external power supply, all work as expected, and IRQs are received normally. Not sure if it is the same problem with your Arduino. But is a little issue i found when using the Arduino. Powering from other 3v3 boards does not seem to be a problem.

What is your compiled sketch size in the Arduino environment?

37K Flash, 4.3K RAM (on a Teensy 3.0).

Are you compiling with CC3000_TINY_DRIVER definition enabled?.

When I set the target to Uno and set CC3000_TINY_DRIVER it uses 11.4K Flash and ~ 250 bytes RAM (but doesn't actually work yet).

How many pins are you using to communicate with the chip?

Yep, 6 pins:

The normal SPI pins: MOSI, MISO, SCK, CS
The notification pin (TI calls this WLAN_SPI_IRQ)
The 'enable module' pin (TI calls this VBAT_SW_EN in some places and WLAN_EN in others).

Hope to see some library or reference software to test with the Arduino

Licensing for my implementation will start at $25 per CPU. Just kidding. I'll post it as soon as I'm not embarrassed by it.

alvarolb:
Something I have seen with my first IRQ tests, is that when powering the CC3000 from the Arduino 3v3 ( board is at 3v3 ), all stop working and cannot receive any IRQ or communicate with serial port with PC, when driving WIFI_ENABLED on. However, powering the CC3000 module from an external power supply, all work as expected, and IRQs are received normally. Not sure if it is the same problem with your Arduino. But is a little issue i found when using the Arduino. Powering from other 3v3 boards does not seem to be a problem.

I did have this problem at the very beginning...the CC3000 wants up to 250mA @ 3.3V and neither my Teensy or Nano can drive that much current. Right now I'm taking the 5V from USB and running it through a LD1117V33 for the CC3000, and connecting the grounds together.

I hope someone's working on a hardware implementation.

There are RF compliance issues, if you don't exactly follow the TI reference design rules and antenna selection. And the design rules are tough to follow (weird board thickness, etc.) There is useful discussion under the hackaday link alvarolb posted...

You get a bit disillusioned when all those lovely $12 modules become $40 boards, and your homemade "simple" replacement isn't legal :frowning:
It'd be more productive to write TPLINK router code to turn it into a slave device, and then you wonder what your arduino is there for at all.

powering the CC3000 from the Arduino 3v3

The CC3000 is a power-hungry beast, well above the 50mA "spec" of the Arduino board, and probably beyond what the separate regulator chip on the Uno can provide...

There are RF compliance issues, if you don't exactly follow the TI reference design rules and antenna selection. And the design rules are tough to follow (weird board thickness, etc.) There is useful discussion under the hackaday link alvarolb posted...

You get a bit disillusioned when all those lovely $12 modules become $40 boards, and your homemade "simple" replacement isn't legal :frowning:
It'd be more productive to write TPLINK router code to turn it into a slave device, and then you wonder what your arduino is there for at all

I agree...that's why I'm hoping someone else does that part...

I actually wouldn't mind a CC3000 daughterboard at $40 if it had more of a normal footprint (not necessarily a real shield, but something more like the hackaday board).

It seems like the WiFi for Arduino right now is either

  • Expensive and weird (the official Arduino WiFi board or the Yún)
  • Cheaper but limited API (the RN-XV)
  • Cheaper but requires "cloud" services (the Electric Imp and the Spark Core)
  • Cheaper but in a form factor not great for small embedded systems (connecting an Arduino to a router per your example)

My hope is the CC3000 will let us get past all of that.

There is a guy that published eagle design files for a CC3000 breakout