Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - andrey_dung

Pages: [1]
1
BLE and Low Level Development / I2C read inside timer interrupt?
« on: June 03, 2017, 10:44:41 AM »
It seems that I2C read is not allowed in the interrupt handler of RFduino. Is there any solution to this?

Code: [Select]
#include <Wire.h>
#include <Adafruit_VCNL4010.h>
#include <SPI.h>
#include <SD.h>
#include <RFduinoBLE.h>


// Proximity sensor
Adafruit_VCNL4010 vcnl;
uint16_t proximity;
uint16_t ambientLight;

char buffer[12];

#define CHIPSELECT 2
uint_fast16_t volatile number_of_ms = 2;     // ms

void timer_config(void)
{
  NRF_TIMER2->TASKS_STOP = 1;  // Stop timer
  NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;  // taken from Nordic dev zone
  NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
  NRF_TIMER2->PRESCALER = 9;  // 32us resolution
  NRF_TIMER2->TASKS_CLEAR = 1; // Clear timer
  // With 32 us ticks, we need to multiply by 31.25 to get milliseconds
  NRF_TIMER2->CC[0] = number_of_ms * 31;
  NRF_TIMER2->CC[0] += number_of_ms / 4;
  NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;  // taken from Nordic dev zone
  NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
  attachInterrupt(TIMER2_IRQn, TIMER2_Interrupt);    // also used in variant.cpp to configure the RTC1
  NRF_TIMER2->TASKS_START = 1;  // Start TIMER
}

bool transmitFlag = 0;

void setup() { 
  // BLE stack
  RFduinoBLE.deviceName = "andrey";
  RFduinoBLE.begin();

  // start SD card
  pinMode(CHIPSELECT, OUTPUT);
  if (!SD.begin(CHIPSELECT)) {
    return;
  }

  timer_config();

  if (!vcnl.begin()) {
    return;
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  if (transmitFlag) {
    transmitFlag = 0;
   
    proximity = vcnl.readProximity();
    ambientLight = vcnl.readAmbient();

    File myFile = SD.open("datafile.csv",  FILE_WRITE);
    if (myFile) {
      myFile.print(buffer);
      myFile.close();
    }
  }   
}

void TIMER2_Interrupt(void) {
  if (NRF_TIMER2->EVENTS_COMPARE[0] != 0) {
    transmitFlag = 1;
//    proximity = vcnl.readProximity();
//    ambientLight = vcnl.readAmbient();

    sprintf(buffer, "%5d5d\n", 12, proximity, ambientLight);
   
    NRF_TIMER2->EVENTS_COMPARE[0] = 0;
  }
}

As soon as I uncommented vcnl.readProximity or vcnl.readAmbient inside the interrupt handler, BLE doesn't work.

How could I resolve this?

2
Support / Clock stretching I2C with RFduino
« on: May 19, 2017, 12:36:04 AM »
How do I implement clock stretching with I2C in RFduino? It seems that the RFduino Wire library does not support that?

3
Support / Write data to SD card with RFduino
« on: May 06, 2017, 07:07:02 PM »
Are there any examples of high frequency data logging to SD card with RFduino (> 100Hz)? I need to be able to write in multiple blocks. Any suggestion are appreciated.

I have been trying using SdFat library, but it's not compatible with RFduino (there are compilation error, which I think that SPI.h from RFduino does not fit with Sdfat). Any way to fix this?


UPDATE:

I managed to make SD library work with RFduino (Arduino 1.6.5, RFduino 2.3.2 and some old version of SD library from arduino 1.5.6). However I still need to use Sdfat library to reduce number of IOs.

What is the difference between libraries

inside Arduino.app: Arduino.app/Contents/Java/libraries;

/Arduino15/packages/RFduino/hardware/RFduino/2.3.2/libraries

and Documents/Arduino/libraries?

4
Support / RFduino.send on demand, not streaming
« on: May 02, 2017, 08:52:09 PM »
I am building a low power device based on RFduino. There is an app to monitor the device, which every hour (and by demand of users when click a button) asks for some data from RFduino.

I don't want to put RFduino.send function in the for loop, since it will continuously streaming data when RFduino is connected to the app, and that will waste battery.

On the other hand, I could put RFduino.send whenever the device connects to the smartphone. However this way to get new data, the app would have to disconnect and connect again.

Code: [Select]
void RFduinoBLE_onConnect() {
  RFduinoBLE.send(data);
}

What is the best way to implement on demand data sending in RFduino?

Pages: [1]