-
Notifications
You must be signed in to change notification settings - Fork 129
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
bp_delay_us is not accurate #23
Comments
Oh, forgot to mention that for this to work interrupts need to be disabled beforehand and restored once finished (which is not much of an issue as the board is stuck in a busy loop when this code is ran). |
Fixed with 4685d15. |
Sorry to bother. News December 9, 2016: I have digged further and by applying the fix #23 then I2CEEPROMWIN (source code here: http://web.archive.org/web/20150927140926/http://the-bus-pirate.googlecode.com/svn/trunk/scripts/I2CEEPROMWIN.c) does not work any more, it read wrong (all values are 0x01 does not matter what). |
The changes applied for #23 were supposed to fix 1-Wire, where the delays are grossly miscalculated and causing the protocol to simply operate out of spec. I wonder why I2C stops working since the two calls to bp_delay_us in i2c.c are commented out... Would it be possible to get some logic analyser dumps / screenshots / etc. for before and after 4685d15 got applied? The problem may be somewhere else, but I'll see if there was something obvious I missed that triggered this. Thanks for reporting! |
Sorry for the late reply. |
@USBEprom Can you please to try changing the value of FCY in base.h to see if things improve? I'm not sure if v3 runs at the same frequency as v4. Is v3 supposed to run at 16MHz too? |
Unfortunately inside of base.h I can not find the word FCY, where it should be? http://dangerousprototypes.com/docs/index.php?title=BPv3_FTDI_UART_demo&oldid=16133 It is stated that "The Bus Pirate uses an 8 MHz internal clock multiplied by a 4x PLL to produce a 32 MHz CPU clock" and when I have calculated the prescalers for the new speeds into the menu of SPI I have used the 16MHz value. http://dangerousprototypes.com/forum/viewtopic.php?f=40&t=3864&start=15#p41505 it is said "The 16MHz SPI speed mode is not valid, the max SPI peripheral speed is 8MHz (10MHz slave)", ignoring the context (SPI) seems that also for the Bus Pirate v3 FCY is really 16MHz. http://dangerousprototypes.com/forum/viewtopic.php?f=4&t=2262&p=22362#p22362 it is said "the bus pirate is running at Fosc 32MHz so Fcy becomes 16Mhz". |
@USBEprom FCY is here: https://github.com/BusPirate/Bus_Pirate/blob/master/Firmware/base.h#L24 Now, the only difference I can see that might impact delays would be linking libpic30 together with the project. I'll see if I can just extract the delay function alone and see if that helps. |
OK, still you won while I lose being a total babo. As it is possible to see the clock speed is still low compared the expected. |
@USBEprom can you please try to build this version and see if things change? The only difference is that libpic30 is not linked in anymore, but its delay function has been merged in anyway - as it allows for 1-Wire to function reliably. |
Unfortunately nothing happens. Thank you very much for your support sir. |
@USBEprom I think I found the problem... Can you please give this version a try? It theoretically should fix the extra delay issue on I2C, but I cannot really test things at the moment. |
Before all merry Christmas to you and thanks a lot for your hard work. I am really sorry that you alone have to take all this trouble also spending your holidays by working, as I understand that fixing the problem is really very, very hard. |
@USBEprom thanks for trying that out. I'll do some more test on my end with some sample circuits (I only have SPI devices to test with at the moment) and hopefully see what can be done. |
I agree with you. dangerousprototypes.com/forum/download/file.php?id=12196 Thank you very much sir. |
@USBEprom which mode did you use for I2C? Hardware or software? For software I2C I do get ~700Hz on SCL: For hardware I2C I get ~500kHz on SCL: Both of those using the maximum speed available. |
@USBEprom I tried with the very latest version, just rebuilt and installed and I get ~100kHz in software mode: I have the feeling that I hit a v3-only issue I don't have a board to test with... |
@USBEprom Can you please try this firmware, just to be sure? This is the last version that does not have the bug #23 fix. On a v4, in software mode I have around 111kHz on SCL, which is slower than what I get after I applied the fix. Please try this one in software and hardware modes if possible, thank you! |
Oh ok, I thought you were relying on TIMER1 asynchronously, my bad. For 1-Wire, a quick and dirty way to test things up is to hook up a logic analyser with the software of your choice - as long as it can decode 1-Wire - and use https://gitea.youb.fr/youen/OneWireArduinoSlave on any Arduino board you have laying around. That's how I debugged things back then before I stumbled upon a proper 1-Wire device. |
@agatti Best Christopher |
Thank you very much sir for having spent time on fixing this! As for you suggestion I will surely test 1-WIRE protocol too. |
thank you very much sir for your invaluable code! @ALL About #111 and #112 I must write that I am not 100% sure it totally works now because I tested them in an unorthodox manner. Please pay attention to the fact that orange color for the caption about ~400kHz SOFTWARE mode does not mean it is working bad, simply that does not match the value into the menu. |
@agatti \libraries\OneWireSlave\src/utility/LowLevel.h: In member function 'void Pin::attachInterrupt(void (*)(), int)': \libraries\OneWireSlave\src/utility/LowLevel.h:157:3: error: 'CLEARINTERRUPT' was not declared in this scope CLEARINTERRUPT; // clear any pending interrupt (we want to call the handler only for interrupts happening after it is attached) ^ I wonder if it possible to fix the issue or otherwise use something else to check 1-WIRE protocol. And another thing if possible. |
@USBEprom I used an Arduino Nano for this, even if I had the time to look into this I do not have neither a Uno nor a Mega 2560 I'm afraid. For connections, if you connect the two GND pins together and MOSI and 1-Wire together as well, that should be it - if both devices are using 5v logic levels (that's important!) for data transmission it shouldn't damage anything. At most it won't detect any data coming in or out - it's the same principle that applies for UART to USB adapters, for example... |
Please do not worry sir. |
I added @ChristopherSamSoon's delay code to the main branch - it is currently enabled by default, but can be switched off by undefining BP_USE_HARDWARE_DELAY_TIMER in configuration.h. |
I just built new firmwares SAFE and UNSAFE starting from this repository (https://github.com/BusPirate/Bus_Pirate/archive/master.zip) where you have merged the code provided by Christopher Sam Soon (https://github.com/ChristopherSamSoon/Bus_Pirate) and for me it works with Bus Pirate v3. http://dangerousprototypes.com/forum/viewtopic.php?f=28&t=8498&start=120 |
No problem, I am glad to contribute to the community. Lest us know of your results for 1-WIRE together with the iButton. I tried to lookout for my Arduino but could not get hold on it yet. |
Surely, I am already at work on that. |
Ok, in the end I managed to test the functioning of the 1-WIRE protocol on the Pirate v3 Bus using the firmwares that I got from the current repository and therefore updated, concluding that everything works as expected. https://github.com/orgua/OneWireHub It is the only one I could find that works with the Arduino MEGA 2560 board. For what I could see everything works correctly, even if I noticed a weirdness and could in my opinion be introduced some improvements. The weirdness I noticed is that while performing MACRO (1-50) which show the 8-byte ROM identifier of the device placed on the specific address chose, then the resulting final message does not match to the device on which the query was made. So for instance while querying for device 3 on the 1-WIRE bus by performing MACRO (3): 1-WIRE>(3) Then the response show the device numbered as n+1, or 4 rather than 3 as actually it should be in this case: ADDRESS MACRO 4: 0x81 0x00 0xA0 0x90 0x19 0xDA 0x00 0x03 I guess this behavior could be related to the fact that the numbering does not start from 0 because that is the purpose of MACRO (0) that on the Bus Pirate show the list of available macros, do not the 8-byte ROM of the device number 0 on the 1-WIRE bus, though I can very well be wrong. The possible improvement that I thought is tied with the item Overdrive (~160kps) into the menu as available choice. |
Ok, in the end I managed to test Overdrive (~160kps) on 1-WIRE protocol with the Bus Pirate v3 despite as it is now Bus Pirate v3 can not natively switch from standard to overdrive speed without turning off power supply and pull-up resistors so that the 1-WIRE slave device is indesirably deselected (#117 and 07c8be9). The target 1-WIRE slave was a DS2506 64Kb Add-Only Memory simulated by an Arduino MEGA 2560 running the OneWireHub-2.2.1 library (https://github.com/orgua/OneWireHub) where in "OneWireHub_config.h" the overdrive support for the slaves was enabled #define OVERDRIVE_ENABLE 1 // support overdrive for the slaves. a) SWITCH 3 = OPEN b) SWITCH 2 = CLOSE c) SWITCH 1 = CLOSE Once did so I started the Bus Pirate v3 for 1-WIRE protocol and Standard (~16.3kbps) speed, ending turning on the power supplies with command "W" and pull-up resistors with command "P". a) SWITCH 2 = OPEN b) SWITCH 3 = CLOSE c) SWITCH 1 = OPEN Then I reset the Bus Pirate v3 with command "#" and restarted it for 1-WIRE protocol this time choosing the Overdrive (~160kps) speed and ending turning on the power supplies with command "W" and pull-up resistors with command "P". a) SWITCH 1 = CLOSE b) SWITCH 3 = OPEN c) SWITCH 2 = CLOSE And I started to query the simulated DS2506 from the Bus Pirate v3. Many, many thanks sir! |
Thank you for providing the detailed test results for 1Wire mode. Let us aim to close this issue by end 2018! Best Christopher |
That would be really great, sir! |
@ ALL Maybe I am wrong, but it seems to me that also 1-WIRE protocol uses the "blocking" way described here #18, especially when the clock speed is high as in the case of Overdrive (~160kps), or rather the whole thing is more evident with high speeds. |
You may be correct. I would not be surprised if the root-cause of this behaviour is the same as #18. Anyways, this problem is not because of bp_delay_us() (This issue here), but because of "blocking" printout to UART during 1WIRE transmission (possibly other protocols as well) |
Is there anything that can be done with this issue? |
A more precise way to perform delays should be implemented as this might mess with timing-sensitive protocols such as 1-Wire. Unfortunately I bricked my v4 and I'm away for a week so I can't really work on this at the moment, but before the bricking I made 1-Wire work more reliably by changing the amount of time being waited, and my logic analyser all of a sudden would detect the protocol state changes.
Something that on paper should be more accurate would be this (assuming the number of milliseconds is in W0 and that it's running on a v4 board, which means it can execute 16 instructions each microsecond):
However I can't really try this out at the moment, if somebody with a logic analyser or a PIC simulator or a PicKit and a spare board wants to get wild with this, that'd be awesome!
The text was updated successfully, but these errors were encountered: