Wire now uses Hardware I2C by default

Information on the latest releases
User avatar
RogerClark
Posts: 7422
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Wire now uses Hardware I2C by default

Post by RogerClark » Tue Aug 01, 2017 7:06 am

After conducting a pseudo poll over the last few days, I've changed the default implementation of Wire to use hardware I2C instead of software.

The software I2C has been retained but has been named Softwire.

The files called HardWire.* have been renamed to Wire and various header references changed etc

I've added an example so that Wire, Hardwire and Softwire now all have examples

This change has been tested with a STM VL53L0X device connected to a Maple mini and both the VL53L0X demo and the I2C scanner worked fine using hardware I2C

I suspect a few people may initially have issues with this change, but we'll need to address those issues when and if they arise

peekay123
Posts: 18
Joined: Tue Nov 08, 2016 8:39 pm

Re: Wire now uses Hardware I2C by default

Post by peekay123 » Wed Aug 02, 2017 1:24 pm

@RogerClark, made the move and everything works well. Makes more sense to have hardware libs as defaults, following the typical Arduino approach. :D

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

Re: Wire now uses Hardware I2C by default

Post by RogerClark » Wed Aug 02, 2017 10:03 pm

peekay123 wrote:
Wed Aug 02, 2017 1:24 pm
@RogerClark, made the move and everything works well. Makes more sense to have hardware libs as defaults, following the typical Arduino approach. :D
Thanks for letting me know.

WindyYam
Posts: 17
Joined: Mon Aug 07, 2017 2:39 am

Re: Wire now uses Hardware I2C by default

Post by WindyYam » Tue Aug 15, 2017 2:41 am

just curious does it takes any benefit when using hardwire? for what i read it seems block until transfer done, unlike the serial where interrupt based ringbuffer exists

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

Re: Wire now uses Hardware I2C by default

Post by RogerClark » Tue Aug 15, 2017 3:49 am

Timing on the Hardware I2C is supposed to be better.

Its probably possible to DMA to it as well, but its not been implemented.

Software only used to run at 100khz, but I recently reworked it to squeeze it up to just over 400khz, but its highly dependant on the optimisation level in the code, both at 100khz or 400khz.

I asked the community what they wanted, and those that bothered to reply indicated they would prefer hardware, hence why it was changed.

racemaniac
Posts: 617
Joined: Sat Nov 07, 2015 9:09 am

Re: Wire now uses Hardware I2C by default

Post by racemaniac » Tue Aug 15, 2017 6:41 am

RogerClark wrote:
Tue Aug 15, 2017 3:49 am
Timing on the Hardware I2C is supposed to be better.

Its probably possible to DMA to it as well, but its not been implemented.

Software only used to run at 100khz, but I recently reworked it to squeeze it up to just over 400khz, but its highly dependant on the optimisation level in the code, both at 100khz or 400khz.

I asked the community what they wanted, and those that bothered to reply indicated they would prefer hardware, hence why it was changed.
which is then also a possible advantage, not sure if the core currently supports it, but i've been using the hardware i2c up to 1.2Mhz. (i know, way beyond its specs, but it worked well for me :) ).

victor_pv
Posts: 1734
Joined: Mon Apr 27, 2015 12:12 pm

Re: Wire now uses Hardware I2C by default

Post by victor_pv » Tue Aug 15, 2017 1:41 pm

WindyYam wrote:
Tue Aug 15, 2017 2:41 am
just curious does it takes any benefit when using hardwire? for what i read it seems block until transfer done, unlike the serial where interrupt based ringbuffer exists
I just checked and softwire also blocks, and I understand the Arduino wire library also blocks. Given that, what is the disadvantage or using hardwire?

Unlike Serial, the wire library is transaction based. To have arduino compatibility, it needs to return some values on endTransmission() and that would not be possible if it was interrupt driven and returned before completing the transmission, so it has to block.

victor_pv
Posts: 1734
Joined: Mon Apr 27, 2015 12:12 pm

Re: Wire now uses Hardware I2C by default

Post by victor_pv » Tue Aug 15, 2017 1:43 pm

racemaniac wrote:
Tue Aug 15, 2017 6:41 am
RogerClark wrote:
Tue Aug 15, 2017 3:49 am
Timing on the Hardware I2C is supposed to be better.

Its probably possible to DMA to it as well, but its not been implemented.

Software only used to run at 100khz, but I recently reworked it to squeeze it up to just over 400khz, but its highly dependant on the optimisation level in the code, both at 100khz or 400khz.

I asked the community what they wanted, and those that bothered to reply indicated they would prefer hardware, hence why it was changed.
which is then also a possible advantage, not sure if the core currently supports it, but i've been using the hardware i2c up to 1.2Mhz. (i know, way beyond its specs, but it worked well for me :) ).
I'm interested in that. Did you just set a higher speed clock setting for i2c, or did you also need to adjust any other peripheral or gpio setting to get reliable communications.
I know many eeproms support at least 1Mhz, and would be nice to use them at max speed.

racemaniac
Posts: 617
Joined: Sat Nov 07, 2015 9:09 am

Re: Wire now uses Hardware I2C by default

Post by racemaniac » Tue Aug 15, 2017 2:05 pm

victor_pv wrote:
Tue Aug 15, 2017 1:43 pm
racemaniac wrote:
Tue Aug 15, 2017 6:41 am
RogerClark wrote:
Tue Aug 15, 2017 3:49 am
Timing on the Hardware I2C is supposed to be better.

Its probably possible to DMA to it as well, but its not been implemented.

Software only used to run at 100khz, but I recently reworked it to squeeze it up to just over 400khz, but its highly dependant on the optimisation level in the code, both at 100khz or 400khz.

I asked the community what they wanted, and those that bothered to reply indicated they would prefer hardware, hence why it was changed.
which is then also a possible advantage, not sure if the core currently supports it, but i've been using the hardware i2c up to 1.2Mhz. (i know, way beyond its specs, but it worked well for me :) ).
I'm interested in that. Did you just set a higher speed clock setting for i2c, or did you also need to adjust any other peripheral or gpio setting to get reliable communications.
I know many eeproms support at least 1Mhz, and would be nice to use them at max speed.
Just the I2C port itself, look at the documentation on the CCR (clock control register).
I've posted code using this here: http://www.stm32duino.com/viewtopic.php ... 747#p12747 (last reply)
I used it at that speed for getting 60khz samplerate on an i2c DAC

User avatar
Manny
Posts: 41
Joined: Wed Dec 09, 2015 3:15 pm

Re: Wire now uses Hardware I2C by default

Post by Manny » Tue Aug 15, 2017 3:11 pm

Where are the default pins for Hardwire defined? Having some problems running the samples.

Post Reply