Hardware I2C on Maple mini

z1rqdym
Thu Aug 27, 2015 12:56 pm
I see a lot of things about i2c on maple mini. But I’m not sure what is right. So I want to use 400khz hardware I2C on baite maple mini clone. What should i do?

mrburnette
Thu Aug 27, 2015 1:31 pm
z1rqdym wrote:I see a lot of things about i2c on maple mini. But I’m not sure what is right. So I want to use 400khz hardware I2C on baite maple mini clone. What should i do?

RogerClark
Thu Aug 27, 2015 9:36 pm
The Wire library I2C is now defaulted to 100khz due to hardware compatibility.

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


madias
Thu Aug 27, 2015 9:46 pm
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.

RogerClark
Thu Aug 27, 2015 10:16 pm
Matthias

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)


z1rqdym
Fri Aug 28, 2015 5:04 pm
with saleae logic clone (finally i found one and bought it) i see stange clock freq’s, for a bit on sda pin scl pin gives 20khz, on the second bit from sda pin, scl pin gives 63khz and so many between 8khz-85khz. This is very slow for my project.
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.


martinayotte
Fri Aug 28, 2015 5:43 pm
In STM32F1/libraries/Wire/Wire.h, what values do you have for SOFT_STANDARD and SOFT_FAST ?
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.


RogerClark
Fri Aug 28, 2015 9:01 pm
Martin,

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.


fredbox
Sat Aug 29, 2015 12:00 am
Read 12 bytes using I2C device at address 0x10
#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);
}


martinayotte
Sat Aug 29, 2015 1:23 am
RogerClark wrote:I can change the values if we can get some consensus about which value to use.

fredbox
Sat Aug 29, 2015 2:15 am
@fredbox, seeing your post, do you means that using Hardwire, you’re getting garbage ? did you have some PullUps on both SDA/SCL lines ?
No these are status registers from a radio module. It’s valid data. Pullups are 2.2k.

martinayotte
Sat Aug 29, 2015 2:18 am
Ah ! Ok !
I didn’t not understand the goal of your post …
Is that just to mentioned that Hardwire is working fine ?

RogerClark
Sat Aug 29, 2015 3:07 am
I had 2 PR’s for Hardware

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.


fredbox
Sat Aug 29, 2015 3:34 am
martinayotte wrote:Ah ! Ok !
I didn’t not understand the goal of your post …
Is that just to mentioned that Hardwire is working fine ?

z1rqdym
Thu Sep 03, 2015 7:24 pm
I tried HardWire library and it was great. I already check with logic analyser and everything is fine. but I see that the I2C module on STM32F1 has differences between microchip PIC’s. With L3G4200D sensor gives strange values. Maybe it’s from the pull-up ressitors which they are 10Kohm. With MPU6050 it works nice and it has 4.7Kohm pull-up ressistors. I cant change L3G4200D’s pull-up ressistors so I’m gonna change the sensor to MPu6050.

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?


kolalde
Thu Sep 03, 2015 10:37 pm
Which PIC are you using? I had some old 16F87x chips in a draw and put together some slave I2C code. Just a skeleton, but worked enough.

Jumping in here wondering if any of the STM code in question has slave support?


fredbox
Fri Sep 04, 2015 3:41 am
in HardWire library, which parameter gets HardWire to run at 100kHz?
//400kHz
HardWire HWire(1, I2C_FAST_MODE);
//100kHz
HardWire HWire(1);

z1rqdym
Fri Sep 04, 2015 6:43 am
kolalde wrote:Which PIC are you using?

z1rqdym
Fri Sep 04, 2015 6:45 am
//400kHz
HardWire HWire(1, I2C_FAST_MODE);
//100kHz
HardWire HWire(1);

Dazwah
Sat Oct 03, 2015 6:12 am
Hello,
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?

RogerClark
Sat Oct 03, 2015 6:19 am
the files are in the repo

see this example

https://github.com/rogerclarkmelbourne/ … _hwire.ino


Leave a Reply

Your email address will not be published. Required fields are marked *