difference between wire twowire

Post here first, or if you can't find a relevant section!
aster
Posts: 119
Joined: Thu Mar 30, 2017 2:41 pm
Location: bella italy
Contact:

difference between wire twowire

Post by aster » Tue Dec 05, 2017 12:59 am

hello,
i am using a library which uses the TwoWire instance instead of Wire, which is exactly the difference?
from the repo i can see that twoWire is used inside softWire but i don't think that theTwoWire inside the library would like to use a software emulation
that lib has been made firstly for teensy boards, is it possible that there TwoWire refers to the hardware i2c?

stevestrong
Posts: 1973
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: difference between wire twowire

Post by stevestrong » Tue Dec 05, 2017 9:46 am

The F103 Wire lib now includes the hardware I2C interface.

Code: Select all

#include <Wire.h>
...
HardWire bus;
If you want to use the software I2C, you need to do:

Code: Select all

#include <SoftWire.h>
...
TwoWire bus;

User avatar
RogerClark
Posts: 7552
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: difference between wire twowire

Post by RogerClark » Tue Dec 05, 2017 10:03 am

Just to elaborate on what Steve said

TwoWire is Arduino's internal class name for the Wire class

i.e Wire is an instance of TwoWire on AVR and ARM Arduino boards

In the LibMaple core, there are 2 implementations of I2C, HardWire and SoftWire

I guess for greater compatibility then perhaps we should rename the HardWire class to TwoWire, but I'm not sure why that library needs to create its own instance of the I2C class

stevestrong
Posts: 1973
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: difference between wire twowire

Post by stevestrong » Tue Dec 05, 2017 10:42 am

RogerClark wrote:
Tue Dec 05, 2017 10:03 am
... but I'm not sure why that library needs to create its own instance of the I2C class
It makes sense because this way you can configure to use the interface you want without changing the library.

User avatar
RogerClark
Posts: 7552
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: difference between wire twowire

Post by RogerClark » Tue Dec 05, 2017 10:51 am

Steve

Yes. I agree


Unfortunately this means , I must change the Hardwire class name to TwoWire :-(

I'll need to try it and see what happens

It will break anything which references Hardwire

aster
Posts: 119
Joined: Thu Mar 30, 2017 2:41 pm
Location: bella italy
Contact:

Re: difference between wire twowire

Post by aster » Tue Dec 05, 2017 12:34 pm

RogerClark wrote:
Tue Dec 05, 2017 10:03 am
I guess for greater compatibility then perhaps we should rename the HardWire class to TwoWire
Wow so my guesses about twowire were actually corrects

I think that following straigh forward the arduino API would be the best practise. The library i posted in the first message works on arduino boards, teensy boards and also here, isn t this magic?

If you don t have time i will fork and then open a pull request (hoping to do all correctly)

stevestrong
Posts: 1973
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: difference between wire twowire

Post by stevestrong » Tue Dec 05, 2017 1:48 pm

We could simply rename HardWire to TwoWire, and the old TwoWire to SoftWire.
And define HardWire to TwoWire.

User avatar
mrburnette
Posts: 2060
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: difference between wire twowire

Post by mrburnette » Tue Dec 05, 2017 3:48 pm

After being this way for years... I vote NO to changing names. If it were important, we would have done it back with the libmaple port effort to Arduino 1.5.

I think it is too late to worry about such things. If it is not documented in the WiKi, it should be. That should be enough.

Ray

UPDATE:

I have decided that I really don't care (anymore.)

Because there are constant forces pressing to change "this" or change "that" and I might as well accept that no one really cares about how or why things are the way they are ... folks just want what they want. Fortunately, I am a unique member and can do what the heck I want locally and I do not rely upon the forum or the STM32duino github cores for my own homebrew. Lastly, I'm tired... it is rare that I use the STM32F103 anymore... newer boards, more SRAM and more flash at the same or lower price-point of the Baite Maple Mini of 3 years ago. It is good to be eclectic.

aster
Posts: 119
Joined: Thu Mar 30, 2017 2:41 pm
Location: bella italy
Contact:

Re: difference between wire twowire

Post by aster » Tue Dec 05, 2017 4:59 pm

So if i am not wrong:

WireBase is the actual library which do the i2c stuffs (in arduino is twi)
Wire is exactly the same as Arduino's Wire

Ray, i am just an hobbiest so i am the last person who could take word over a programming problem but the arduino core is powerful, it s not anymore true that arduino = avr, now arduino is a simpler interface to use many different architectures

Arduino will continue to exist (i am not sure about CMSIS, HAL or others) and their api will become bigger and with the time more and more hardware will use it. At some point in the future we will change it, why don t do it today?

User avatar
RogerClark
Posts: 7552
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: difference between wire twowire

Post by RogerClark » Tue Dec 05, 2017 7:49 pm

i have not checked or tried this, but we may just be able to add

#define TwoWire Hardwire

in Wire.h

Post Reply