Hi all,
I am working on a project that uses a feather nRF52840 sense and needs BLE communication and TLC59711 based led animation (board connected on SPI). Basically I send command over BLE UART from a smartphone to the feather and some LED animation parameters change in realtime.
It seems that as soon as BLE advertising is on and that I write to the TLC59711 (SPI) it crashes the board with an "nrf_error_cb: 121: id = 1".
I can't find the pattern yet, it appears to be somehow related to timing (I was suspecting that I take too much time in the loop() and that the scheduler was crashing the board). I even remember that it was sometimes working with one SPI write but now it crashes everytime. I tried many things, including changing the order of init, adding delay() and yield() in the loop, but I am a bit clueless. I also read a few things about the 4 SPI controllers that are onboard the nRF52840 with BLE on but nothing really spot on this problem?
Anything known about using BLE and SPI at the same time (maybe specifically TLC59711)?
I am working on a minimal sketch to better understand what happens (based on the "bleuart" peripheral example where I just add a simple TLC59711). It still crashes...
Any comments welcome! thanks!
feather nRF52840 sense BLE + TLC59711 SPI crash
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jonlab
- Posts: 51
- Joined: Mon Jun 03, 2013 4:15 am
- jonlab
- Posts: 51
- Joined: Mon Jun 03, 2013 4:15 am
Re: feather nRF52840 sense BLE + TLC59711 SPI crash
Here is the minimal sketch:
Here is the console output:
Code: Select all
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <bluefruit.h>
#include <Adafruit_LittleFS.h>
#include <InternalFileSystem.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_TLC59711.h"
#define TLC_DATA 5
#define TLC_CLOCK 6
#define TLC_COUNT 2
Adafruit_TLC59711 tlc = Adafruit_TLC59711(TLC_COUNT, TLC_CLOCK, TLC_DATA);
// BLE Service
BLEDfu bledfu; // OTA DFU service
BLEDis bledis; // device information
BLEUart bleuart; // uart over ble
BLEBas blebas; // battery
int frame = 0;
void setup()
{
Serial.begin(115200);
tlc.begin();
//delay(1000);
#if CFG_DEBUG
// Blocking wait for connection when debug mode is enabled via IDE
while ( !Serial ) yield();
#endif
Serial.println("Bluefruit52 BLEUART Example");
Serial.println("---------------------------\n");
// Setup the BLE LED to be enabled on CONNECT
// Note: This is actually the default behavior, but provided
// here in case you want to control this LED manually via PIN 19
Bluefruit.autoConnLed(true);
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.begin();
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
Bluefruit.setName("minimal"); // useful testing with multiple central connections
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
// To be consistent OTA DFU should be added first if it exists
bledfu.begin();
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.begin();
// Configure and Start BLE Uart Service
bleuart.begin();
// Start BLE Battery Service
blebas.begin();
blebas.write(100);
// Set up and start advertising
startAdv();
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
Serial.println("Once connected, enter character(s) that you wish to send");
}
void startAdv(void)
{
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
// Include bleuart 128-bit uuid
Bluefruit.Advertising.addService(bleuart);
// Secondary Scan Response packet (optional)
// Since there is no room for 'Name' in Advertising packet
Bluefruit.ScanResponse.addName();
/* Start Advertising
* - Enable auto advertising if disconnected
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
* - Timeout for fast mode is 30 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* For recommended advertising interval
* https://developer.apple.com/library/content/qa/qa1931/_index.html
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
//delay(5000);
//Bluefruit.Advertising.stop();
}
void loop()
{
Serial.print("tlc write ");
Serial.println(frame);
tlc.write();
delay(20);
frame++;
}
// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{
Serial.println("connect_callback");
// Get the reference to current connection
BLEConnection* connection = Bluefruit.Connection(conn_handle);
char central_name[32] = { 0 };
connection->getPeerName(central_name, sizeof(central_name));
Serial.print("Connected to ");
Serial.println(central_name);
}
/**
* Callback invoked when a connection is dropped
* @param conn_handle connection where this event happens
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
*/
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void) conn_handle;
(void) reason;
Serial.println();
Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
}
Code: Select all
Bluefruit52 BLEUART Example
---------------------------
[CFG ] SoftDevice's RAM requires: 0x200038A0
Please use Adafruit's Bluefruit LE app to connect in UART mode
Once connected, enter character(s) that you wish to send
BSP Library : 1.3.0
Bootloader : s140 6.1.1
Serial No : 93BE6C1D3E746E75
--------- SoftDevice Config ---------
Max UUID128 : 10
ATTR Table Size : 4096
Service Changed : 1
Peripheral Connect Setting
- Max MTU : 247
- Event Length : 100
- HVN Queue Size : 3
- WrCmd Queue Size: 1
--------- BLE Settings ---------
Name : minimal
Max Connections : Peripheral = 1, Central = 0
Address : F5:DC:F6:80:58:0D (Static)
TX Power : 4 dBm
Conn Intervals : min = 20.00 ms, max = 30.00 ms
Conn Timeout : 2000 ms
Peripheral Paired Devices:
c9d6 : MacBook Air de Jonathan (121 bytes)
83F0A37A81D0 : MacBook Air de Jona (141 bytes)
tlc write 0
tlc write 1
tlc write 2
tlc write 3
tlc write 4
tlc write 5
tlc write 6
nrf_error_cb: 121: id = 1
void nrf_error_cb(uint32
- jonlab
- Posts: 51
- Joined: Mon Jun 03, 2013 4:15 am
Re: feather nRF52840 sense BLE + TLC59711 SPI crash
I did some more tests - I can toggle the BLE advertising on and off - as soon as I try to write to the TLC59711 with advertising on OR a device connected it crashes (not always at the first write, but sometimes after maybe 1 to 10 writes). If I make sure there is no BLE connection active AND I stop the BLE advertising then I can write to the TLC59711 without any issue. Couldn't that be some timing issue. I notice in the TLC59711 library that interrupts are disabled for some time during the write...
- GilbertD
- Posts: 9
- Joined: Tue May 23, 2017 7:18 pm
Re: feather nRF52840 sense BLE + TLC59711 SPI crash
Hi
I had a similar problem NRF52840 BLE and a LoRa module to control a Sony Camera.
After using the LoRa Radio I was not able to talk to the camera anymore.
I solved this issue by using the RHSoftwareSPI and redefining other pins for the SPI.
In my case I used (MOSI->TX1) (MISO->RX0) ans (SCK->D7)
Now everything work fine.
May worth a try, If you can redefine your pin for your TLC59711.
Best regard Gilbert.
I had a similar problem NRF52840 BLE and a LoRa module to control a Sony Camera.
After using the LoRa Radio I was not able to talk to the camera anymore.
I solved this issue by using the RHSoftwareSPI and redefining other pins for the SPI.
In my case I used (MOSI->TX1) (MISO->RX0) ans (SCK->D7)
Now everything work fine.
May worth a try, If you can redefine your pin for your TLC59711.
Best regard Gilbert.
- jonlab
- Posts: 51
- Joined: Mon Jun 03, 2013 4:15 am
Re: feather nRF52840 sense BLE + TLC59711 SPI crash
It turned out that removing the noInterrupts() ( and the corresponding interrupts() ) call in Adafruit_TLC59711::write() is a workaround - the TLC59711 is still working fine and the nrf52840 is not crashing anymore.
Please be positive and constructive with your questions and comments.