arduino / Arduino

Arduino IDE 1.x
https://www.arduino.cc/en/software
Other
14.18k stars 7.02k forks source link

Due TWI+TWI1 pins : are there integrated pullups on-board or not? if yes: how to disable? #4007

Closed shiftleftplusone closed 9 years ago

shiftleftplusone commented 9 years ago

hello, 1st question: about Due TWI1 pins (2nd i2c port): are there integrated pullups on-board or not? if yes: how to disable?

shiftleftplusone commented 9 years ago

why is there no one who can comment and fix this effing issue?

mikaelpatel commented 9 years ago

Seems like you need some help to search info. I found this (in 10 us :-) here: https://www.arduino.cc/en/Main/ArduinoBoardDue

TWI 1: 20 (SDA) and 21 (SCL) TWI 2: SDA1 and SCL1. Support TWI communication using the Wire library. SDA1 and SCL1 can be controlled using the Wire1 class provided by the Wire library. While SDA and SCL have internal pullup resistors, SDA1 and SCL1 have not. Adding two pullup resistor on SDA1 and SCL1 lines is required for using Wire1.

Cheers!

shiftleftplusone commented 9 years ago

thank you, but then I wonder why the Mega with disabled pullup resistors works as an i2c slave (to a Lego Mindstorms EV3 master) and the DUE don't - neither by Wire not by Wire1.

http://www.mindstormsforum.de/viewtopic.php?f=25&t=8673#p67709

In this case it must be a hardware bug which needs to be fixed pls CMIIW).

mikaelpatel commented 9 years ago

Can you get the Due to work as an I2C slave at all? For instance with a Mega as master. It does not necessary have to be a hardware issue. Have you tried debugging the Due I2C code? Checking the state machine etc.

Thanks for the poetry :)

mikaelpatel commented 9 years ago

BW: Is there a difference in voltage? The pullup resistors on the Lego Mindstorm might be to large and/or expects 5V? What is the spec? The Due is a 3V3 board. Is it not?

http://forums.adafruit.com/viewtopic.php?f=31&p=191092 (Goggle 42 us) http://www.dexterindustries.com/howto/connect-the-arduino-and-the-lego-mindstorms-together/ (Another 42 us :) http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter Cheers!

shiftleftplusone commented 9 years ago

According to Lego company specs, the EV3 is at 3.3V level but has a 5V protection. All new EV3 sensors also work at 3.3V level (ADC, UART, I2C).

2 DUEs work by i2c by a simple test, 1 as a master, 1 as a slave (Wire-Wire, Wire-Wire1, Wire1-Wire). (did not try Wire1-Wire1).

By having internal pullups activated also the Mega fails to work with either Lego brick. by disabled pullups the Mega always worked with either Lego brick.

The dexter industries example works with an Uno, basically it's similar to my approach using a Mega. Note that the EV3 needs 2x 47k pullups (actually 32k...82k work) because of it's weird bitbang i2c implementation. Either lower resistor in that line breaks the i2c transmission.

mikaelpatel commented 9 years ago

@VogonJeltz

Good work! You will need a scope or at least a logic analyzer for the next step. So far this looks like a hardware problem in your setup. There is no evidence that there is a problem with the Due board or the software then.

Have you tried a level shifter with the correct pullups on both side?

Cheers!

shiftleftplusone commented 9 years ago

no, I dont have level shifters and I also don't have a scope, I am not experienced in electrical stuff. Just plugging wires from one header to the other is ok of course.

mikaelpatel commented 9 years ago

@VogonJeltz I think that this issue is answered now and should be closed. Good luck with your project!

shiftleftplusone commented 9 years ago

I'm not quite sure if everything is answered. First of all I would like to try to disable the internal Due pullups on Wire by software, like I did for the Mega (patch in ...\avr\twi.c ) . How can I do this for the Due?

NicoHood commented 9 years ago

This is not a support forum. It really looks like a hardware issue, so arduino IDE developers cannot really help you. You might want to ask in the forums or chat about this specific project question.

A Level shifter (logic level converter) is 1$ and a logic analyzer (salae china clone) is 8$. Both can be really useful at any time/project.

shiftleftplusone commented 9 years ago

the design of twi.c in the avr subfolder is there by default, but it can only enable (or disable by outcommenting) AVR pullups, no ARM pullups.

// file: twi.c           
//  activate internal pullups for twi.
 //  digitalWrite(SDA, 1);
 //  digitalWrite(SCL, 1);

So there has to be changed something in the ARM libs, and this is a question or a request to the developers, not to end users in either user forum.

NicoHood commented 9 years ago

As said above from @mikaelpatel we do not have your hardware and cannot help you debugging your hardware. Grab a logic level converter and a logic analyzer and provide us more information.

And if you need to change the "arm" lib, go ahead, its open source. The due is SAM by the way, no ARM.

The forums are still a better place, since mostly noone checks the github issues, except some interrested developers. You have a better change to ask there or in the IRC chat. From time to time there are very experienced users.

Another idea would be to ask @sandeepmistry who created a lot of PRs with TWI fixes. He is the guy to ask I guess.

Good luck.

shiftleftplusone commented 9 years ago

which part was ununderstandable? my question was not about hardware debugging, it is simply about disabling Due-pullups on Wire by a software command. Just like for AVRs. But * there is not a single twi.c file in either \arm... subdirectory. * // << why does the editor erase the 2nd backslash?

So how to do it?

If not implemented FTM: please implement it for the future release. Architecture: SAM Library: Wire Type: improvement

This is my issue.

mikaelpatel commented 9 years ago

@VogonJeltz I took a few minutes to browse through the SAM TWI code. I was a bit curious to how it was done as I mainly work on my own framework (https://github.com/mikaelpatel/Cosa)

Actually I could not find anything that looked like enabling of pullup - that assumption seems to be wrong for the SAM. In any case you could write a few lines of code and check the pin mode after initiating as TWI slave. I don't have an Arduino Due so I am sorry that I cannot help with that. I would also like to suggest that you check the ATMEL SAM documentation for the TWI. Guess there is some interesting info there.

Keep up the poetry!

NicoHood commented 9 years ago

SDA/SCL0-3 are connected to a pullup by hardware. (pin 7/8). The default pins (above D13/AREF)for I2C dont seem to be connected to any HW pullup.

Just use a multimeter or @mikaelpatel s suggestion.

shiftleftplusone commented 9 years ago

yes, also on the Mega SDA/SCL are connected to hardware pullup resistors, but they can be enabled or diasbled by software command in twi.c.

The feature request to the developers was: If not implemented FTM: please implement it for the future release. Architecture: SAM Library: Wire Type: improvement

NicoHood commented 9 years ago

Well it has in chip pullups and on PCB. Maybe the volt level is a problem or the Pullup is too strong/too weak.

The devs have recognized your issue and will respond if they feel to respond.

mikaelpatel commented 9 years ago

Now I think there is some confusion about hardware pullup resistors (internal or external). On the Mega (https://www.arduino.cc/en/uploads/Main/arduino-mega2560_R3-sch.pdf) there are 10K external hardware pullup resistors. The AVR device driver code uses the internal port pullup resistors to protect the pins in TWI mode. These are large 20-50K but apparently affect the Lego Mindstorm when in parallel with the external pullups (6-8K when in parallel).

The Due (https://www.arduino.cc/en/uploads/Main/arduino-Due-schematic.pdf) on the other hand has external pullup resistors on Wire0 1K5 to VCC (3.3V). There are no external pullup resistors on Wire1.

@VogonJeltz I think you have got this mixed up. Please check the schematics and the device driver code.

NicoHood commented 9 years ago

Of course there are! RNB1 and RNC1, 10k pullup to 5V top middle next to the isp header (and the 16u2 has no I2C at all)

Maybe you DO need pullups, but stronger pullups.

mikaelpatel commented 9 years ago

@NicoHood Found them! But they are hardly controlled by software as @VogonJeltz claims :-). With the internal pullup in parallel this gives approx. 6-8K. Deactivating the internal pullup gives these 10K pullups to 5V which seems to work with the Lego Mindstorm. But this does not help much with the Due? It puts the record straight with Mega though.

Cheers!

shiftleftplusone commented 9 years ago

to be honest, I now don't understand any more what you're saying... too many "there is not" ...."there is though"...."no there is not, but something different"..."no, there is also not" ...."no, of course there is!"... "no, they are not, but does not help..." ???

so can you confirm that there are DUE-pullups both on Wire and Wire1 (either if internal or external would not matter)?

That would explain the issue, because pullups on the bus have to be at least 32k... up to 82k. just 1.5k-10k is too low for EV3, it pulls up the wires too strongly. If not disabled and replaced e.g. by 47k's, no communication to EV3 will be possible.

remark: on the Mega instead, I once was told that there are no "chip-internal" but "extra-on-board" pullups on the board, somewhere in the corner close to pins 18-22 in the vicinity of the SPI header - but actually that does not matter because they can be disabled by software completely (enough) which makes the Mega work with additional "extra-external" 47k resistors

anyway, again, this following would be the crucial question: can one confirm that there are DUE-pullups both on Wire and Wire1 (either if internal or external would not matter)?

shiftleftplusone commented 9 years ago

next, if there indeed are pullups anywhere on the Due board

if not possible FTM:

peabo7 commented 9 years ago

On October 24, 2015 at 1:40 AM VogonJeltz notifications@github.com wrote:

next, if there indeed are pullups anywhere on the Due board

  • how can you disable by software pullups on Wire pullups on Wire1 ?

What does this have to do with the Arduino IDE?

You need to consult the schematic and data sheets (noted previously IIRC).

Try something out. You are not as simple as you claim. If you find something relevant to Arduino, find out how to submit a pull request.

shiftleftplusone commented 9 years ago

which part of this thread didn't you understand? Come on, you are not as simple as you claim

in the Arduino-IDE/API (system installation folder) there is a file called twi.c for avr as I already repeatedly had posted, and with a twi.c patch it worked, search the post above!

Now the request is about a similar API functionalty for the Due, is that so hard to understand?

NicoHood commented 9 years ago

But we cant help you debugging your hardware problem without any hardware. You need to give us some information, as requested here: https://github.com/arduino/Arduino/issues/4007#issuecomment-150532579 https://github.com/arduino/Arduino/issues/4007#issuecomment-150590042

peabo7 commented 9 years ago

Now the request is about a similar API functionalty for the Due, is that so hard to understand?

Not a problem, can you work on it?

We're all volunteers here: help yourself.

shiftleftplusone commented 9 years ago

peabo, Man, if I could I had not asked. I am a simple Arduino beginner and hobby programmer, I have no idea of electonics or C compilers underneath, I just use the Arduino Sketch because it's so simple and I dont have to care about all this technic and gpp and make mess.

(honestly, I think Arduino would be better off if there were professional, full-time paid employees to care about all board issues and improvements.)

shiftleftplusone commented 9 years ago

@NicoHood, what do you want to know? please simple words, short sentences, I need to use Google translate for it. Or post in German, that would be best. I can only report the issue and the twi.c software disable-request for the Due:

quote: " anyway, again, this following would be the crucial question:

next, if there indeed are pullups anywhere on the Due board

if not possible FTM:

"

NicoHood commented 9 years ago

Ich bin nicht der King in Sachen I2C. Das problem ist, dass wir dir einfach kaum helfen koennen, ohne hardware. Wenn sich die devs nicht mit einer Loesung melden, musst du wohl oder uebel ran. Und wahrscheinlich kann dir da auch niemand helfen, WEIL es ein HW und nicht SW problem ist.

Was er hier vorgeschlagen hat https://github.com/arduino/Arduino/issues/4007#issuecomment-150532579 war, dass du dir einen logic analyzer nimmst und schaust, was auf dem port abgeht. Raten bringt nichts. Nachschauen. Wie gesagt kostet so ein Teil aus china auch kaum was.

Hier https://github.com/arduino/Arduino/issues/4007#issuecomment-150590042 schreibt er, dass er in dem code nichts finden konnte, was einen pullup aktiviert. Es muss nicht zwanglaufig beim due auch soetwas geben, das sind ganz andere processor architektueren. Wenn dus wirklich wissen willst, musst du eben ins datenblatt schauen oder eben hardwareseitig messen. Ebenso hat er vorgeschlagen mal den pinmode auszulesen, nachdem der I2C slave initialisiert wurde. Ich schaetze mal es ging ihm darum zu sehen ob der pin high oder low ist. Einfacher gehts eben mit messen. Eventuell ist der pullup so stark, dass einfach kein signal durchkommt.

Und da wie oben erwahnt es wahrscheinlich auf ein HW problem hinauslauft musst du einfach einen level converter mal testen (1€) oder mit nem logic analyzer messen (8€). Wir haben keinen mindstroms hier rumliegen, noch die entsprechenden connector, noch die zeit dazu.

Wie gesagt am besten ist immer noch im chat zu fragen, weil da die bastler rumduedeln und hier mehr die entwickler. Wobei die auch sehr beschaeftigt sind. Kann ja wirklich sein, dass es ein bug ist etc. Aber im open source geschaeft bist du dazu angehalten den fehler selbst zu finden oder bei der loesung zu helfen. Letztendlich ist es so, und du kannst kaum was machen. Wenn du linux als OS nutzt, wirst du das auch da merken. Mal mehr mal weniger. Andererseits bekommst du natuerlich auch viel zurueck, wo andere etwas einbauen, was du bereits alles schon nutzt und dir gar nicht auffaellt. Aber naja darum gehts nun nicht.

Und bitte poste jetzt nicht in deutsch, das versteht hier wahrscheinlich keiner. Und da ich so gut wie gar keine ahnung von I2C habe kannst du mich auch nicht mehr Fragen, als wie du versuchen koenntest das Problem selbstaendig zu loesen. Keiner will dir boese oder dich aergern. Nur ohne deine Hilfe koennen wir das nicht loesen.

shiftleftplusone commented 9 years ago

So kommen wir nicht weiter, ich habe kein elektronisches Equipment außer Jumper-Kabel und 1 Breadboard. Und ich werde es mir auch nicht anschaffen, ich programmiere ein bisschen hobbymäßig mit Arduino und Lego, ich baue keine Schaltkreise.

ich brauche erstmal eine ganz einfache, klare Antwort auf die aller-erste Gretchen-Frage (offensichtlich sind 3 Fragen auf einmal zu viel):

Gibt es nun wo auch immer eingebaute oder dazugelötete Pullups auf dem 2. I2C-Port (auf dem Due, natürlich)?

Google-translate:

So we will not get further, I do not have electronic equipment except jumper cables and 1 breadboard. And I'm not going to buy me, I program a little hobby with Arduino and Lego, I do not build circuits. I need first a very simple, clear answer to the all-first crucial question (obviously 3 questions at once are too much): Is there now wherever incorporated or already soldered pullups on the 2nd I2C port (on the Due, of course)?

NicoHood commented 9 years ago

Nach Schaltplan hat nur der eine port (pin 7 + 8) HW pullups. Alle haben aber (vermute ich mal) interne pullups, im chip direkt.

shiftleftplusone commented 9 years ago

ok. dann muss man sie per Software abschalten können, genau wie auf dem Mega. Und zwar alle, sowohl auf dem 1. als auch auf dem 2. i2c-Port.

Also die 2. elementare Frage: wie kann man - JETZT SCHON - sämtliche auf dem Due verbauten Pullups softwaremäßig abschalten genau wie auch bereits heute schon auf dem Mega möglich?

Google translate: OK.then one must be able to switch them off by software, just like on the Mega. And all of them, both on the first and on the second I2C port. So the 2nd crucial question: how can one - ALREADY NOW - turn off on the Due all existing pullups in software just like already on the mega possible today?

mikaelpatel commented 9 years ago

@VogonJeltz I borrowed a Due from a friend and got it to work with EV3, Wire1 and level shifter with large pullup according to spec. You might have fried your Due Wire1 port when playing around?

shiftleftplusone commented 9 years ago

the Due Wire1 works when plugged to a 2nd Due, no issues, both as a master and as a slave, but both Dues don't work on Wire1 with the EV3 as a slave (and also not on Wire0, as expected)

But level shifter? why level shifter? EV3 is 3.3V, too!?.

mikaelpatel commented 9 years ago

@VogonJeltz Then you are doing something else wrong. If you have limited knowledge of electronics it is easy to connect something wrong such as ground. Anyway there is no problem when using a level shifter and the correct pullup resistors on the EV3 side.

shiftleftplusone commented 9 years ago

But level shifter? why level shifter? EV3 is 3.3V, too!?.

mikaelpatel commented 9 years ago

@VogonJeltz Sorry but I cannot help you more. I was curious about the EV3 I2C, did some reading and testing. That is all I have to offer. Have a nice day!

shiftleftplusone commented 9 years ago

I see, probably my 2 Dues are broken and it's a hardware damage then. But I won't buy 2 new ones then, too expensive. Then I'll abandon this try. Thanks for your test!

NicoHood commented 9 years ago

Maybe you tell him your setup and then he can solve the problem. I dont think both dues are broken.

shiftleftplusone commented 9 years ago

anyway, it would be helpful if one could switch off all the Due pullups by software just like it's already possible for the Mega. (ceterum censeo)

shiftleftplusone commented 9 years ago

update: I also tried with level shifters as mikaelpatel wrote:

NO CHANCE, NO CONNECTION AGAIN! Mega works, DUE NEVER !

shiftleftplusone commented 9 years ago

anyway, it would be helpful if one could switch off all the Due pullups by software just like it's already possible for the Mega. (ceterum censeo)

peabo7 commented 9 years ago

I am a simple Arduino beginner and hobby programmer

This is your opportunity to advance your knowledge. Everyone here was once a beginner. Beginners become experts by trying to solve their problems. The AVR code is your starting point. The schematic and the datasheet for the DUE tell you what your resources are. Try making a version for Due. When you run into problems, ask questions.

shiftleftplusone commented 9 years ago

come on, please spare me your conceited, snoopy, uppish, lecturing and ludicrous attitude! Do you wantt to make fun of me?
Or are you just trolling?

If you don't want to help or contribute something productive, just shut up and keep walking!

It's a feature request to be added to DUE lib improvements to disable pullups on Wire pullups and on Wire1 pullups by Arduino IDE/API software functions similar like it already works for the Mega.

period!

cmaglie commented 9 years ago

1st question: about Due TWI1 pins (2nd i2c port): are there integrated pullups on-board or not?

Pins "SDA" and "SCL" (number 20 and 21) have pull-up resistor on board. Pins "SDA1" and "SCL1" does NOT have pull-up resistors on board.

This is explained here: https://www.arduino.cc/en/Main/ArduinoBoardDue

Support TWI communication using the Wire library. SDA1 and SCL1 can be controlled using the Wire1 class provided by the Wire library. While SDA and SCL have internal pullup resistors, SDA1 and SCL1 have not. Adding two pullup resistor on SDA1 and SCL1 lines is required for using Wire1.

They can not be disabled via firmware because there are two physical resistors on board (you should de-solder the components from the board to physically remove the pull-ups).

The CPU on the Due board has pin pull-ups that can be controlled via firmware, but they are too weak (100KOhm) to be used in I2C bus.

shiftleftplusone commented 9 years ago

cmaglie, thank you very much for clarification. So after all, the way the on-board-hardware-pullups on the Mega appear to be constructed in another way, because they actually can be disabled by software - but this would absolutely not be possible for the Due, is this irrefutable?

matthijskooijman commented 9 years ago

The internal pullups on the Mega (and most other AVR-chips) are smaller, typically just over 20k, which is usually small enough for I2C comunication.

For the Due, the current resistors are soldered in place, so no, there is nothing you can do in software to disable them. A future revision could have a transistor added to enable/disable the pullups, but it seems unlikely that that extra complexity will be added.

I'm not sure why you actually want to disable these pullups, though? They are required for I2c operation, so unless you're running I2c with another device that runs at < 3.3V, I can't see any reason not to have these pullups?

shiftleftplusone commented 9 years ago

they have to be disabled to be interfaced as a slave to a "very special master device" (see posts above). On the Mega the board-pullups can be deactivated be patching the twi.c file (see above) without deactiving the board-pullups Mega don't work as a slave (see above), after deactivating the board-pullups by software it works (see above).

Now my question was, why is it possible to deactivate the board-pullups on the Mega by software via twi.c and is it possible or is it _absolutely irrefutably impossible_ to do this on the Due in a similar way?

PaulStoffregen commented 9 years ago

@VogonJeltz You are wasting the very valuable and limited time of many software developers with your selfish requests. Please stop using Arduino's Github issue tracker for your personal project tech support.

DO NOT ask for improvements here regarding issues you do not understand. Ask on the forum first. You should never make these sorts of requests, without knowledge and experience, until other experienced people have confirmed the true nature of the problem. The forum is meant for exactly that type of conversation.

For example, you should conduct this query on the forum. Solicit experts to answer your questions regarding what is and is not possible by the hardware. DO NOT POST HERE until after you have received confirmation from experts on the forum for your technical questions.

You are selfishly wasting precious time from people who do contribute to Arduino. Please stop being so selfish and unproductive.