Oh, by the way, the SerialUSB.println("SETUP"); is never traced, but I have done a test and the setup function is executed, so, I presume the Serial communication is just not initialize here!
libmaple i2c API
(97 posts) (15 voices)-
Posted 5 years ago #
-
Quote: "no pull ups used since I do not need any on the Arduino, this may be the problem!"
Reply: I believe the Arduino had weak (software) pullups enabled in their wire library.
Your I2C will not work without them! Since the Maple pin config. made the SDA & SCL pins
"open drain" then you need to add a 3.3K to 10K pullup on each I2C pin. Just attach one
leg of the pullup resistor to each I2C pin then the other leg to 3.3 VDC.BTW ... most PCB boards with I2C has places on them to install or enable the
necessary pullups. If your board is a homemade board then you need to add them.
A trip to "The Shack" is necessary. (Radio Shack)Also, it is very possible for the soft I2C code to enable the software pullups when
the SDA and SCL pins are read BUT it might require a software re-write. I don't know,
off hand, what the software values are, but I think is would be wise to put external
pullups on your board.Posted 5 years ago # -
Regarding serialUSB - serialUSB is ALWAYS initialized by default. However, the 0.0.6 SerialUSB library has no transmit buffer, so if there is not serial monitor listening on the other end, data is simply dropped. What happens is that setup runs before you can get the window open, and so you never see the print. This is being improved.
On our xl345 driver, we were using SerialUSB, and it worked fine. However, try throwing a
SerialUSB.end() in your setup routine. Its *possible* that the softI2C routine is getting interrupted by the SerialUSB periodic bus interrupts and mangling the I2C clock. Be aware that calling SerialUSB.end() will cause the auto-reset feature (you will have to manually reset the board when programming) to STOP WORKING. You can always turn it back on again with SerialUSB.begin()Posted 5 years ago # -
Great news, I've got it working.
Put some pull-up, don't know what, I've got it from the arduino proto shield, take 2 identical that come with it.
http://www.sparkfun.com/commerce/product_info.php?products_id=7914
I was able to get it initialize and even get good data from it.
At first, did get some reading, but, not what I was expecting. The initialization process of the gyro was not completely done correctly. Also get like 500ms reading delay. Like, moving the gyro, and when stop, that take haft a second to get 0 reading as value. Then, I put back the delay at 1 I was still getting delay and weird data. Then, I remove the leaflabsandy patch "sorry bro" and I finally get the reading expected. Still have a delay, but less important.
then, I have the original file of the library
http://github.com/leaflabs/maple-ide/tree/soft-i2c/libraries/
and my adapted code from the arduino... the same actually
https://code.google.com/p/gauiquad/source/browse/trunk/GauiQuad/Gyro.h
I just call, one time, the initialize, and in the loop measure and one of the print function
Other noob question. what is the fastest communication interrogation in term of millisecond? With this gyro setting, I can interrogate it a every 2ms, but, is the library able to acheive that speed?
and the last one, do I need to pull-up for every device I add on the i2c lines? or just one time between the maple pin and the first device???
Posted 5 years ago # -
got some sample of reading here
13 (300,-324,0)
14 (642,-610,0)
14 (766,-993,0)
14 (813,-1216,0)
15 (805,-1232,0)
15 (801,-1192,0)
15 (815,-1108,0)
15 (695,-1034,0)
15 (571,-901,0)
14 (541,-770,0)
14 (415,-673,0)
14 (81,-624,0)
13 (-53,-536,0)
14 (-88,-444,0)
14 (-121,-510,0)
15 (-169,-671,0)
15 (-65,-767,0)
14 (-61,-975,0)
14 (-92,-1175,0)
15 (-140,-1355,0)
16 (-69,-1445,0)
15 (285,-1458,0)
15 (204,-1353,0)
15 (-122,-1252,0)
16 (-539,-1186,0)
16 (-1146,-1073,0)
17 (-2199,-824,0)with that code
//////////////////////////////////////////////////////////
#include "Wire.h"
TwoWire Wire;#define GYRO_ADDRESS1 0x69
#include "ITG3200Gyro.h"
ITG3200Gyro _gyro(GYRO_ADDRESS1);boolean _gyroInitialise = false;
void setup()
{
// SerialUSB.println("SETUP");Wire.begin();
}
void loop()
{
if (!_gyroInitialise)
{
_gyro.initialize();
_gyro.calibrate();
_gyroInitialise = true;
}int start = millis();
_gyro.measure();
_gyro.toStringRawData();int stop = millis();
int time = stop - start;
SerialUSB.print(time);
SerialUSB.print(" ");delay(2);
}
//////////////////////////////////////////////////////////////////that can take 17ms to do the reading, that's really long!!!
Posted 5 years ago # -
Quote: " do I need to pull-up for every device I add on the i2c lines? or just one time"
Reply: Just once BUT the value of the pullups are important if you have more than
one device. You need a stronger pullup (lower resistance 3.3K) for multiple devices and
a weaker one for just one device (10K). It varies, but it is not as critical as having
no pullups at all!Quote: "Then, I remove the leaflabsandy patch"
Reply: So the "clock streching" is needed for some devices and is not needed for other
devices. Let Leaflabs address this problem.hehe... Now we got three I2C devices to work with the soft I2C wire library.
RTC DS3231, Accelerometer: ADXL345, and the ITG-3200: triple-axis MEMS gyroscope -- CoolPosted 5 years ago # -
Oh, pretty sure we can get more than that :), I may give a try to the bma-180 accelerometer tomorrow!
Posted 5 years ago # -
I would definitely remove the "toString" function from your timing! I would suspect you spend a substantial proportion of your read loop in there. Well probably make some simple speed optimizations before pushing it in. Ive done 5MHz software-I2C before, but it was a bit hackish and I sacrificed speed for readability and library-usage here. I would probably keep hacking on it until we get passed 250KHz or so. Thats 250KHz CLOCK, obviously most transactions are 8 bits device address, 8 bit transactions, plus 4 cycles-ish of ack and other wait, so 250KHz/20 ~ 12.5KHz, "fast I2C" is 400KHz. For this reason, burst mode is often handy. Such that if the number of writes/reads your doing to the same device is large, your throughput goes up to clk/8 instead of clk/20...so at 250KHz, its ~31KHz. The Wire implementation here supports this, just stuff more stuff in the buffer before calling endTransmission, or "request" more bytes.
Posted 5 years ago # -
So far, through observation, slow I2C devices like the ADXL345 and the ITG-3200 don't need "clock streching" or "burst read" but my RTC DS3231 "fast IC2" (400Khz) needs it?
Sounds like a slow (100khz) or fast (400khz) timing selection is needed?
The Maple's precision clocks really should be used eg I2C hardware DMA.Posted 5 years ago # -
Got the BMA180 accelerometer working at first try! did not get the time to verify if the data was correct, but, still, this seem fine to me!
Also have tested with 2 itg3200 and 2 bma180, and that seem working also, but, this time, look like I got some weird data on one gyro... did not get the time to trouble shoot wet!
Since, my goal is to make an aeroquad with the board, I started to import more code from my arduino project, and I have a strange compilation problem, so, I'm stuck, I started a new thread for it here!
Posted 5 years ago # -
I'm interested in using 7 Leaf Maples to control a hexapod, but they need to be able to communicate with one another. Does the soft-i2c library support multimaster mode?
Posted 5 years ago # -
no, but the hardware I2C in 0.1.0 will. Alternatively you can use the fast UARTS for this, chain them together Tx->Rx and run your own little protocol. Those run really fast too, as fast a shift out at the clock rate. Also, the HardwareSPI currently is all setup, so you could use that as well.
I would LOVE to see a project parallel communicating maples.
Posted 5 years ago # -
The fastest communication rate for the UART peripheral is 4500Kbps, from page 748 of the reference manual.
Posted 5 years ago # -
It seems like 0.1.0 could be a while away given that 0.0.7 is in progress. Do you by chance know how long that will be? If not or if it's going to be a while then may take a crack at it myself.
I considered using SPI but as far as I could tell there was no support for slave mode. Did I over look it?
Posted 5 years ago # -
0.7.0 is going out before Maker Faire. 0.1.0 it going out sometime in october.
Currently, there is no support for slave mode in the HardwareSPI implementation. Which is a bit of a glitch for stringing boards together. Hmm. We'll take a look at how hard it would be to add it in, it might not be much. I want to see your project happen.
Posted 5 years ago #
Reply »
You must log in to post.