The Wire library is soft I2C ( bit banged) so you can use it on any GPIO pins.
Max speed is around 250khz, but you need to instantiate another copy and pass SPFTWARE_FAST as the speed.
Hardwire is a separate class and uses the dedicated HW I2C pins and is good for 400k, but you need to change your existing code to use that class name instead of Wire
BTW. with some optimisation the soft I2C could easily be pushed up to 400k, its just no one has had the need for this, so no one has looked at optimization
The one who doesn’t need speed or performance take the bitbanged soft library, the “need for speed” and performance seekers use the HW version – I do both, depends on the project.
I think a complete HW based wire library isn’t possible with the old libmaple i2c.h core (errors, not corrected HW issues and other pitfalls) so this is also a reason why nobody combined it.
Someone did a Pull Request to make some fixes to hardware I2C last week.
I didn’t test Hardware I2C because I didnt have time, but the OP said it was now working OK. (Sorry again, I can’t remember the link etc but the PR will be visible on github)
I used maple ide 0.0.12 and wire.h library.
I looked the topic ray posted here. But i’m still confuse.
So, is the only way to must write my own driver to use hardware i2c ?
maybe I should use arduino ide with maple mini but i have not any st-link other usb-rs232 converter to change the bootloader for arduino ide.
In STM32F1/libraries/Wire/Wire.cpp, which speed is used in the “TwoWire Wire(PB6, PB7, SOFT_xxx)” constructor ?
I’ve done few measurements with my Saleae too, for SOFT_STANDARD, it gives around 66KHz (which still near the normal 100KHz), and for SOFT_FAST, it gives me around 333KHz.
EDIT : I’ve change the SOFT_STANDARD define from 27 to 20, and then it went up to almost 100KHz instead of the previous 66KHz.
I will need to find the post, but someone did some timing test and concluded that the delay values e.g that set the speed were wrong, and sent me the revised ones in a PR, which I actioned.
I wonder if this is a difference between optimisation in the ARM compiler on different platforms?
I can change the values if we can get some consensus about which value to use.
#include <Streaming.h>
#include <HardWire.h>
HardWire HWire(1, I2C_FAST_MODE);
#define debugPin 33
void setup() {
pinMode(debugPin, OUTPUT);
HWire.begin();
Serial.begin(9600);
}
void loop() {
byte status;
HWire.requestFrom (0x10, 12);
while (HWire.available())
{
status = HWire.read();
Serial << (status<0x10?"0":"") << _HEX(status) << " ";
}
Serial << endl;
digitalWrite(debugPin, !digitalRead(debugPin));
delay(500);
}
No these are status registers from a radio module. It’s valid data. Pullups are 2.2k.
I didn’t not understand the goal of your post …
Is that just to mentioned that Hardwire is working fine ?
https://github.com/rogerclarkmelbourne/ … 3c4fd8e2d8
and
https://github.com/rogerclarkmelbourne/ … 2df976788b
Looks like given the data from @fergul on github, I SOFT STANDARD speed to use the new recommended setting
https://github.com/rogerclarkmelbourne/ … 4e7a0c6c0b
However this looks like its too slow, i.e on some machines its 30% to low.
Anyway, Looking at the details from @fergul, it looks like Hardwire is now working for them.
I didn’t not understand the goal of your post …
Is that just to mentioned that Hardwire is working fine ?
and will say that I2Cdevlib works fine with Mapple Mini Baite clone. I upload and run perfectly HMC5883L, BMP085/BMP180, MPU6050(without DMP, I have no idea where I wire the MPU6050 INT pin to the Mapple Mini, on an Arduino UNO it is D2 pin).
in HardWire library, which parameter gets HardWire to run at 100kHz?
Jumping in here wondering if any of the STM code in question has slave support?
//400kHz
HardWire HWire(1, I2C_FAST_MODE);
//100kHz
HardWire HWire(1);//400kHz
HardWire HWire(1, I2C_FAST_MODE);
//100kHz
HardWire HWire(1);I have a maple mini using maple-ide. I cannot see the libraries for HardWire? Any help to set these up? I have downloaded libmaple-master but not sure where to copy the files across to get to work with Maple ide?
see this example

