Using the nRF8001 with other SPI devices
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- southernatheart
- Posts: 79
- Joined: Tue Mar 22, 2011 10:54 pm
Using the nRF8001 with other SPI devices
Hi, I got this working great! I've got a temp sensor and LCD in with my project, and also a RTC. The RTC was the last part of code I'm implementing. But now, when I initiate the RTC chip (DS3234), which runs on the SPI lines, the BLE has quit working. It doesn't show up anymore on my iPhone Bluefruit app. The DS3234 and nRF9001 have different CS pins on my arduino, so they both are working, separately. I've found that if I initiate the RTC before the BLE, the BLE works, but then the RTc doesn't. Has anyone used the nRF8001 with other SPI devices successfully? I'm trying to re-initiate each one as I access them, but so far I'm having no luck.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Using the nRF8001 with other SPI devices
The nRF8001 does not play well with other SPI devices. Can you run the RTC in soft SPI on a different set of pins?
- southernatheart
- Posts: 79
- Joined: Tue Mar 22, 2011 10:54 pm
Re: Using the nRF8001 with other SPI devices
I got it to work, I just had to re-initiate whichever SPI device I was accessing. Here's part of my code:
Code: Select all
BTLEserial.pollACI(); // Tell the nRF8001 to do whatever it should be working on.
aci_evt_opcode_t status = BTLEserial.getState(); // Ask what is our current status
if (!status == ACI_EVT_CONNECTED) { //if BLE is connected, skip this
if (millis() - prevMillis > 3000) {
DS3234_init(cs, DS3234_INTCN); //init the RTC
delay(300); //wait for RTC to startup; 300 is max from the datasheet, 120 is typical
DS3234_get(cs, &t); //check the time
//delay(2000); //be sure we have a temp reading on startup
BTLEserial.begin(); //begin BLE
- southernatheart
- Posts: 79
- Joined: Tue Mar 22, 2011 10:54 pm
Re: Using the nRF8001 with other SPI devices
PS. it just fires up the RTC and checks the time every few seconds. It uses the BLE.status flag to make sure the BLE isn't being used, and if it is, it doesn't bother with the RTC as that will break the BLE connection
- swca
- Posts: 10
- Joined: Wed Mar 25, 2015 8:22 pm
Re: Using the nRF8001 with other SPI devices
If my application on an Arduino Mega requires two SPI devices using SPI_MODE_0 and SPI_MODE_1, will using two different sets of pins for SPI solve this? The two devices are nRF8001 and SD shield using SdFat library.
Currently have SD shield using soft serial pins at 10-13, and BLE at pins 50-53. When I try to instantiate Adafruit BLE, SdFat will not work. Is it possible to have both running using different SPI modes?
My current loop (pseudocode):
While BLE.available():
if BLE.read() == 'record':
logData() //SDFatLib
if BLE.read() == 'dump':
dumpData() // transfer from SD to phone using BLE.write()
Or is this pretty deep into a rabbit hole?
Can I just use two arduinos, communicating via Serial to avoid this incompatibility issue?
Thanks.
Currently have SD shield using soft serial pins at 10-13, and BLE at pins 50-53. When I try to instantiate Adafruit BLE, SdFat will not work. Is it possible to have both running using different SPI modes?
My current loop (pseudocode):
While BLE.available():
if BLE.read() == 'record':
logData() //SDFatLib
if BLE.read() == 'dump':
dumpData() // transfer from SD to phone using BLE.write()
Or is this pretty deep into a rabbit hole?
Can I just use two arduinos, communicating via Serial to avoid this incompatibility issue?
Thanks.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Using the nRF8001 with other SPI devices
What SD shield is this? Does it connect to the ICSP header at all?
Does SdFat work if you don't enable BLE?
Does SdFat work if you don't enable BLE?
- swca
- Posts: 10
- Joined: Wed Mar 25, 2015 8:22 pm
Re: Using the nRF8001 with other SPI devices
I am using the Seeed Studio SD shield v4. It connects to software SPI for the mega. It still work, I think the configuration automatically detects if this is the case. It does connects to the ICSP pins, what does this do?
SdFat does work if I do not enable BLE. The BLE program works until I call a routine from the SdFat library.
It seems the two libraries are in conflict with each other. fat16lib said the differences are:
[*]SdFat uses MSBFIRST, BLE_UART uses LSBFIRST
[*]interrupt latency of nrF8001 is too long
[*]NRF8001 uses slow SPI clock SPI_CLOCK_DIV8, which is too slow for fast data logging
The Adafruit library also only sets SPI options once at the beginning, whereas SdFat sets the SPI bus before every access. Bluetooth connection will not stay connected if SdFat is accessed.
SdFat does work if I do not enable BLE. The BLE program works until I call a routine from the SdFat library.
It seems the two libraries are in conflict with each other. fat16lib said the differences are:
[*]SdFat uses MSBFIRST, BLE_UART uses LSBFIRST
[*]interrupt latency of nrF8001 is too long
[*]NRF8001 uses slow SPI clock SPI_CLOCK_DIV8, which is too slow for fast data logging
The Adafruit library also only sets SPI options once at the beginning, whereas SdFat sets the SPI bus before every access. Bluetooth connection will not stay connected if SdFat is accessed.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Using the nRF8001 with other SPI devices
I think the problem is that the SD shield will have connections between pins 11, 12, and 13 and the ICSP header. The Mega has connections between pins 50, 51, and 52 and the ICSP header.
So, even though you are running SD on soft SPI, it is interfering with the hardware SPI through all the shared connections with the ICSP header. Are there any jumpers on the SD shield which will disconnect the ICSP socket?
So, even though you are running SD on soft SPI, it is interfering with the hardware SPI through all the shared connections with the ICSP header. Are there any jumpers on the SD shield which will disconnect the ICSP socket?
- swca
- Posts: 10
- Joined: Wed Mar 25, 2015 8:22 pm
Re: Using the nRF8001 with other SPI devices
Oh interesting! If I connect:
[*] the SD shield connections directly to 5V, GND, 4,11,12, and 13 to the mega (bypassing ICSP header) and ran SdFat in software SPI mode
[*]the BLE shield to pins 50, 51, 52, 53
There will be two SPI mode protocols and the interrupts from both libraries will not conflict?
[*] the SD shield connections directly to 5V, GND, 4,11,12, and 13 to the mega (bypassing ICSP header) and ran SdFat in software SPI mode
[*]the BLE shield to pins 50, 51, 52, 53
There will be two SPI mode protocols and the interrupts from both libraries will not conflict?
- swca
- Posts: 10
- Joined: Wed Mar 25, 2015 8:22 pm
Re: Using the nRF8001 with other SPI devices
I could not figure out how to bypass the ICSP headers on the Seeed SD shield. I tried plugging in the connectors as mentioned above (including reset, IOREF) to the mega, but could not get it to work. I see the Adafruit is out of stock. Is it possible for you to test compatibility of two libraries? And when in stock, I will buy.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Using the nRF8001 with other SPI devices
The Adafruit SD library in soft SPI mode and the nRF8001 library in hardware SPI mode are compatible.
Please be positive and constructive with your questions and comments.