Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire.begin() affecting clock based functions #82

Open
dbradby opened this issue Oct 26, 2016 · 5 comments
Open

Wire.begin() affecting clock based functions #82

dbradby opened this issue Oct 26, 2016 · 5 comments

Comments

@dbradby
Copy link

dbradby commented Oct 26, 2016

When I used Wire.begin in my setup() method, both delay(...) and millis() don't work correctly.

delay() blocks forever and millis() returns 0

If I comment out the Wire.begin() both those functions work again. Small sample code below ...


#include <Wire.h>

unsigned long myTime;

void setup() {
  Serial.begin(9600);

  Serial.println("starting setup");
  pinMode(13, OUTPUT);
  Wire.begin();
  Serial.println("setup complete");
}

void loop() {
  Serial.println("start loop");
  digitalWrite(13, HIGH);
  delay(1000);              
  digitalWrite(13, LOW);   
  delay(1000);
  myTime = millis();
  Serial.println(myTime);
  Serial.println("end loop");              
}
@zoujixing
Copy link

Thanks for your point, I will test this.

@zoujixing
Copy link

I have test the sample code, but I don't meet the problem.It works fine!
Here is some log:

start loop
349059
end loop
start loop
351088
end loop
start loop
353118
end loop
start loop
355148
end loop
start loop
357178
end loop

@dbradby
Copy link
Author

dbradby commented Nov 19, 2016

Thanks for confirming that it can work. I went back and looked at the board I was selecting. I previously had selected "BLE Nano v1.5" so instead I tried RBL nRF51822 v1.5) and it works!

What is the difference between the two boards and why should I select one over the other?

@dbradby dbradby closed this as completed Nov 19, 2016
@dbradby
Copy link
Author

dbradby commented Nov 20, 2016

So I dug a little deeper myself and I can see the difference between the two is PIN assignments.

The RBL nRF51822 profile uses D14 and D15 by default
BLE Nano uses D2 and D3 which is what I want to be using.
When I switch to using the D2 and D3 pins then I see the delay and millis methods stop working and blocking.

If I had to guess, it looks like the SCL assignment is hijacking the clock from the general MCU functions.

@dbradby dbradby reopened this Nov 20, 2016
@zoujixing
Copy link

So your board is RBL nRF51288 V1.5. I use the following code to test:

#include <Wire.h>

unsigned long myTime;

void setup() {
  Serial.begin(9600);

  Serial.println("starting setup");
  pinMode(13, OUTPUT);
  Wire.begin(D3, D2, TWI_FREQUENCY_100K);
  Serial.println("setup complete");
}

void loop() {
  Serial.println("start loop");
  digitalWrite(13, HIGH);
  delay(1000);              
  digitalWrite(13, LOW);   
  delay(1000);
  myTime = millis();
  Serial.println(myTime);
  Serial.println("end loop");              
}

I have used the D3/D2 for SCL/SDA, I still didn't meet the problem.It works fine!
Can you tell me what you have done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants