-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some I2C MAG does not work #4531
Comments
I2C mag repeatedly come up as not working properly in various symptoms (including "it works on iNav"), but it is usually the case that only those with proper measurement apparatus (e.g., DSO, logic analyzers - LAs) really help trouble shooting the issue. @McGiverGim Do you have an LA? |
No, sorry, I don't :( |
Hm... Usually it's the other way arouind - hardware is reported working in Betaflight and not working in INAV 😄 In INAV it's usually an edge cases with marginal hardware quality. Some compass sensors will only work at lower I2C speeds (200 kHz). As far as I know Betaflight doesn't have the code to select low I2C speeds. |
Taking a look at the code, Betaflight works at 800 and 400, and iNav has 100 and 200 too, but I think by default it is configured to work at 400. |
You want to try 200? I'm building for default 200 now. Or, you can do it yourself? |
I can try, for sure. If the changes in the code are minimum, you can told me where to change and what values you want to try and I can compile the code by myself, if it is easier for you. I don't want to give you a lot of work ;) If I'm not wrong, is here? betaflight/src/main/drivers/bus_i2c_stm32f10x.c Lines 414 to 417 in 8b334e5
|
Yeap. That it, line 417. Change 400000 to whatever you want, 200000, 100000, ... |
I need to disable the overclock too I think? betaflight/src/main/target/common_fc_pre.h Lines 31 to 32 in 8b334e5
I will remove the if completelly and put to 200000 the value always. |
Good finding! |
Some advance:
So the constant overclock does not seem to work. Any other ideas to try? :) |
More info :) Using 400000 and changing: betaflight/src/main/drivers/bus_i2c_impl.h Lines 25 to 27 in 8b334e5
The default timeout to the long timeout... the MAG is detected and I've no errors. I need to test if it works, if the north is detected right, but is an advance :) |
Result of some tests: it does not seem to work. When I start the FC the configurator always point to the north, ignoring the position of the quad. So the MAG is detected, there're no errors, but the data does not seem to be readed correctly. EDIT: the MAG does not work because the calibration is not working. If I add some "random" values like
Then the mag is "working" (not too good because the random values are not the correct), but it works. Maybe a bug in the configurator or some problem with my changes. I will test more. |
After a lot of tests, now I think that the mag is faulty. With the changes, betaflight detects it, but the sensors tab of the mag always is 0, so I think they were not readed. |
😭 |
I have bought another, the same model, pigheaded that I am... The thursday will be here and we will see what happens... |
Hi please keep up the good work i have the same problem and would love to be able to use my mag but programing is beyond me. |
@catchra: At least telling us what board you are using, or how you are connecting your I2C device, whould give us a chance to help you with your problem... ;-) |
I am using the omnibus f4 v3 with sdcard on firmware 3.2.2 in the betaflight flasher i am using OMNIBUSF4SD at version 3.2.2 in Inav flasher i am using OMNIBUSF4SD at version 1.6-ALPHA2 |
You must put this commands in cli:
|
Thank you that work but this is the output from the CLI
it did not work until i used the commands that you gave me. |
Yes, don't worry. They are warnings. |
To let more info about this problem, until I receive the new unit, I have found an iNav user with the same problem and the same product: One of the comments say that the MAG maybe is a QMC5883 and not a HMC5983L. The photo shows an "DA 5883 7002". Is there a way to know if is HMC or QMC? |
@McGiverGim The "DA 5883" looks like a QMC5883; there are numerous Chinese sites listing the DA chip as "HMC5883 alternative". EDIT |
So I have two problems:
|
I think the manufacturer is offering custom chips with non-standard I2C address; data sheet says The default I2C address is 0D: 0001101 http://img.filipeflop.com/files/download/Datasheet-QMC5883L-1.0%20.pdf |
Here's the whole story. |
Thanks! I will try to compile inav using QMC and the address of HMC, to see if it works... Maybe this will be the only "customization". |
Data sheet mentions "OTP Load" immediately after POR and Soft Reset. I suspect I2C address is written in the OTP area... |
Oh yeah, that QMC5883 chip appears to be a real pain the back. When it's on the default address - all is ok, but if manufacturer configures it for something different - funny things starts to happen. |
@asizon: Negative... (I tried mag_hardware = QMC5883 instead of AUTO, but both failed) |
@andrejpodzimek Interesting, my Mark 4 build has a Turtle on board, and # of satellites received varies a lot, many times dropping below 6 during flight. Not trustworthy enough yet... :-o It seems it is independent of WiFi being switched on or off - I always have it off during flight... GPS receiver sits in very back of the quad, might be partly obstructed by FPV antenna, plus noise intereference might come frome that as well... |
I had problems in the past with my rincam split too, but some GPS have a good filtering that help a lot. Now I have it working without too much problem. One with compass (hmc) and the other without (qmc). I'm happy with both results. |
@RipperDrone, @andrejpodzimek: Re the differences in I2C bus driver, I think one factor there is that in the past Betaflight has tried to support as fast as possible loop times for the few flight controller models (mostly early SPRACINGF3 / clones) that use an I2C attached gyro, whereas iNav where working support for (mostly I2C) compass devices is crucial, has taken a different approach. |
We have to be careful about decreasing I2C bus speed, as HAL drivers may do busy waiting, resulting in larger jitter of loop time. Iirc, F4 (and F1) drivers does per byte interrupt, so this would not be a problem. HAL, we should investigate what it’s doing. |
If we finally go to dma interruptions in Betaflight the problem of jitter will be fixed? |
Sounds this might be an option. Anyway, dma interrupts have a lot other issues involved, as one could see with timer sensitive code parts like rpm bidir where timer interference and/or overlaid/duplicate assignments cause bugs. I feel that mag is not considered important in BF in general so putting these efforts for the mag to work only seems pointless. Going as far as to propose to drop mag support, to be consistent. If GPS Rescue is fabricated in a way to work completely independent of overlaid mag/compass information, why support it? |
I can only say probably. I2C DMA is very complicated, as I2C bus cycle is not a plain read (input) / write (output). Haven't seen F4 (and F1 and F3) library codes supporting DMA. HAL may have one. However, DMA is much less CPU intensive than what we currently do, thus friendly to jitter sensitive codes.
Lol. Why drop working code because of a non-working chip that we don't even know if the chip has a published spec? |
I have a Beitian BN-880 with the HMC5883L with 4.1 MAMBA-F7 that also does not get detected despite proper configuration and pull-ups. I'd like to try build with i2c clocked to the normal speed 400kbps and not overclocked. Are there any caveats here? I found the speed definition in bus_i2c_hal.c - still to find where overclock is set. |
Fake (labeled as) HMC5883s are actually QMC5883 and it has a different address and register from HMC. The correct address and register for QMC5883 are 0x0D and 0x1D respectively. |
Honeywell, the manufacturer of the HMC5883L and HMC5983 (same compass but with temperature compensation), discontinued these devices around 2016. However, they licensed the design to a Chinese company called QST Corporation. QST Corporation produced two versions of the QMC5883L, version "A" and "B" with each device labelled "DA5883" and "DB5883" respectively. The "DA5883" version "A" device behaves identically to the original HMC5883L and responds to the I2C address 0x1E, except that its status register doesn't work. The "DB5883" version "B" is totally different device, behaves according to the QMC5883L datasheet and as you mention responds to the I2C address 0x0D. Frustratingly, this information remains completely undocumented by QST. The fact that the status register doesn't work on the version "A" devices, means that they fail when used as a substitute for the original Honeywell magnetometers. Although it's possible to workaround the issue, by tweaking the firmware. The version "B" device has a completely different set of internal registers and any flight control firmware needs to handle this as a completely new and separate chip. Unfortunately, there's much confusion as many "HMC5883L" breakout boards are being sold with this compass replaced by either "A" or "B" versions of the QMC5883L, neither of which work with standard HMC5883L code. |
@jflyper u got me wrong here, lol. Dropping QMC type mag support for GPS rescue in BF should have been my more concise proposal. Not aware that ANY QMC type mag is currently working on BF, still it exists as a mag_hardware option. |
I have invested some time into this problem myself today. I use the recommended RX3 and TX3 pads for I2C. these are my CLI changes: resourcesresource SERIAL_TX 3 NONE masterset align_mag = CW270FLIP I have not noticed any magnetometer "wandering" yet, but the connection by usb takes longer sometimes... |
thank you so lot!!! it also worked for me on my mamba f722 with gps + mag matek m8q. |
Hi @MoppelMat, you mention you're using the Mamba F722 FC, is that the mini or the full size? I'm using the Mamba F722 mini FC and a Rush Tank Mini video transmitter. The Video and Smart Audio pads on the transmitter are going to TX3 and VTX respectively. Could those wires be moved to TX2/RX2 in order to free up TX3 for I2C? Then I wire up the SCL/SDA wires from the BN-880 to TX3? Where is RX3? Thanks! |
I have a Mamba F405 mk2 flight controller with FURYF4OSD firmware. I have connected a GPS BN-880 module with a built-in HMC5883 magnetometer. However, in automatic mode in Betaflight, the magnetometer was not detected. Although INAV sees it perfectly. It turned out that the parameter mag_i2c_address = 1 by default. There is no description of the magnetometer parameters on Githab, but there is a description of similar parameters of the barometer. It states that the value of address 1...7 is not valid. Address value 0 automatically finds the device address. I set mag_i2c_address = 0 and the magnetometer was detected. Also I tried setting mag_i2c_address = 30, which corresponds to the HMC5883 address (0x1E) and the magnetometer is detected as well. If you know the model of the magnetometer, you can specify the specific model, in my case mag_hardware = HMC5883. |
@kotikvadik Clock speed issue is already fixed. Also it will be possible to select speed you want. Check these PRs: |
wow, these are great findings - after 4 yrs BF's wonky HMC support gets fixed - genius! I fumbled around with darn HMC magneto and finally gave up - it was fine on INAV, never got it working on BF. Seems some of the legacy code GPS parameters were forgotten by some BF devs and no one remembered about the correct configuration options anymore. As easy as a setting of 0 means autodetect, contrary to the default 1 - kudos! :-) |
... As easy as a setting of 0 means autodetect, contrary to the default 1 - kudos! :-) |
Hallo, I've succesfully configured my QMC5883L (config icon is light up) on a F745 (flywooF745nano board) but in the sensor page I can't see any variation in the graph. Is it a bug in the configurator or the mag is not comunicating ? |
Update: I've noted an error on the barometer value. After disabling the magnetometer the baro return to work correctly. So there must be a conflict between the two sensor. This is the configuration: resource I2C_SCL 1 B06 mag_hardware = QMC5883 baro_hardware = AUTO |
@sdellava, what a lifesaver. Just noting what worked for me with a Mazel 5883. All that was needed in BF 4.3 RC3 was: mag_hardware = QMC5883 Well done, and thanks! |
I also had a QMC5883 working on a mamba MK4 but I had to change it to mag_i2c_device = 1 |
Latest Betaflight Configurator 10.8 renamed parameter of I2C speed. Now it is i2c1_clockspeed_khz = 800 by default. You should set it to 400 kHz (i2c1_clockspeed_khz = 400). |
I also have a Mamba F405 mk2 v2 flight controller with FURYF4OSD firmware . I have connected a GPS GEP-M8Q module with a built-in QMC5883L magnetometer. INAV sees it perfectly. But bf not work. I'm sure it's on magnetometer. I tried the setup mag_hardware = qmc5883 mag_i2c_address = 13 or mag_i2c_address = 12 i2c1_clockspeed_khz = 400. I tried all kinds of combinations and frequencies and they didn't work. bf version is 4.4.2 |
I've a Omnibus F4 Pro (V3). Two months ago I added a Radiolink SE100 (M8N + HMC5983) to my quad. It worked perfectly but after some hours the hardware was dead, I don't know why. I bought another, the same model, but this does not work. Betaflight does not detect the MAG.
First, I thinked it will be a hardware issue, so I tried with iNav, and iNav detected it perfectly out of the box, so the hardware is working.
I Have observed that the board in the old version (that worked in Betaflight) and the new (that don't work) are slightly different being the same model.
Here you have the complete diff:
But I've tested with
defaults
too, only adding this:Things that I've tested:
Maybe someone with more knowledge can compare the iNav and Betaflight code to see where the difference can be?
The text was updated successfully, but these errors were encountered: