nRF5 action!
-
@mfalkvidd yeah, now you tell me
-
So I made a version of script with MySensors library, it's not a final version and needs some cleaning and improvements but it seems to work well (I didn't test so much yet :)) and shows basic usage. Comments should be enough to understand what to change to adapt to your board. Current script is for my board:
- BUTTON_1 on pin 1, it's a hall sensor for door so no pullup and sensing on up=>down and down=>up changes
- BUTTON_2 on pin 3, push button with pullup and debouncing, sensing only on up=>down when button is pressed. At the moment it just makes some light blinking to show it's detected.
- led on pin 2.
I join the main script file and the MyBoardNRF5 files, for using with MyBoardNRF5 nrf51822. Files to include are described in the main script file, but don't forget to add a weak attribute in the WInterrupt.c file before the GPIOTE_IRQHandler so it can be overridden.
__attribute__ ((weak)) void GPIOTE_IRQHandler()
On my Windows PC this file is in C:\Users[your user name]\AppData\Local\Arduino15\packages\sandeepmistry\hardware\nRF5\0.5.1\cores\nRF5
Main script file:
// Include app_gpiote and related files from NRF5 SDK 12 extern "C" { #include "app_gpiote.h" #include "nrf_gpio.h" #include "app_error.h" } // Files to include from SDK: // app_error_weak.h + .c // app_gpiote.h + .c // app_util.h // nordic_common.h // nrf_error.h // nrf_gpio.h // sdk_errors.h // app_error.h + .c // for this last one (c file) I decided to stop the endless list of includes so I commented the following includes: // #include "sdk_errors.h", #include "nrf_log.h", #include "nrf_log_ctrl.h" lines #include <nrf.h> #define IS_NRF51 //true if the target is an nRF51. If an nRF52, then comment this line out! #define APP_GPIOTE_MAX_USERS 1 // max users for app_gpiote, we only use one #define MY_RADIO_NRF5_ESB #define MY_NODE_ID 60 // To avoid getting a new ID at each flashing of the sensors... #include <MySensors.h> // variables for app_gpiote calls uint32_t err_code; static app_gpiote_user_id_t m_gpiote_user_id; uint32_t PIN_BUTTON1_MASK; // Mask for PIN_BUTTON1 input uint32_t PIN_BUTTON2_MASK; // Mask for PIN_BUTTON2 input // defines variables for MySensors #define SN "22Board Door Basic" #define SV "0.2" // Sensor messages #define CHILD_ID_DOOR 1 MyMessage doorMsg(CHILD_ID_DOOR, V_TRIPPED); bool last_sent_value; bool door_status; long last_button2_event = 0; // Cause of interrupt volatile byte interrupt_cause = 0; // Settings to avoid killing coin cell in case of connection problem #define MY_TRANSPORT_WAIT_READY_MS 10000 #define MY_SLEEP_TRANSPORT_RECONNECT_TIMEOUT_MS 5000 // Battery settings #define BATTERY_ALERT_LEVEL 30 // (%) Will triple blink after sending data if battery is equal or below this level // Parameters for VCC measurement #define BATTERY_VCC_MIN 2400 // Minimum expected Vcc level, in milliVolts. #define BATTERY_VCC_MAX 2900 // Maximum expected Vcc level, in milliVolts. // This a a coefficient to fix the imprecision of measurement of the battery voltage #define BATTERY_COEF 1000.0f // (reported voltage / voltage) * 1000 uint16_t currentBatteryPercent; uint16_t lastBatteryPercent = -1; // Enables/disables sleeps between sendings to optimize for CR2032 or similar coin cell #define USE_COIN_CELL // Called before initialization of the library void before() { hwPinMode(LED_BUILTIN, OUTPUT_D0H1); blinkityBlink(2, 3); } // Setup node void setup(void) { //Configure button pins as inputs nrf_gpio_cfg_input(PIN_BUTTON1, NRF_GPIO_PIN_NOPULL); nrf_gpio_cfg_input(PIN_BUTTON2, NRF_GPIO_PIN_PULLUP); APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS); //Only initialize once. Increase value of APP_GPIOTE_MAX_USERS if needed // Initialize value of pin (for DRV5032 hall sensor HIGH = no magnet nearby = door opened); door_status = digitalRead(PIN_BUTTON1); last_sent_value = !door_status; // so we always send value in first loop // Registers user and pins we are "watching" // gpiote_event_handler is handler called by interrupt, see method below PIN_BUTTON1_MASK = 1 << PIN_BUTTON1; // Set mask, will be used for registration and interrupt handler PIN_BUTTON2_MASK = 1 << PIN_BUTTON2; // Set mask, will be used for registration and interrupt handler // app_gpiote_user_register(p_user_id, pins_low_to_high_mask, pins_high_to_low_mask, event_handler) // to have no trigger for high=>low or low=>high change on your button, pass 0 instead // here I check PIN_BUTTON1 on both low=>high and high=>low changes and PIN_BUTTON2 only on high=>low change when someone presses the button err_code = app_gpiote_user_register(&m_gpiote_user_id, PIN_BUTTON1_MASK, PIN_BUTTON1_MASK | PIN_BUTTON2_MASK, gpiote_event_handler); APP_ERROR_CHECK(err_code); // will reset if user registration fails // Enable SENSE and interrupt err_code = app_gpiote_user_enable(m_gpiote_user_id); APP_ERROR_CHECK(err_code); // will reset if SENSE enabling fails // initialize last event for button2 debounce last_button2_event = millis(); } void presentation() { sendSketchInfo(SN, SV); present(CHILD_ID_DOOR, S_DOOR); } // Sleep between sendings to preserve coin cell // if not using button cell just make sure the #define USE_COIN_CELL is commented at the beginning of the sketch and it will do nothing void sleepForCoinCell() { #ifdef USE_COIN_CELL sleep(400); #endif } // main loop void loop(void) { // for sending battery level at first run if (lastBatteryPercent < 0) { sendBatteryStatus(); sleepForCoinCell(); } if (interrupt_cause == PIN_BUTTON1) { // if door status changed, we send door message if (door_status != last_sent_value) { sendDoorStatus(); } } else if (interrupt_cause == PIN_BUTTON2) { if (millis() < last_button2_event || (millis() - last_button2_event > 100)) { last_button2_event = millis(); blinkityBlink(2, 3); // not so useful, just for testing :) } } else { // end of sleeping period, we send battery level sendBatteryStatus(); } // Low battery warning or confirm status of door if (lastBatteryPercent < BATTERY_ALERT_LEVEL) { blinkityBlink(3, 1); } else { blinkityBlink((last_sent_value == true ? 2 : 1), 1); } // Go to sleep mySleepPrepare(); interrupt_cause = 0; // reset interrupt cause sleep(300000); } void sendDoorStatus() { send(doorMsg.set(door_status)); last_sent_value = door_status; } #define CHILD_ID_VOLT 254 MyMessage voltMsg(CHILD_ID_VOLT, V_VOLTAGE); void sendBatteryStatus() { uint16_t batteryVoltage = hwCPUVoltage(); if (batteryVoltage > BATTERY_VCC_MAX) { currentBatteryPercent = 100; } else if (batteryVoltage < BATTERY_VCC_MIN) { currentBatteryPercent = 0; } else { currentBatteryPercent = (100 * (batteryVoltage - BATTERY_VCC_MIN)) / (BATTERY_VCC_MAX - BATTERY_VCC_MIN); } if (currentBatteryPercent != lastBatteryPercent) { sendBatteryLevel(currentBatteryPercent); lastBatteryPercent = currentBatteryPercent; } } // "Interrupt handler" // not real handler, but call inside handler to void gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low) { MY_HW_RTC->CC[0] = (MY_HW_RTC->COUNTER + 2); // Taken from d0016 example code, ends the sleep delay if ((PIN_BUTTON1_MASK & event_pins_low_to_high) || (PIN_BUTTON1_MASK & event_pins_high_to_low)) { interrupt_cause = PIN_BUTTON1; door_status = !door_status; } else if ((PIN_BUTTON2_MASK & event_pins_low_to_high) || (PIN_BUTTON2_MASK & event_pins_high_to_low)) { interrupt_cause = PIN_BUTTON2; } } /** Utility functions for NRF51/52, from nerverdie's code here https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/1307 */ void disableNfc() { //only applied to nRF52 #ifndef IS_NRF51 //Make pins 9 and 10 usable as GPIO pins. NRF_NFCT->TASKS_DISABLE = 1; //disable NFC NRF_NVMC->CONFIG = 1; // Write enable the UICR NRF_UICR->NFCPINS = 0; //Make pins 9 and 10 usable as GPIO pins. NRF_NVMC->CONFIG = 0; // Put the UICR back into read-only mode. #endif } void turnOffRadio() { NRF_RADIO->TASKS_DISABLE = 1; while (!(NRF_RADIO->EVENTS_DISABLED)) {} //until radio is confirmed disabled } void turnOffUarte0() { #ifndef IS_NRF51 NRF_UARTE0->TASKS_STOPRX = 1; NRF_UARTE0->TASKS_STOPTX = 1; NRF_UARTE0->TASKS_SUSPEND = 1; NRF_UARTE0->ENABLE = 0; //disable UART0 while (NRF_UARTE0->ENABLE != 0) {}; //wait until UART0 is confirmed disabled. #endif #ifdef IS_NRF51 NRF_UART0->TASKS_STOPRX = 1; NRF_UART0->TASKS_STOPTX = 1; NRF_UART0->TASKS_SUSPEND = 1; NRF_UART0->ENABLE = 0; //disable UART0 while (NRF_UART0->ENABLE != 0) {}; //wait until UART0 is confirmed disabled. #endif } void turnOffAdc() { #ifndef IS_NRF51 if (NRF_SAADC->ENABLE) { //if enabled, then disable the SAADC NRF_SAADC->TASKS_STOP = 1; while (NRF_SAADC->EVENTS_STOPPED) {} //wait until stopping of SAADC is confirmed NRF_SAADC->ENABLE = 0; //disable the SAADC while (NRF_SAADC->ENABLE) {} //wait until the disable is confirmed } #endif } void turnOffHighFrequencyClock() { NRF_CLOCK->TASKS_HFCLKSTOP = 1; while ((NRF_CLOCK->HFCLKSTAT) & 0x0100) {} //wait as long as HF clock is still running. } void mySleepPrepare() { turnOffHighFrequencyClock(); turnOffRadio(); turnOffUarte0(); } void blinkityBlink(uint8_t pulses, uint8_t repetitions) { for (int x = 0; x < repetitions; x++) { // wait only in case there's been a previous blink if (x > 0) { sleep(500); } for (int i = 0; i < pulses; i++) { // wait only in case there's been a previous blink if (i > 0) { sleep(100); } digitalWrite(LED_BUILTIN, HIGH); wait(20); digitalWrite(LED_BUILTIN, LOW); } } }
MyBoardNRF5.h
/* If you don't use an nRF5 board, you can ignore this file. This file was part of the "My Sensors nRF5 Boards" board repository available at https://github.com/mysensors/ArduinoBoards If you have questions, please refer the documentation at https://github.com/mysensors/ArduinoHwNRF5 first. This file is compatible with ArduinoHwNRF5 >= 0.2.0 This file allows you to change the pins of internal hardware, like the serial port, SPI bus or Wire bus. All pins referenced here are mapped via the "g_ADigitalPinMap" Array defined in "MyBoardNRF5.cpp" to pins of the MCU. As an example, if you have at the third position in "g_ADigitalPinMap" the 12, then all ports referenced in Arduino with 2 are mapped to P0.12. If you don't change the "g_ADigitalPinMap" Array, the Arduino pins 0..31 are translated to P0.00..P0..31. ########################################################################### This file is compatible with ArduinoHwNRF5 > 0.1.0 Copyright (c) 2014-2015 Arduino LLC. All right reserved. Copyright (c) 2016 Sandeep Mistry. All right reserved. Copyright (c) 2017 Sensnology AB. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _MYBOARDNRF5_H_ #define _MYBOARDNRF5_H_ #ifdef __cplusplus extern "C" { #endif // __cplusplus // Number of pins defined in PinDescription array #define PINS_COUNT (32u) #define NUM_DIGITAL_PINS (32u) #define NUM_ANALOG_INPUTS (8u) #define NUM_ANALOG_OUTPUTS (8u) /* * LEDs * * This is optional * * With My Sensors, you can use * hwPinMode() instead of pinMode() * hwPinMode() allows to use advanced modes like OUTPUT_H0H1 to drive LEDs. * https://github.com/mysensors/MySensors/blob/development/drivers/NRF5/nrf5_wiring_constants.h * */ #define PIN_LED1 (2) // #define PIN_LED2 (25) // #define PIN_LED3 (26) // #define PIN_LED4 (27) // #define PIN_LED5 (12) // #define PIN_LED6 (14) // #define PIN_LED7 (15) // #define PIN_LED8 (16) // #define USER_LED (PIN_LED2) // #define RED_LED (PIN_LED3) // #define GREEN_LED (PIN_LED4) // #define BLUE_LED (PIN_LED1) // #define BLE_LED BLUE_LED #define LED_BUILTIN PIN_LED1 /* * Buttons * * This is optional */ #define PIN_BUTTON1 (1) #define PIN_BUTTON2 (3) // #define PIN_BUTTON3 (5) // #define PIN_BUTTON4 (6) // #define PIN_BUTTON5 (7) // #define PIN_BUTTON6 (8) // #define PIN_BUTTON7 (9) // #define PIN_BUTTON8 (10) /* * Analog ports * * If you change g_APinDescription, replace PIN_AIN0 with * port numbers mapped by the g_APinDescription Array. * You can add PIN_AIN0 to the g_APinDescription Array if * you want provide analog ports MCU independed, you can add * PIN_AIN0..PIN_AIN7 to your custom g_APinDescription Array * defined in MyBoardNRF5.cpp */ /* static const uint8_t A0 = ADC_A0; static const uint8_t A1 = ADC_A1; static const uint8_t A2 = ADC_A2; static const uint8_t A3 = ADC_A3; static const uint8_t A4 = ADC_A4; static const uint8_t A5 = ADC_A5; static const uint8_t A6 = ADC_A6; static const uint8_t A7 = ADC_A7; */ /* * Serial interfaces * * RX and TX are required. * If you have no serial port, use unused pins * CTS and RTS are optional. */ #define PIN_SERIAL_RX (29) #define PIN_SERIAL_TX (28) // #define PIN_SERIAL_CTS (13) // #define PIN_SERIAL_RTS (14) /* * SPI Interfaces * * This is optional * * If SPI is defined MISO, MOSI, SCK are required * SS is optional and can be used in your sketch. */ #define SPI_INTERFACES_COUNT 0 #define PIN_SPI_MISO (6) #define PIN_SPI_MOSI (3) #define PIN_SPI_SCK (4) #define PIN_SPI_SS (5) static const uint8_t SS = PIN_SPI_SS; static const uint8_t MOSI = PIN_SPI_MOSI; static const uint8_t MISO = PIN_SPI_MISO; static const uint8_t SCK = PIN_SPI_SCK; /* * Wire Interfaces * * This is optional */ #define WIRE_INTERFACES_COUNT 1 #define PIN_WIRE_SDA (9u) #define PIN_WIRE_SCL (10u) /* #define PIN_WIRE_SDA1 (15u) #define PIN_WIRE_SCL1 (16u) */ static const uint8_t SDA = PIN_WIRE_SDA; static const uint8_t SCL = PIN_WIRE_SCL; #ifdef __cplusplus } #endif #endif
MyBoardNRF5.cpp
/* If you don't use an nRF5 board, you can ignore this file. This file was part of the "My Sensors nRF5 Boards" board repository available at https://github.com/mysensors/ArduinoBoards If you have questions, please refer the documentation at https://github.com/mysensors/ArduinoHwNRF5 first. This file is compatible with ArduinoHwNRF5 >= 0.2.0 This file allows you to change the relation between pins referenced in the Arduino IDE (0..31) and pins of the nRF5 MCU (P0.00..P0.31). If you can live with addressing the GPIO pins by using the Arduino pins 0..31 instead of a custom mapping, don't change this file. If you have a lot of Arduino code with fixed pin numbers and you need to map these pins to specific pins of the nRF5 MCU; you need to change this file. If you fill the "g_APinDescription" Array with numbers between 0..31, the Arduino pins 0..31 are assigned to pins P0.00..P0.31 of the MCU. As an example, if you need to change the pin mapping for Arduino pin 5 to P0.12 of the MCU, you have to write the 12 after PORT0 into the sixth position in the "g_APinDescription" Array. The extended attributes only affects the nRF5 variants provided with official Arduino boards. The arduino-nrf5 variant ignores the extended attributes. The pin mapping effects commands like "pinMode()", "digitalWrite()", "analogRead()" and "analogWrite()". If you change the pin mapping, you have to modify the pins in "MyBoardNRF5.h". Especially the analog pin mapping must be replaced with your pin numbers by replacing PIN_AIN0..7 with a number of your mapping array. You can use the constants PIN_AIN0..7 in the "g_APinDescription" Array if you want to reference analog ports MCU independent. You cannot use the pins P0.00 and P0.01 for GPIO, when the 32kHz crystal is connected. ########################################################################### Copyright (c) 2014-2015 Arduino LLC. All right reserved. Copyright (c) 2016 Arduino Srl. All right reserved. Copyright (c) 2017 Sensnology AB. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifdef MYBOARDNRF5 #include <variant.h> /* * Pins descriptions. Attributes are ignored by arduino-nrf5 variant. * Definition taken from Arduino Primo Core with ordered ports */ const PinDescription g_APinDescription[]= { { PORT0, 0, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM0, NOT_ON_TIMER}, // AREF0 ADC/LPCOMP reference input 0 { PORT0, 1, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A2, PWM1, NOT_ON_TIMER}, { PORT0, 2, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A3, PWM2, NOT_ON_TIMER}, { PORT0, 3, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A4, PWM3, NOT_ON_TIMER}, { PORT0, 4, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A5, PWM4, NOT_ON_TIMER}, { PORT0, 5, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A6, PWM5, NOT_ON_TIMER}, { PORT0, 6, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A7, PWM6, NOT_ON_TIMER}, // AREF1 ADC/LPCOMP reference input 1 { PORT0, 7, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM7, NOT_ON_TIMER}, { PORT0, 8, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM8, NOT_ON_TIMER}, { PORT0, 9, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM9, NOT_ON_TIMER}, { PORT0, 10, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM10, NOT_ON_TIMER}, { PORT0, 11, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, PWM11, NOT_ON_TIMER}, { PORT0, 12, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 13, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 14, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 15, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 16, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 17, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 18, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 19, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 20, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 21, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 22, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 23, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 24, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 25, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 26, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A0, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 27, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), ADC_A1, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 28, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER}, { PORT0, 29, PIO_DIGITAL, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER} }; // Don't remove this line #include <compat_pin_mapping.h> #endif
-
I'm struggling to get my EByte NRF52 to work. I'm on a mac, so it should be easy..
I installed the two boards in the Arduino IDE.
https://github.com/sandeepmistry/arduino-nRF5
https://github.com/mysensors/ArduinoBoardsThen I carefully soldered some wires on it, and connected it to my ST-Link V2:
gnd ->gnd (in the corner)
3.3v -> vcc (in the same corner)
SWDIO -> SWDIO
SWDCLK -> SWDCLKDownloaded the example app with three files in one folder (like the post above this one)
- Main file
- MyBoardNRF5.h
- MyBoardNRF5.cpp
In Arduino I set things up:
- Board: "MyBoardNRF5 NRF52832"
- Reset: "don't enable"
- Bootloader/SD: "none"
- Low frequency clock: "RC Oscilator" (tried others too)
- Port: none
- Programmer: ST-Link V2
Then I try "sketch -> upload via programmer"
I tried to 'wipe' the chip by clicking "tools -> burn bootloader"I always get:
Open On-Chip Debugger 0.10.0-dev-gdc53227 (2016-04-09-13:45) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html debug_level: 2 0x4000 Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter speed: 10000 kHz Info : Unable to match requested speed 10000 kHz, using 4000 kHz Info : Unable to match requested speed 10000 kHz, using 4000 kHz Info : clock speed 4000 kHz Info : STLINK v2 JTAG v19 API v2 SWIM v4 VID 0x0483 PID 0x3748 Info : using stlink api v2 Info : Target voltage: 3.242857 Info : nrf52.cpu: hardware has 0 breakpoints, 2 watchpoints Error: timed out while waiting for target halted TARGET: nrf52.cpu - Not halted in procedure 'program' in procedure 'reset' called at file "embedded:startup.tcl", line 478 in procedure 'ocd_bouncer' embedded:startup.tcl:454: Error: ** Unable to reset target ** in procedure 'program' in procedure 'program_error' called at file "embedded:startup.tcl", line 479 at file "embedded:startup.tcl", line 454 the selected serial port at file "embedded:startup.tcl", line 454 does not exist or your board is not connected
I found loads of things online and in this thread.
- Could it be some kind of security bit that needs to be erased?
- I also suspect I have not connected it properly? Does the board have a power / indicator LED that should light up when its connected to power? Nothing lights up currently..
- Does the STLink V2 not provide enough power?
- I replaced the wires. Same problem.
-
@alowhum said in nRF5 Bluetooth action!:
STLink V2
I can't comment on the STLink V2, but if using a JTAG, you want to power the module independently from the programmer, because the programmer is meant to sense the voltage there more than to supply it. Maybe worth a try? Looking back, I've often thought it may be the reason why my early attempts with the STlink V2 failed. At least it's something you can look into while you wait for the cavalry to come rescue you.
Also, not sure as to whether running on a Mac is a good idea.
-
W00t! Hurray! Nevermind. I just tried my other module, and that one worked fine!
Open On-Chip Debugger 0.10.0-dev-gdc53227 (2016-04-09-13:45) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html debug_level: 2 0x4000 Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD adapter speed: 10000 kHz Info : Unable to match requested speed 10000 kHz, using 4000 kHz Info : Unable to match requested speed 10000 kHz, using 4000 kHz Info : clock speed 4000 kHz Info : STLINK v2 JTAG v19 API v2 SWIM v4 VID 0x0483 PID 0x3748 Info : using stlink api v2 Info : Target voltage: 3.239128 Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints nrf52.cpu: target state: halted target halted due to debug-request, current mode: Thread xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc ** Programming Started ** auto erase enabled Info : nRF51822-QFN48(build code: B00) 512kB Flash Warn : using fast async flash loader. This is currently supported Warn : only with ST-Link and CMSIS-DAP. If you have issues, add Warn : "set WORKAREASIZE 0" before sourcing nrf51.cfg to disable it nrf52.cpu: target state: halted target halted due to breakpoint, current mode: Thread xPSR: 0x61000000 pc: 0x2000001e msp: 0xfffffffc wrote 4096 bytes from file /var/folders/pg/bjymtmv12dv77vh__zxyvs600000gn/T/arduino_build_362545/MyBoardNRF5.ino.hex in 0.215516s (18.560 KiB/s) ** Programming Finished ** ** Verify Started ** nrf52.cpu: target state: halted target halted due to breakpoint, current mode: Thread xPSR: 0x61000000 pc: 0x2000002e msp: 0xfffffffc verified 2768 bytes in 0.065170s (41.478 KiB/s) ** Verified OK ** ** Resetting Target ** shutdown command invoked
I had to do "burn bootloader" once to remove the security. And then it worked!
Hmm "reset enable" is still turned on. What does that do exactly?
-
Glad you found the breakout board useful. I hesitated to post it, thinking it might be too "easy," and it never did get many likes.
-
@neverdie: yes very useful! I was thinking I should buy some, and wanted to explore which ones could be bought without a credit card (Europe..).
Perhaps you can entice some Chinese manuafacturer to put create a lot of them and then sell them on Aliexpress
-
@neverdie I think these are your design? Bought some when I was ordering some other stuff from Pcbway but haven't gotten around to using them yet.
-
Yup. Those little boards are really quite handy.
Thanks for the photo!
-
Nice indeed. I was just about to order some of those breakouts after receiving 4 Ebyte modules (€8 total).
But just to make sure (I didn't read the complete thread...), the capacitors for DEC1, DEC3 and DEC4 are already present on the Ebyte module, so no need to add these on your breakout, @NeverDie ?
-
No need to add anything not already on the board.
-
You could add some inductors for dcdc mode
-
@omemanti Yes I will. This is a long thread to catch up ;-), but I did find that the latest revision of the breakout added room for the inductors to use the DCDC mode.
I guess it takes some more reading & doing to get the firmware loaded on those Ebyte modules, but as others did that already I'm confident that that will be ok!
It will be my first nRF52 application.
-
I'm working on a gesture sensor connected to a Fanstell BT832 via I2C. It is a Sparkfun APDS9960 breakout I have had lying around for a while. Unfortunately I can't get my sketch to compile. It gives 'Wire' was not declared in this scope.
Wire.h is included in the library and in the sketch. I'm using MyBoardNRF5 for an NRF52832. Using Arduino 1.8.3 on Windows 10.
There is a wire library in:
\AppData\Local\Arduino15\packages\sandeepmistry\hardware\nRF5\0.5.1\libraries\Wire
Which I think is the one that this sketch should be using.
Usually I can sort out the compile errors, but this one has me stumped.
Anyone have any suggestions?
-
@nagelc if you turn on "show verbose output during compilation+upload" in File->preferences you should get output telling which library the Arduino IDE has chosen.
The following sketch:#define MY_RADIO_NRF5_ESB #include <Wire.h> #include <MySensors.h> void setup() { } void loop() { }
Gives this result for me:
Using library Wire at version 1.0 in folder: C:\Users\Micke\AppData\Local\Arduino15\packages\sandeepmistry\hardware\nRF5\0.5.1\libraries\Wire Using library MySensors at version 2.3.0-alpha in folder: R:\Documents\Arduino\libraries\MySensors
-
@mfalkvidd Thanks. The verbose settings show it using the sandeepmistry library.
Wire.h works fine when I include it in my sketch. There is something about the way it is called in the Sparkfun library that fails to compile. I'll keep poking at it.
Duh . . . Found the problem!
I had left WIRE_INTERFACES_COUNT defined as 0 in MyBoardNRF5.h
It has to be #defined to 1 or more, or the sandeepmistry library doesn't extern Wire.
I looked at the SDA and SCL pin definitions in MyBoardNRF5.h, but missed setting the define for how many I2C interfaces were to be used.
Change #define WIRE_INTERFACES_COUNT 1. Now it compiles as expected.
-
This might be a silly question, but: there there a number of NRF5 smart watches available on Aliexpress, like this one. Would it theoretically be possible to turn that into a MySensors smart watch? If you had access to the programming pins, for example?
-
@alowhum Usurping control of it by uploading code wouldn't be difficult, assuming access to the programming pins. However, taking control of the screen and making good use of it might be difficult
-
yes it's doable, maybe not for those who are not smd friendly. And once opened it should be less waterproof
-
@alowhum there is a whole "movement" of people who are trying to reprogram them. Key issue is openability (how hard is to open it)
The last easily openable watches are based on nrf51822, but the good thing is that programming pins are easily accesable and even marked SWD/SCLCK.
Search Ali for ID107HR and google for "roger clark smartwatch"
I am yet to find a watch that would be both nrf52 based AND easily openable
-
https://github.com/micooke/arduino-nRF5-smartwatches
Mark is a fantastic guy
-
@toyman said in nRF5 Bluetooth action!:
"roger clark smartwatch"
Seems like there is hope then of accessing the screen after all. On http://www.rogerclark.net/arduino-on-the-id100hr-fitness-tracker/ it says: "Display: 0.49 inch OLED display (64×32 pixels) which uses the SSD1306 display controller"
-
Maybe someone here can figure out how to 3D print their own nRF52832 smart watch? i.e. one that's meant to be taken apart and put back together so that it's as good as new.
-
@neverdie read Issues section in Mark Cooks's repo referenced above. He's just committed a PR to support the display.
I need nrf52 to able to use Central role in my projects. For Mysensors nrf51 is pretty adequate if someone wants to create something like a wearable weather station
Everything is in place.
-
@toyman Seems like it has a lot of potential as an awesome notifier/remote-control that's conveniently always with you. If you succeed in getting it to work, please do post a photo and let us know!
-
Note: to hack it you need a J-Link device:
https://github.com/micooke/arduino-nRF5-smartwatches/blob/master/nrf52_disable_read_protection.txt
-
@nca78 I tried to follow your instructions in post #1514 but I must be doing something wrong when I add files from the NRF5 SDK to my sketch folder because I keep getting some errors about missing files, so I keep adding and now I got to this point:
WARNING: Spurious .ci folder in 'MySensors' library WARNING: Spurious .mystools folder in 'MySensors' library In file included from C:\Users\Tomas\Documents\Arduino\NRF5SceneCtLC2Protoboard\NRF5SceneCtLC2Protoboard.ino:4:0: nrf_gpio.h:67: error: #error "Not supported." #error "Not supported." ^ exit status 1 #error "Not supported."
-
@korttoma sorry it seems I messed up with the files, this one is not from sdk.
Please take the one here, I'll clean up and reorganize later:
https://github.com/bitcraze/crazyflie2-nrf-mbs/blob/master/include/nrf/nrf_gpio.h
-
@nca78 still not getting anywhere with this. Would you mind ziping your sketch folder, then I should have all the correct files (right?). If I still have issues to compile I must be missing some library or are using the wrong version of something.
-
@korttoma said in nRF5 Bluetooth action!:
@nca78 still not getting anywhere with this. Would you mind ziping your sketch folder, then I should have all the correct files (right?). If I still have issues to compile I must be missing some library or are using the wrong version of something.
Sure, but unfortunately I cannot upload a zip file here, please send me your email by private message.
Ok here is a google drive link, it should be easier:
https://drive.google.com/open?id=1IhLIx0nHd5KZR9dJ9qA0-_SMGmjEpbKj
-
@toyman said in nRF5 Bluetooth action!:
I am yet to find a watch that would be both nrf52 based AND easily openable
or, perhaps a little easier, this one?
https://www.alibaba.com/product-detail/2018-NEW-Messages-Sync-smart-bracelet_60733935490.html?spm=a2700.7724857.main07.70.6deb404ewQickLI'm guessing that a typical jeweler would have the right tools to open it. Maybe get a little help with that part of it? I doubt it would cost much.
Fortunately, there seem to be a plethora of different inexpensive nRF52832 watches available. Gobs of them.
https://www.aliexpress.com/item/CACGO-K2-Smart-Watch-Bluetooth-4-0-Nordic-NRF52832-Chip-Sleep-Heart-Rate-Blood-Pressure-Blood/32853451564.html
-
@neverdie AFAIK, they are all heavily glued to meet IPX67
-
Just curious design consideration, based on my question to Nordic:
https://devzone.nordicsemi.com/f/nordic-q-a/33448/led-power
LED consumption will not exceed 0.5ma if the pin is configured as s0s1
-
@toyman Maybe that's enough to light a subset of the pixels on the display?
In theory these nRF52832 BLE are OTA re-programmable. If someone left the door open for that, then you wouldn't have to crack the case or fight with the glue. Well, maybe someday...
-
@neverdie I was thinking about that, but that's not gonna work. Why? The bootloader that accepts OTA has a private key. The key in the software should match the key.
-
@toyman Would this work? Buy two. Sacrifice the first so that you can image the firmware on the chip and extract the password. Use that password to unlock the OTA firmware update for the second one.
Or, maybe it's the universal bluetooth password: 1234. Maybe try that first.
-
afaik mysensors nrf52 isn't working with softdevice yet (same as your 'bootloader' here). there might be some conflicts with nrf52 resources (timers etc.). so you may need to open it for reprogramming.
-
For me losing Bluetooth would be a feature: it makes you less likely to be tracked while in stores / smart cities.
-
I turned a ST-Link v2 into a Black Magic Probe using this guide.
The Black Magic Probe creates two virtual serial ports. One to program over, and another one. Can that second one be used to listen to Serial output from the NRF52? If so, how can that be set up?
-
@alowhum Doesn't answer your question, but I use just regular FTDI to listen to the serial output from the nRF5. So, there's always that for you to fall back on.
-
@alowhum I'm using a BMP that I made from a STM32 Blue Pill. The Serial works just fine.
Set a TX pin on your NRF5 in the MyBoardNFR5.h file. Connect it to the RX pin on your BMP. The default pins are TX (PA.2) and RX (PA.3). So if you connect PA.3 on your programmer to the TX pin you select on the NRF5, you should have what you need.
To program, select the lower number serial port.
To see serial output, select the higher number serial port for your serial monitor.
-
@nagelc I am using a ST-Link V2 that I turned into a BMP. So i don't have a RX pin on that. But I do have these pins left:
- RST
- SWIM
So you suppose any of these two pins are now RX?
-
@toyman Looks like a DIY watch, using one of the very small nRF52 modules and a small OLED screen (or maybe ePaper?) would be fairly easy to design and put together.
https://www.aliexpress.com/item/Free-shipping-Latest-Big-time-wearable-devices-DIY-electronic-watch-programmable-watch-FOR-ARDUINO/32309696848.html?spm=2114.search0104.3.43.6855283fBpRmHN&ws_ab_test=searchweb0_0,searchweb201602_5_10152_10065_10151_5711320_10344_10068_10130_10324_10342_10547_10325_10343_10546_10340_10341_10548_10698_10545_10697_10696_10084_5722520_10083_10618_10307_5711220_10059_5722620_5722920_308_5722720_5722820_100031_10103_441_10624_10623_10622_10621_10620-10152,searchweb201603_25,ppcSwitch_5&algo_expid=e4147df1-7362-4700-8575-4d5fa986cd9a-6&algo_pvid=e4147df1-7362-4700-8575-4d5fa986cd9a&transAbTest=ae803_1&priceBeautifyAB=0Making it aesthetically pleasing is probably much harder! Still, maybe a DIY bridge would tide you over until a more proper watch is available for conversion. Interestingly, it looks like they made their case from stacked pieces of laser cut acrylic.
Unfortunately, theirs is impractically large:
-
@alowhum Reset seems unlikely. Maybe SWIM. You could try it.
If you can follow the trace back to the microprocessor, then you could figure out which pin it is. Then you could change to that pin in the BMP files, recompile, reload . . .. . Not sure it's worth all that experimentation when you can just use an FTDI as @NeverDie does.
-
Is this an alternative programmer or is it STM32 only? https://www.aliexpress.com/store/product/CJMCU-JLINK-Support-for-SWD-s-JLINK-Simplified-Edition-Supports-STM32-SWD-Debugging-3-Wire/1245924_32792177272.html
-
@gohan J-Link is in the list of supported programmers at https://github.com/sandeepmistry/arduino-nRF5 so it should work
-
@alowhum just buy a real Blue Pill (around $2) and convert it into BMP.
Then you''ll get both a programmer and an USB-serial that you can use to get data from NRF52 UART
-
@toyman said in nRF5 Bluetooth action!:
@alowhum just buy a real Blue Pill (around $2) and convert it into BMP.
Then you''ll get both a programmer and an USB-serial that you can use to get data from NRF52 UARTThank you for this idea, I didn't receive my STM32 (got lost somewhere in transit) but I have 2 unused blue pills, I'll try that tomorrow.
"Conversion" process is easy to find: https://medium.com/@paramaggarwal/converting-an-stm32f103-board-to-a-black-magic-probe-c013cf2cc38c
-
Is the main (only?) advantage of the BMP that you have a single USB connection from your PC to your project instead of two (e.g. J-link plus an FTDI)? Or is there more to it that that?
-
@nca78 I used exactly this guide. Works like a charm.
-
@neverdie for us - yes. For other folks, I think the advantage is the number of targets it supports and the license. Equivalent Segger costs hundreds of $
BTW, Sandeep added BMP support into his core after I raised the issue
-
This post is deleted!
-
@nca78 I have now measured the current consumption of the small bluetooth beacon device (N51822 QFABC0) using your code and the results are encouraging.
With your code I get around 4uA sleep current compared to 800-4000uA with my old code
Measurements done with an Micro (nano) ampere meter (double) that has not been calibrated against a reliable meter so do not take the measured values so seriously but more as a comparison.
-
@korttoma I was going to ask you for some news. This is great news as it confirms the problem is solved even with older versions of the chip.
Time to start work on a clean library...PS: I think you will have a reliable measurement with a simple multimeter, as the nrf51 by default is using an internal LDO, whether you feed it with 3.3V or (3.3V - burden voltage) in the end the chip will run at the same 1.8V voltage and use the same current. Of course it won't be the case if you have extra sensors on the board but it's not the case here.
-
@nca78 BTW, HolyIoT makes a similar beacon but nrf52 based. Should be much more energy efficient. The price is about $7
-
I see a lot of nice assembled PCB's on this forum, and just out of curiosity, but do you guys do your own SMT assembly?
I looked at the PCBA options, but just a small batch of 10 PCB's starts somewhere around $140 excluding components.
It would save me I think a lot of work, but on the other hand it feels expensive...My ebyte modules & STM32 programmers are on there way from AliExpress, so no problem in that area.
-
@mars-warrior it depends on quantities of both PCBs and components on the PCBs.
If you have lets say 10 pcbs with 20 components and potentially will have to do it again, the best bet is get a small oven (kitchen type) with PID regulator.
If you just need 2-3 pcbs with 5-6 componets, hot air gun is your choice.
In my current project, I solder ebyte module by hand (very easy) and then LED, resisttors and capacitors with hot air and solder paste.
Looks pretty neat.
-
@toyman Thanx for that info!
Never worked (yet) with a hot air station/pencil.
Found some reviews here: https://wiki.ezvid.com/best-soldering-stations. Both the Kendal 853D and the Ayyue 968+ are stations I can afford to buy. I assume the cheaper ones ($50) are the ones to avoid...
Looking at some youtube vids about this subject, it seems doable, even for a novice like me
Of course, any recomendations about hot air stations are appreciated!
-
-
140$ it is quite expensive compared with a simple small oven
#192 Aldi Hack: Simplify SMD Soldering with a Cheap Aldi Oven. Nothing else – 06:09
— Andreas Spiess
-
@gohan I am not telling you to buy this. Just a direction.
I've created a PID sous vide machine. It's relatively easy project. SMD oven is absolutely the same. All you need is Arduino, thermoprobe and a relay.
-
Quick question: when programming the eByte module (or any module really):
Should I select "reset enable or not? What does that do exactly?
Should I select clock: "Crystal oscillator" for the eByte module?
-
@alowhum "Reset enable" determines whether pin21 acts as a reset pin or not.
-
@alowhum IIRC, the crystal oscillator is only required by Bluetooth. For everything else, the internal resonator is sufficient.
-
Thanks!
I received two new eByte modules. I can't even connect to either one, both with BMP or ST-Link V2. Very strange. I'm going to try not powering them from the USB stick but from a second 3.3v source.
-
@alowhum did you manage to flash them?
-
@toyman No. I don't understand what's going on, as I was able to flash one succesfully before. I did find [this a bit unnerving].(https://devzone.nordicsemi.com/f/nordic-q-a/19943/nrf52832-unable-to-connect-to-the-target).
Could it be that the EByte chips need the DCDC stuff before they can be connected to? Or that the exact moment on power-on (reset) matters?
One thing I have found is that I had installed OpenOCD on my laptop to turn a ST-Link V2 into a Black Magic Probe. That version of OpenOCD was overruling the hacked version that Sandeep Mistry had created for the NRF5.
But even with that removed, the problem remains this:
"TARGET: nrf52.cpu - Not halted".
Apparently this is a sign that the chips are protected. I was able to remove that protection before (by selecting "Burn Bootloader"), but it doesn't work now.
-
@alowhum said in nRF5 Bluetooth action!:
Could it be that the EByte chips need the DCDC stuff before they can be connected to?
No.
-
@alowhum have you tried the menu item to write softdevice ? If I remember well it will unlock the chip and after that you will be allowed to write code to it.
-
Hey,somehow I cant change the pins on my Ebyte module. Im trying to test with MockMysensors.
I want te TX set to pin nr. P0.06I changed: MyBoardNRF.h and included nrf.h#define PIN_SERIAL_RX (8)
#define PIN_SERIAL_TX (6)but somehow the TX pin stays P0.25.Can someone point me in the right direction?The node connects to the gateway, so thats also working.Seems like that if you put the MyBoardNRF5 files into the example map and you change some things in that file using the Arduino IDE, it doenst get uploaded. When I changed the MyBoardNRF5 file using Brackets it working as intended.
-
@Nca78 Thanks, but it didn't work either
Some notes from my adventures with the eByte module:
I've been playing with OpenOCD and the ST-Link v2. The ST-Link V2 that I turned into a Black Magic Probe doesn't see the modules.
I went into the Arduino's folder that has OpenOCD, created .cfg file, and then:
./openocd -d2 -f nrf52832.cfg
This started the OpenOCD server. Then I opened another terminal window and did
telnet localhost 4444
Now I could manually issue some OpenOCD commands. The goal was to do a manual mass erase.
Some OpenOCD commands and their output:
flash probe 0 c Unknown device (HWID 0x00000000)
> flash banks #0 : nrf52.flash (nrf51) at 0x00000000, size 0x00000000, buswidth 1, chipwidth 1 #1 : nrf52.uicr (nrf51) at 0x10001000, size 0x00000000, buswidth 1, chipwidth 1
> flash probe 1 Unknown device (HWID 0x00000000) flash 'nrf51' found at 0x10001000
> nrf51 mass_erase 0 Target not halted
This command actually resulted in OpenOCD ballooning to 8Gb in ram. Then after 5 minutes of seemingly being busy, I got the 'target not halted' command.
> flash info 1 Unknown device (HWID 0x00000000) #1 : nrf51 at 0x10001000, size 0x00000100, buswidth 1, chipwidth 1 # 0: 0x00000000 (0x100 0kB) not protected Target not halted error retrieving flash info
Here is says "target not protected".
> nrf52.cpu curstate reset
Weird: the processor says it is in reset state? Could it be that it is not so much protected, but that it is constantly being reset? But then why is this with all the chips?
Once the OpenOCD server is running I also tried getting into the chip with
telnet localhost 3333
But then I get "Error: attempted 'gdb' connection rejected"
The OpenOCD documentation mentions the chip protection:
Flash Driver:Â nrf5
All members of the nRF51 microcontroller families from Nordic Semiconductor include internal flash and use ARM Cortex-M0 core. Also, the nRF52832 microcontroller from Nordic Semiconductor, which include internal flash and use an ARM Cortex-M4F core.
flash bank $_FLASHNAME nrf5 0 0x00000000 0 0 $_TARGETNAME
Some nrf5-specific commands are defined:
Command:Â nrf5 mass_erase
Erases the contents of the code memory and user information configuration registers as well. It must be noted that this command works only for chips that do not have factory pre-programmed region 0 code.
http://www.openocd.org/doc/html/Flash-Commands.htmlI also got out my voltmeter. Pin 21 and pin 25 have 3v on them, the rest don't.
-
I have the same problem with brand news ebyte modeules.
Here are my openocd logs:
Open On-Chip Debugger 0.10.0-dev-gdc53227 (2016-04-09-13:45)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
debug_level: 2
0x4000
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 10000 kHz
Info : Unable to match requested speed 10000 kHz, using 4000 kHz
Info : Unable to match requested speed 10000 kHz, using 4000 kHz
Info : clock speed 4000 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.241270
Info : nrf52.cpu: hardware has 0 breakpoints, 2 watchpoints
Error: timed out while waiting for target halted
TARGET: nrf52.cpu - Not halted
in procedure 'program'
in procedure 'reset' called at file "embedded:startup.tcl", line 478
in procedure 'ocd_bouncer'embedded:startup.tcl:454: Error: ** Unable to reset target **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 479
at file "embedded:startup.tcl", line 454
wybrany port szeregowy at file "embedded:startup.tcl", line 454
nie istnieje albo Twoja płytka nie jest podłączona
-
@alowhum I'm not in sync with the whole thread , but I had similar issues when I had an FTDI adapter connected with @NeverDie 's breakout.
As soon as I disconnected the DTR (reset) line the thing started to work!Not sure if this is related to your issue, but it's worth a try.
-
@alowhum I intentionally asked you because I know the problem exists.
You need to erase the chip via Jlink Commander. Neither nrfjprog nor anything alse will work (AFAIK)
Actually, it was @NeverDie who found it in the beginning of his quest with nrf52. "The thing that started it all" (c)
-
another method (although I haven't tried it with Ebyte) is to use BMP with GDB and issue a "erase mass" command
-
Is there a way to enhance the sending performance of the Ebyte units?
I got a gateway that's sitting upstairs when I connect an Ebyte module I must be right underneath the gateway to let it receive packages.
When I do exactly the same same thing with an NRF52832-DK It doesn't matter where I'm standing, every message is received by the gateway.
-
@omemanti said in nRF5 Bluetooth action!:
Is there a way to enhance the sending performance of the Ebyte units?
@omemanti Maybe by using a properly tuned external antenna? At least for the built-in antenna's, the Fanstel modules seem to have more effective Tx reach than the Ebyte modules do. That's a major reason for my switch from the Ebyte's to the Fanstel's.
-
@neverdie, I did some digging and cut a part of my PCB that was grounded. range drastically increased, guess I need to order a new prototype
-
@omemanti Ah, that makes sense. That's why on my PCB's I have the antenna portion of the module hanging over the edge of the PCB into empty space.
-
@neverdie said in nRF5 Bluetooth action!:
, that makes sense. That's why on my PCB's I have the antenna portion of the module hanging over the edge of the PCB into e
yeah, next one will be a big hole in the middle, lets see how that will work out..
-
@omemanti said in nRF5 Bluetooth action!:
@neverdie said in nRF5 Bluetooth action!:
, that makes sense. That's why on my PCB's I have the antenna portion of the module hanging over the edge of the PCB into e
yeah, next one will be a big hole in the middle, lets see how that will work out..
Interesting board !
But module in the middle is a bad idea, even with a big hole below the antenna it will affect performance to still have some PCB around
For example here is an extract of the Fanstel BT832 module datasheet. It's not the same antenna design but it show having the antenna sticking out is the best solution, else you should but as close as possible to the edge and of course keep ground plane and traces as far as possible.
-
@nca78 I'm trying to create a node that fits inside a standard wallsocket. (I'll post it when it's done) it got a motion and moisture sensor.
For the next version I'm moving the module more to the outside but I need to take the screwholes into account.
The groundplane I used filled the entire PCB, next one will have less ground around the antenna or even holes.It's designed to hold 3 AA batteries to have a couple years of service.
But cutting away that spot around the antenna gave me reception throughout the entire house
-
Hi I managed to clear the access protection.
I connected ebyte module directly to raspberry pi.
I used this guide http://hivetool.org/w/index.php?title=BMD301 with little modifications
Compiled openocd - current version - 7b94ae9e520877e7f2341b48b3bd0c0d1ca8a14b
Added chip definition - I don't know if it is needed, I can check that - I have more modules to unlock
diff --git a/src/flash/nor/nrf5.c b/src/flash/nor/nrf5.c index 31dd5aae..e01d7ddf 100644 --- a/src/flash/nor/nrf5.c +++ b/src/flash/nor/nrf5.c @@ -204,6 +204,7 @@ static const struct nrf5_device_spec nrf5_known_devices_table[] = { /* nRF52832 Devices */ NRF5_DEVICE_DEF(0x00C7, "52832", "QFAA", "B0", 512), + NRF5_DEVICE_DEF(0x00C7, "52832", "QFN48", "B00", 512), }; static int nrf5_bank_is_probed(struct flash_bank *bank)
Started openocd:
openocd -f interface/raspberrypi-native.cfg -c "transport select swd; set WORKAREASIZE 0" -f target/nrf52.cfg
Connected with telnet to port 4444
Commands:nrf52.dap apreg 1 0x0c nrf52.dap apreg 1 0x04 0x01 reset
I tried also with st-link but I think it doesn't support dap commands? Can anyone confirm that?
After clearing access protection I am able to successfully flash chip with st-link.
Now it shows in logs:
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Before it was:
Info : nrf52.cpu: hardware has 0 breakpoints, 2 watchpoints
Good luck with unlocking your modules:)
-
@maciekczwa said in nRF5 Bluetooth action!:
nrf52.dap apreg 1 0x0c
Thanks for the tip! Unfortunately ST-Link V2 gives:
> nrf52.dap apreg 1 0x0c invalid command name "nrf52.dap"
(same with just "dap", which I had tried earlier).
-
@omemanti That PIR sensor lens sure has a small footprint. I'll be interested to hear how well it performs and whether you like it or not.
-
@neverdie it's the AM612, and in the little tests I did so far, it did great.
-
@maciekczwa If you could share a guide to unlocking these devices, I would be very grateful. I'm have a bit of trouble still. I create an JLink device form an STM32. But even that gives the same general error on all my modules.
nrfjprog --recover ERROR: JLinkARM DLL reported an error. Try again. If error condition ERROR: persists, run the same command again with argument --log, contact Nordic ERROR: Semiconductor and provide the generated log.log file to them.
I tried lots of DLL versions, and a new version of nrfjprog.. no luck.
nrfjprog --recover --log nrfjprog verion 9.7.0 -------------------------------------------------------------------------------- FUNCTION: open_dll. FUNCTION: open_dll. FUNCTION: enum_emu_snr. FUNCTION: enum_emu_snr. FUNCTION: enum_emu_snr. FUNCTION: enum_emu_snr. FUNCTION: connect_to_emu_with_snr. FUNCTION: connect_to_emu_with_snr. FUNCTION: connect_to_emu_without_snr. FUNCTION: enum_emu_snr. Device "NRF52832_XXAA" selected. FUNCTION: read_connected_emu_snr. FUNCTION: read_connected_emu_snr. FUNCTION: read_device_family. FUNCTION: read_device_family. JLinkARM.dll CORESIGHT_WriteAPDPReg returned error -1. JLinkARM.dll CORESIGHT_WriteAPDPReg returned error -102. FUNCTION: close_dll. FUNCTION: close_dll.
-
@alowhum, you seem to need Jlink Commander:
@toyman said in nRF5 Bluetooth action!:
@alowhum I intentionally asked you because I know the problem exists.
You need to erase the chip via Jlink Commander. Neither nrfjprog nor anything alse will work (AFAIK)
Actually, it was @NeverDie who found it in the beginning of his quest with nrf52. "The thing that started it all" (c)Furthermore, It would be nice to have a small step-by-step guide to unlock and then program the ebyte module.
@Omemanti and @NeverDie are using these modules, so should be able to write something up that works for other ppl(My ebyte modules are still on their way)
-
For uploading code onto the Ebyte modules I use an ST-Link V2 (2 dollar USB modules).
-
Install the USB-Driver using Zadig
-
Connect the DIO, CLK VCC, and GND.
For testing purposes, I soldered just the tips of some Dupont cables to the Ebyte module and put the female parts on the ST-link. -
The first time I want to upload code, I first "burn the bootloader" (Tools => burn Bootloader) (https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/386)
This will give an error.
After that, you should be able to upload sketches.
-
-
@omemanti said in nRF5 Bluetooth action!:
- The first time I want to upload code, I first "burn the bootloader" (Tools => burn Bootloader) (https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/386)
This will give an error.
After that, you should be able to upload sketches.
That's what I suggested earlier but it seems it didn't work. But I don't remember if it was with an stlink.
- The first time I want to upload code, I first "burn the bootloader" (Tools => burn Bootloader) (https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/386)
-
@alowhum
maybe a very stupid question, but did you check all the wires and after that if your computer uses the right drivers.I took me quite a while to figure this out myself. Especially the driver part messes things up. Errors everywhere that referred to different problems, but after I used Zadig they all disappeared.
-
@mars-warrior said in nRF5 Bluetooth action!:
@Omemanti and @NeverDie are using these modules, so should be able to write something up that works for other ppl
As I've said many times previoiusly, I use the nRF52 DK to program external modules, and it's what I recommend for noobs because it's relatively hassle free. If you're able to use the $2 st-link v2 programmer then great, my hat's off to you. If not, I recommend the nRF52 DK rather than get frustrated and give up.
-
@neverdie said in nRF5 Bluetooth action!:
nRF52 DK
Which hardware programmer do you use with that?
I find many of these software packages, like Segger's JLink stuff, are made for Windows (I'm on a mac).
-
@alowhum you can still install windows on it
-
@alowhum by programmer you mean in something like the Arduino ide? That's what I use ( I both use the nrf52dk =>j-link aswell the st-link v2 => st-link)
-
@Omemanti I didn't realise the nRF52-DK was a hardware device. I thought it was a software program.
On the picture you provided (thanks!), are pin 6 and 8 connected to a serial port to read what's going on? Your ground is connected in a different place than mine (I connect it next to the VCC pin). I suspect both those side-pins near the antenna, at the top, where you have soldered something, are ground too, right?
-
@alowhum said in nRF5 Bluetooth action!:
@Omemanti I didn't realise the nRF52-DK was a hardware device. I thought it was a software program.
The nrf52 dev kit= > NRF52 Dev kit
To connect the DK to a module :
DK Ebyte module
GND(detect) => GND
SWDIO => SWDIO
SWDCLK => SWCLK
VTG => 3,3V
3,3V => 3,3V
GND =>GNDselect J-link and there you go.
On the picture you provided (thanks!), are pin 6 and 8 connected to a serial port to read what's going on?
I used Pin 6 and 8 to connect to a FTDI to read out the serial. Since you can tell the sketch where to put the RX and TX I just connected them to 6 & 8.
Your ground is connected in a different place than mine (I connect it next to the VCC pin).
the Ebyte module has multiple GND connections, I messed the one next to the VCC up so I connected them next to the antenna. Just because I was easy
I suspect both those side-pins near the antenna, at the top, where you have soldered something, are ground too, right?
Indeed!
-
JLinkExe gives me this:
WARNING: RESET (pin 15) high, but should be low. Please check target hardware.
I already had some signs these EByte modules have a reset issue. As it they are constantly being reset. This points to that again. hmm.
-
Hey, sorry, I'm not familiar with your error messages.
Can you please sum everything up what you did so far and what your setup looks like (pic)
- Drivers
- Libraries
- what software you use
- Number of modules you tested
- etc
just to retrace your steps ( It might be useful to post it in a separate topic to keep this one cleaner ) => https://forum.mysensors.org/category/5/troubleshooting
-
For those interested, NRF52840 is already available on AliExpress from HolyIOT, it's the revision 1 of the chip, too bad they put a chip antenna
[Edit] They also have the most compact NRF24 compatible gateway ever, for 10$
https://www.aliexpress.com/store/product/Nordic-nRF52832-BLE-4-0-4-2-5-0-USB-UART-BLE-dongle-for-computer/420533_32862480389.html