bluzDK / bluzDK-firmware

Firmware for the bluz development kit
Other
15 stars 15 forks source link

Wire.isEnabled() always returns true #26

Closed telliottosceola closed 8 years ago

telliottosceola commented 8 years ago

Noticed this during library development for I2C device. Cannot check status of Wire like this: if(!Wire.isEnabled()){ Wire.begin(); } My library never starts Wire because Wire.isEnabled always returns true even when Wire is not ready.

eely22 commented 8 years ago

Hmm, looking at the code this should work. You can see here the function is checking the register: https://github.com/bluzDK/bluzDK-firmware/blob/develop/hal/src/bluz/i2c_hal.c#L136

Are you attempting to use SPI at the same time? They share a register so this could cause issues.

I will verify later this evening

telliottosceola commented 8 years ago

Not using SPI. However same test code does run on a Photon no issue. I am getting a status return of 3 when calling Wire.endTransmission which seems to be due to the port not being ready for read/write operations. I only start Wire if isEnabled returns false.

eely22 commented 8 years ago

There was indeed an issue with this, however the symptoms you describe seem a little off. Basically, we used a flag to determine if Wire was initialized, if it wasn't then we wouldn't initialize it in the first place. So I could enable Wire, then disable it, and never re-enable it again. This is now fixed.

I tested with the following code:

void setup()
{
    Serial1.begin(38400);
    Serial1.println("Welcome!");
}
void loop()
{
    if (Wire.isEnabled()) {
        Serial1.println("Wire is on!");
    } else {
        Serial1.println("Wire is off!");
    }
    Wire.begin();
    delay(4000);
    if (Wire.isEnabled()) {
        Serial1.println("Wire is on!");
    } else {
        Serial1.println("Wire is off!");
    }
    Wire.end();
}

With this, I received the expected output on Serial1 of: Wire is on! Wire is off!

Every 4 seconds. Could you re-test with the latest develop branch and verify this fixes the issue? If you are still seeing it, can you post more detailed code to reproduce the issue? I will leave open for now

telliottosceola commented 8 years ago

I did a pull on the latest for the devlop branch. I saw your fix in the pull request for Wire. However this is what I get in my serial output:

Wire is on!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
Wire is off!
This is the code in my application.cpp file:
#include "application.h"
void setup(){
    Serial1.begin(115200);
}

void loop(){
    if (Wire.isEnabled()) {
        Serial1.println("Wire is on!");
    } else {
        Serial1.println("Wire is off!");
    }
    Wire.begin();
    delay(4000);
    if (Wire.isEnabled()) {
        Serial1.println("Wire is on!");
    } else {
        Serial1.println("Wire is off!");
    }
    Wire.end();
}
eely22 commented 8 years ago

Did you happen to update the system part on your bluz board after you did the pull and rebuild?

telliottosceola commented 8 years ago

You are absolutely right Eric. Flashed system part, working as expected now.
Thanks