that is to say, that it is implicitly delayed
libmaple i2c API
(97 posts) (15 voices)-
Posted 4 years ago #
-
Last I checked, Arduino's Wire implementation was actually using the TWI interface on the ATMEGAs. I'll be reporting back after I run a few tests this morning.
Posted 4 years ago # -
Ok, here are the results from the test this morning (a bit delayed, sorry about that).
The Wire library has been fixed in terms of suddenly becoming slow after x time (I had left a line calling SerialUSB for debugging purposes). Timeouts occur as they should, and will trigger ASSERT on the next attempt to send data. I have to have around a 5uS delay before I can have continuous communication with the ESC, if I have anything less than this (I've only tested 2uS, not 3 or 4uS), ASSERT is triggered. I still need to discover why this is (investigation for tomorrow morning), which will involve making a test program to print out the exit states. Of i2c_master_xfer();. My thoughts is, it could be taking longer than 1ms which is the timeout period I've set, if so, I will quickly find it tomorrow.
Currently I'm working on getting data from a timer channel set for input capture to measure a PWM signal. I've implemented a 'lighter' EXTI routine (due to problems with getting enough timer channels on the mini without using USB and other peripheral pins), and will be attempting later to see if I can't get it even more efficient.
Posted 4 years ago # -
sweet! dont forget to send us a pull request when you are ready.
Posted 4 years ago # -
I'm still having problems and I can't seem to isolate the problem yet, however I might be able to point in the right direction. The tests are run on my Maple Mini board unless stated otherwise.
The first test I ran was just sending commands to the electronic speed controllers (ESCs) with no delays. Here's the code:
http://crennsmind.com/Code/Maple/Debugging/I2C/Running_Motors.pdeThe next test ran was the same test with the delayMicroseconds uncommented, it causes the problem to not occur for some time, but I suspect it will happen eventually (I'll explain why later)
I also ran a test with an i2c sensor module, and had a similar outcome, here's the code for that test:
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C_Test_ADXL.pde
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C-Error-ADXL.png
The above test is run on the Maple with an ADXL345.Then I ran another set of code to attempt to recover from the bug, but the program still halts (ASSERT triggers, although the LED doesn't show that it does). For small amounts of periodic data, a delay of 3uS can be used, however 4uS will give a long running time. Here's the code running and serial outputs for the last test:
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C_Test.pde
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C-Error-ESC.png -- Original testing
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C-Error-ESC_New.png -- No delay between messages
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C-Error-ESC_New-3uS.png -- Delay between messages of 3uS
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C-Error-ESC_New-4uS.png -- Delay between messages of 4uSI've also made minor changes to the i2c files which can be gotten from here:
http://crennsmind.com/Code/Maple/Debugging/I2C/v11-modified.zipI'll also note that for Running_Motors, the LED pulsates when ASSERT is triggered, but neither of the other tests have the LED pulsating after halting. Sadly, I can't debug further due to the lack of a JTAG debugger. Another thing I should mention is, earlier I caused a small bug with my modification of i2c.c but that has been fixed.
Summary of findings:
-There is a I2C_STATE_ERROR which is preventing the
-I2C pins when I2C is halted, are high
-The ESC has a bidirectional voltage level converter between it and the mini.
-Making a small delay increases the run time/number of messages sent (4uS, I got fed up and pulled the power on the ESC which disabled it)
-The ESC has been ruled out as a cause (although apparently there can be issues with it)
-The I2C device cannot be reset to allow recoveryI'd like to try to get this bug fixed, although I'm not exactly sure where to look. I'd also like to have a function which will allow the I2C device to be reset completely so that I can recover from this bug or any other incidences.
Also, current version of the Wire library can be had from here:
http://crennsmind.com/Code/Maple/Wire-Snapshot-110623.zipEDIT: Perry has told me to try i2c_disable() (I should have looked at the i2c.h inline functions, not just the i2c.c defined functions) when I attempt to recover from the bug. I'll be running a quick test in the morning to see if this will allow me to restart the I2C.
Posted 4 years ago # -
By replacing line 50 of this file http://crennsmind.com/Code/Maple/Debugging/I2C/I2C_Test.pde with:
i2c_disable(I2C2);
The micro doesn't trigger ASSERT and continues to work. I'd say it's a suitable workaround:
http://crennsmind.com/Code/Maple/Debugging/I2C/I2C_Errors.txtPosted 4 years ago # -
Hi,
I'm trying to interface an L3G4200D gyro (from sparkfun) with a Maple board. I tried to adapt some example code written for and Arduino but it isn't working at all. Here's the code:
#include <Wire.h> #define CTRL_REG1 0x20 #define CTRL_REG2 0x21 #define CTRL_REG3 0x22 #define CTRL_REG4 0x23 #define CTRL_REG5 0x24 int L3G4200D_Address = 105; int x; int y; int z; void setup() { Wire.begin(); SerialUSB.println("starting up L3G4200D"); setupL3G4200D(2000); delay(1500); } void loop() { getGyroValues(); SerialUSB.print("X:"); SerialUSB.print(x); SerialUSB.print(" Y:"); SerialUSB.print(y); SerialUSB.print(" Z:"); SerialUSB.println(z); delay(100); } void getGyroValues() { byte xMSB = readRegister(L3G4200D_Address, 0x29); byte xLSB = readRegister(L3G4200D_Address, 0x28); x = ((xMSB << 8) | xLSB); byte yMSB = readRegister(L3G4200D_Address, 0x2B); byte yLSB = readRegister(L3G4200D_Address, 0x2A); y = ((yMSB << 8) | yLSB); byte zMSB = readRegister(L3G4200D_Address, 0x2D); byte zLSB = readRegister(L3G4200D_Address, 0x2C); z = ((zMSB << 8) | zLSB); } int setupL3G4200D(int scale) { writeRegister(L3G4200D_Address, CTRL_REG1, 0b00001111); writeRegister(L3G4200D_Address, CTRL_REG2, 0b00000000); writeRegister(L3G4200D_Address, CTRL_REG3, 0b00001000); if(scale == 250) { writeRegister(L3G4200D_Address, CTRL_REG4, 0b00000000); } else if(scale == 500) { writeRegister(L3G4200D_Address, CTRL_REG4, 0b00010000); } else { writeRegister(L3G4200D_Address, CTRL_REG4, 0b00110000); } writeRegister(L3G4200D_Address, CTRL_REG5, 0b00000000); } void writeRegister(int deviceAddress, byte address, byte val) { Wire.beginTransmission(deviceAddress); Wire.send(address); Wire.send(val); Wire.endTransmission(); } int readRegister(int deviceAddress, byte address) { int v; Wire.beginTransmission(deviceAddress); Wire.send(address); Wire.endTransmission(); Wire.requestFrom(deviceAddress, 1); while(!Wire.available()) { SerialUSB.println("waiting"); } v = Wire.receive(); return v; }
I changed the SDA and SCL to 9 and 5 in the library and there are pull-up resistors built into the breakout board. Any ideas why this isn't working?
Posted 3 years ago #
Reply
You must log in to post.