Jump to content
43oh

Unexpected #include <Wire.h> issue with Energia for Stellaris


Recommended Posts

I ran into an unexpected issue when testing my BMP085 library, originally developed on MSP430, with a Stellaris LaunchPad:

 

When I include of Wire.h from my library's header file, it is not found by the compiler.

fatal error: Wire.h: No such file or directory

A bit of research brought me to this thread, which indicates that Arduino does not expect/support <Wire.h> to be included inside libraries.

http://arduino.cc/forum/index.php?PHPSESSID=0799edeb50822ca579644d323baeec5e&topic=37682.msg278141#msg278141

 

And yes, the problem goes away if I include Wire.h in the example instead of my library.

 

Upon looking into the Energia source code, I notice that the msp430 core directory contains Wire.h and Wire.cpp, unlike lm4f and arduino cores.

 

Is this intentional? Looks like an incompatibility, i.e. bug to me.

 

And on a related note, what is best practice for Wire.begin()? Is it recommended to put that within a library or should I leave it to the developer of the sketch to do that?

Link to post
Share on other sites

This has been an issue that has been discussed at length on the Arduino forums. It boils down to that if a Library uses Wire then the Sketch will have to include Wire.h and not the library as the library does not know where to find it. This has to do with how things get setup during the build phase.

 

The reason why MSP430 has Wire.c/h and ultimately twi.c/h in the core is because USCI shares the TX/RX interrupt between I2C and UART. See usci_isr_handler.c for details. 

 

I wouldn't call it a bug as including Wire.h in a Sketch still works. Libraries in this case BMP085 should not make the assumption that including Wire.h is going to work as it for sure does not work on Arduino and Energia LM4F.

Link to post
Share on other sites

Ok, I will move the #include <Wire.h> and Wire.begin() from my library into the example to ensure compatibility.

 

As Wire.h and Wire.cpp seem not to be referenced by usci_isr_handler.c and twi.c, any non-obvious dependencies for not moving those two files to the msp430/libraries/Wire folder?

 

Still works in my quick test, with the compiling behavior consistent with what's observed for Stellaris. (caveat: I don't (knowingly) mess with interrupts)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...