Re: nRF5 action!
I have build up a few NRF modules, including main supply power, Relais, Heating control by pilot wire, all to fit within a 2 DIN unit module within power panel.
They all suffer the same issue, after some time could be few hours or even more than a day they do crash on trying sending something
I have spent nearly a month reading left and right about this in mysensor but did not find ant thread on such issue. I have also tryed either the lastes stable or the dev release without any change. This is propably something evident I dont figure out and thick you help !
I did attach part of the code and part of the debug output when failing
/*
* This example sketch shows how you can manage the nRF5 pin mapping as part of your code.
* You can use the method for any nRF51822 or nRF52832 board or module.
*
* Most components, like UART, SPI, Wire Bus, of the nRF5 series chips don't
* have a fixed pin mapping. There are some pins with restrictions like analog
* inputs, NFC or pins near the radio module. Please refer the latest
* documentation about pin restrictions at http://infocenter.nordicsemi.com
*
* To use the custom pin mapping you have to do following steps:
*
* 1. Install "arduino-nrf5" like described at
* https://github.com/sandeepmistry/arduino-nRF5/
* 2. Install the "My Sensors nRF5 Boards" with the board manager like
* explained at https://github.com/mysensors/ArduinoBoards
* 3. Copy the files "MyBoardNRF5.cpp" and "MyBoardNRF5.h" from
* "MyBoardNRF5" example into your sketch.
* 4. Modify pin mappings in "MyBoardNRF5.cpp" and "MyBoardNRF5.h" to fit
* your requirements.
* 5. Select "MyBoardNRF5 nrf52832" or "MyBoardNRF5 nrf52822" as your board.
* Choose the correct parameters and programmer in the Tools menu.
*/
/* Module DIN 6xPilotes
* LED verte Power
* LED Rouge état Pilote (6x)
* P0.20 -> LED D4 Pilote 1
* P0.25 -> LED D8 Pilote 2
* P0.19 -> LED D3 Pilote 3
* P0.23 -> LED D6 Pilote 4
* P0.18 -> LED D2 Pilote 5
* P0.24 -> LED D7 Pilote 6
* LED Bleu Communication Radio
* P0.22 -> LED D5 Comunication
*/
#define MY_DEBUG
#define MY_SPECIAL_DEBUG
#define MY_DEBUG_VERBOSE
#define MY_DEBUG_VERBOSE_NRF5_ESB
// #define MY_TRANSPORT_SANITY_CHECK
#define MY_RADIO_NRF5_ESB
#define MY_NODE_ID 121
//#define MY_PASSIVE_NODE
// Inverses the behavior of leds
#define MY_WITH_LEDS_BLINKING_INVERSE
// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 22 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 22 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 22 // Transmit led pin
#define INTER_MESSAGES_WAIT 50
#include <MySensors.h>
#include <Wire.h>
#include "Adafruit_MCP23017.h"
#define LED_ON 0
#define LED_OFF 1
#define LED_PILOTE_1 20
#define LED_PILOTE_2 25
#define LED_PILOTE_3 19
#define LED_PILOTE_4 23
#define LED_PILOTE_5 18
#define LED_PILOTE_6 24
#define NB_LED_PILOTE 6
const int LEDS_PILOTE[6] = {
LED_PILOTE_1,
LED_PILOTE_2,
LED_PILOTE_3,
LED_PILOTE_4,
LED_PILOTE_5,
LED_PILOTE_6
};
typedef struct {
char mode_code;
int code_A;
int code_B;
} modeFilPilote;
const modeFilPilote modesFilPilote[4] = {
{'O', 0, 1}, // Mode Off
{'G', 1, 0}, // Mode hors gel
{'E', 0, 0}, // Mode éco
{'C', 1, 1} // Mode confort
};
typedef struct {
int childID;
char *name;
char lastOrder;
int pin_A;
int pin_B;
bool newState;
} FilPilote;
FilPilote ListFilPilote[6] = {
{0, "Pilote1", 'O', 0, 8, true},
{1, "Pilote2", 'O', 1, 9, true},
{2, "Pilote3", 'O', 2, 10, true},
{3, "Pilote4", 'O', 3, 11, true},
{4, "Pilote5", 'O', 4, 12, true},
{5, "Pilote6", 'O', 5, 13, true}
};
#define NB_PILOTE 6
int LedTimer = 0;
int BatteryTimer = 0;
MyMessage msg_S_HEATER(14,V_STATUS);
Adafruit_MCP23017 mcp;
//-------------------------------------
void nRF_Init() {
NRF_POWER->DCDCEN = 0; // Not reducing the radio current
NRF_PWM0 ->ENABLE = 0;
NRF_PWM1 ->ENABLE = 0;
NRF_PWM2 ->ENABLE = 0;
NRF_TWIM1 ->ENABLE = 0;
NRF_TWIS1 ->ENABLE = 0;
//NRF_RADIO->TXPOWER = 8;
}
void disableNfc() {
NRF_NFCT->TASKS_DISABLE = 1;
NRF_NVMC->CONFIG = 1;
NRF_UICR->NFCPINS = 0;
NRF_NVMC->CONFIG = 0;
}
void turnOffAdc() {
if (NRF_SAADC->ENABLE) {
NRF_SAADC->TASKS_STOP = 1;
while (NRF_SAADC->EVENTS_STOPPED) {}
NRF_SAADC->ENABLE = 0;
while (NRF_SAADC->ENABLE) {}
}
}
//void sleepI2C() {
// NRF_TWI1->ENABLE=TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; // I2C Begin is then required on resume (sensor.begin();)
// *(volatile uint32_t *)0x40004FFC = 0;
// *(volatile uint32_t *)0x40004FFC;
// *(volatile uint32_t *)0x40004FFC = 1;
//}
//---------------------------------------
void preHwInit()
{
// Configure Leds ports
pinMode(22, OUTPUT);
for (int i = 0; i < NB_LED_PILOTE; i++) {
pinMode(LEDS_PILOTE[i], OUTPUT);
digitalWrite(LEDS_PILOTE[i], LED_OFF);
}
// Test Leds
for(int i=0; i < NB_LED_PILOTE +1; i++)
{
if (i-1>=0)digitalWrite(LEDS_PILOTE[i-1], LED_OFF);
if (i < NB_LED_PILOTE)digitalWrite(LEDS_PILOTE[i], LED_ON);
wait(250);
}
}
void before()
{
nRF_Init();
disableNfc();
turnOffAdc();
wait(200);
}
void setup()
{
mcp.begin(); // use default address 0
// Load Pilot saved states
for (int i = 0; i < NB_PILOTE; i++) {
ListFilPilote[i].lastOrder = loadState(ListFilPilote[i].childID);
}
// Set MCP ports
for (int i = 0; i <= 15; i++) {
mcp.pinMode(i, OUTPUT);
mcp.digitalWrite(0, HIGH);
}
}
void presentation()
{
sendSketchInfo("DIN 6xPILOTES Gite 1", "0.8");
wait(INTER_MESSAGES_WAIT);
// Present Pilote
for (int i = 0; i < NB_PILOTE; i++)
{
present(ListFilPilote[i].childID, S_HEATER, ListFilPilote[i].name);
wait(INTER_MESSAGES_WAIT);
}
}
void loop()
{
/*
* Off: Half upper Led: Off
* Confort: Nothing Led: On
* Eco: Half upper & lower (Full) Led: Blinking 50/50
* Frizing Protect: Half lower Led: Blinking 10/90
*/
for(int i=0; i < NB_LED_PILOTE; i++)
{
switch (ListFilPilote[i].lastOrder)
{
case 'G': // horsgel
if (LedTimer <9) digitalWrite(LEDS_PILOTE[i], LED_OFF);
else digitalWrite(LEDS_PILOTE[i], LED_ON);
break;
case 'E': // Eco
if (LedTimer < 5) digitalWrite(LEDS_PILOTE[i], LED_ON);
else digitalWrite(LEDS_PILOTE[i], LED_OFF);
break;
case 'O': // off
digitalWrite(LEDS_PILOTE[i], LED_OFF);
break;
case 'C': // Confort
digitalWrite(LEDS_PILOTE[i], LED_ON);
break;
}
}
LedTimer++;
if (LedTimer > 9) LedTimer = 0;
BatteryTimer++;
if (BatteryTimer > 599)
{
BatteryTimer = 0;
#ifdef MY_DEBUG
Serial.println("Send Battery Level");
#endif
sendBatteryLevel(100);
// sendHeartbeat();
}
wait(100);
}
void receive(const MyMessage &message)
{
if (message.type == V_HVAC_FLOW_STATE)
{
for(int p=0; p < NB_PILOTE; p++)
{
if (message.sensor == ListFilPilote[p].childID)
{
#ifdef MY_DEBUG
Serial.print("--Incoming change for: ");
Serial.print(ListFilPilote[p].name);
Serial.print(" --Command: ");
Serial.print(message.getString()[0]);
Serial.println();
#endif
for(int e=0; e < 4; e++)
{
if(message.getString()[0] == modesFilPilote[e].mode_code)
{
// Set new state
mcp.digitalWrite(ListFilPilote[p].pin_A, modesFilPilote[e].code_A);
mcp.digitalWrite(ListFilPilote[p].pin_B, modesFilPilote[e].code_B);
// Save state
ListFilPilote[p].lastOrder = modesFilPilote[e].mode_code;
saveState(ListFilPilote[p].childID, modesFilPilote[e].mode_code);
// Send status update
send(msg_S_HEATER.setSensor(ListFilPilote[p].childID).set((const char *)(modesFilPilote[e].mode_code)));
return;
}
}
// Unknown Order
#ifdef MY_DEBUG
Serial.print("--Unknown Order: ");
Serial.println(message.getString()[0]);
#endif
}
// Wrong Child_ID
#ifdef MY_DEBUG
Serial.print("--Wrong ChildID: ");
Serial.println(message.sensor);
#endif
}
}
}
and the logs
05:08:52.392 -> 72652589 NRF5:SND:TO=0,LEN=8,PID=0,NOACK=0
05:08:52.392 -> 72652596 NRF5:SND:END=1,ACK=1,RTRY=2,RSSI=-45,WAKE=8
05:08:52.392 -> 72652601 TSF:MSG:SEND,121-121-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
05:09:52.387 -> Send Battery Level
05:09:52.387 -> 72712609 NRF5:SND:TO=0,LEN=8,PID=1,NOACK=0
05:09:52.387 -> 72712616 NRF5:SND:END=1,ACK=1,RTRY=2,RSSI=-45,WAKE=8
05:09:52.387 -> 72712621 TSF:MSG:SEND,121-121-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
05:10:52.433 -> Send Battery Level
05:10:52.433 -> 72772629 NRF5:SND:TO=0,LEN=8,PID=2,NOACK=0
05:10:52.433 -> 72772636 NRF5:SND:END=1,ACK=1,RTRY=2,RSSI=-45,WAKE=8
05:10:52.433 -> 72772641 TSF:MSG:SEND,121-121-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
05:11:52.429 -> Send Battery Level
05:11:52.429 -> 72832649 NRF5:SND:TO=0,LEN=8,PID=3,NOACK=0
05:11:52.429 -> 72832656 NRF5:SND:END=1,ACK=1,RTRY=2,RSSI=-45,WAKE=8
05:11:52.429 -> 72832661 TSF:MSG:SEND,121-121-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
05:12:52.459 -> Send Battery Level
05:12:52.459 -> 72892669 NRF5:SND:TO=0,LEN=8,PID=0,NOACK=0
05:12:52.459 -> 72892676 NRF5:SND:END=1,ACK=1,RTRY=2,RSSI=-45,WAKE=8
05:12:52.459 -> 72892681 TSF:MSG:SEND,121-121-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
05:13:52.481 -> Send Battery Level
05:13:52.481 -> 72952689 NRF5:SND:TO=0,LEN=8,PID=1,NOACK=0
05:13:52.481 -> 72952696 NRF5:SND:END=1,ACK=1,RTRY=2,RSSI=-45,WAKE=8
05:13:52.481 -> 72952701 TSF:MSG:SEND,121-121-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
05:14:52.511 -> Send Battery Level
05:14:52.511 -> 73012709 NRF5:SND:TO=0,LEN=8,PID=2,NOACK=0
05:14:52.511 -> 73012716 NRF5:SND:END=1,ACK=1,RTRY=2,RSSI=-45,WAKE=8
05:14:52.511 -> 73012721 TSF:MSG:SEND,121-121-0-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
05:15:52.484 -> Send Battery Level
05:15:52.484 -> 73072729 NRF5:SND:TO=0,LEN=8,PID=3,NOACK=0