[Sloeber] Wire vs. HWire on I2C2 (I2C1) - Wire.h

LibMaple (The core that Roger's repo uses)
Post Reply
User avatar
Pito
Posts: 1498
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

[Sloeber] Wire vs. HWire on I2C2 (I2C1) - Wire.h

Post by Pito » Mon Sep 11, 2017 8:56 am

I am trying to use an ADS1110 library https://github.com/nadavmatalon/ADS1110 I found with BPill (under libmaple F1 latest).
The original works with "Wire.h" library.
I want to use HW I2C fastest on I2C2.
I've spent a night playing with it, with no success.. :?

I've tried so far:

1. Using latest libmaple F1 (there is the Wire library, it does not contain HardWire.h)
2. I include "Wire.h" in the sketch, and/or in ADS1110.h and and/or in ADS1110.cpp
3. With this (and replaced all Wire.xx with HWire.xx in the library and elsewhere) I get "'HWire' was not declared in this scope" errors

Code: Select all

#include "Arduino.h"
#include "Wire.h"
// HardWire HWire(2, I2C_FAST_MODE); // I2C2
#include "ADS1110.h"
HardWire HWire(2, I2C_FAST_MODE); // I2C2
..
4. With this (and replaced all HWire.xx with Wire.xx in the library and elsewhere)

Code: Select all

HardWire Wire(2, I2C_FAST_MODE); // I2C2
I get "..STM32F1\libraries\Wire/Wire.cpp:58: multiple definition of `Wire' " error.

How to proceed in order to use (or modify) a library for HW I2C2, plz?
Last edited by Pito on Mon Sep 11, 2017 10:56 am, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

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

Re: Wire vs. HardWire on I2C2 (I2C1)

Post by RogerClark » Mon Sep 11, 2017 10:07 am

Wire is now Hardwire

This was discussed about a month ago, and the consensus was to change Wire to = HardWire

The old "Wire" is now SoftWire

User avatar
Pito
Posts: 1498
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Wire vs. HardWire on I2C2 (I2C1)

Post by Pito » Mon Sep 11, 2017 10:18 am

Ok, so I include Wire.h, and do

Code: Select all

HardWire HWire(2, I2C_FAST_MODE); // I2C2
and I have to rename the Wire.xx functions in ADS1110 library to HWire.xx.
Is that correct?

Update: it only compiles (and works) here (Sloeber) when I set as above in mysketch.ino and in the ADS1110.cpp I do

Code: Select all

#define Wire HWire
#include "ADS1110.h"
ADS1110.h includes Wire.h
:? :?
When I replace Wire.xx with HWire.xx manually in the ADS1110.cpp it shows error "HWire was not declared..".
:shock:

To recap:
mysketch.ino :

Code: Select all

#include "Arduino.h"
#include "ADS1110.h"
HardWire HWire(2, I2C_FAST_MODE); // I2C2
ADS1110.h :

Code: Select all

#ifndef ADS1110_h
#define ADS1110_h
#include "Wire.h"
ADS1110.cpp :

Code: Select all

#define Wire HWire
#include "ADS1110.h"
Frankly, I do not understand that construct which works here.. :?
But why we cannot simply do

Code: Select all

HardWire Wire(2, I2C_FAST_MODE); // I2C2
?
Update: because of this in Wire.cpp

Code: Select all

HardWire Wire(1);
?
Pukao Hats Cleaning Services Ltd.

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

Re: Wire vs. HWire on I2C2 (I2C1) - Wire.h

Post by stevestrong » Mon Sep 11, 2017 11:35 am

Sloeber again... :roll:

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

Re: [Sloeber] Wire vs. HWire on I2C2 (I2C1) - Wire.h

Post by RogerClark » Mon Sep 11, 2017 10:21 pm

@pito

The HardWire object / class no longer exists

The code was copied into the Wire class

So Wire = HardWire

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest