-
Notifications
You must be signed in to change notification settings - Fork 319
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
TinyWireM returns 3 #122
Comments
I recommend my fork of TinyWireM. What chip are you using? My core supports 19 different chips with three different types of I2C hardware, so it's pretty important to make that clear. Don't use the PNx notation (ie, PB1) to refer to pins; use the Arduino pin number, or the PIN_Nx (ie, PIN_B1) defines. On the Tiny85 it happens to work with PNx notation, but everywhere else, it won't. The avr libraries provide defines for the PNx pin names - but they're meant to be used with the registers and bitshift operators, eg, PORTB|=(1>>PB2); - that is, they're defined as the number after the two letters, so they don't actually uniquely identify a pin. On the tiny85 these happen to line up, and there's only one port, so it's fine. Everywhere else, it won't work. Are you sure that your external device is connected correctly? Do you have hardware pullup resistors in place? I've had issues with I2C functionality without external pullups, the internal ones are weak. I'd put 4.7k from SCL to Vcc and SDA to Vcc if you don't have that in place already. Also make sure you're using the correct form of the address (7 vs 8 bits - I don't recall off the top of my head which is right). |
Sry I did not mention the chip right away.. It's an ATtiny85, I use the PB pins because I used platformio and Arduino IDE and they kept switching up the pin numbers. Thanks for your advice, I will keep this in mind. The connection must be correct, I switch the ATtiny in place with a Arduno Nano and then it all works. I use 4.7K pullups on SCL and SDA. The address should be okay since it works when I use the Nano. Could there be a problem due to difference in clock speed between Nano and ATtiny? |
Clock speed is unlikely to be an issue. Check the state of the pins - are they high while idle like they're supposed to be and all? What is it talking to? I don't think TinyWireM supports I2C clock stretching, which a small number of devices depend on. Got a schematic that I can give a once-over to? |
The chip is the LM75. This is the circuit I use but I use 4.7K pull-ups and no LED Here it shows HIGH on the right pins, also software serial printing the values. |
See this issue: adafruit/TinyWireM#7 |
@SpenceKonde, the key to making this stuff really work is to provide a compatible Wire library vs a library which is a fork of a core specific library - even if that library is better. @Thijxx the fixes to the TinyWireM code aren't that difficult; 2 one line changes; however, you can often work around these issues in the near term if you don't want to go muck in that library code. Another alternative work around is to install the Adafruit core, then grab the libraries/Wire directory down under the package directory and copy it to your other tiny core - I've done this to add Wire support to Mellis' core: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json |
@bperrybap - I totally agree with you. I've had plans for a while (see issue #53 ) to add a version of the wire and SPI libraries that is drop-in compatible with the default one, and will automatically pick the right code to use for the chip in question (as some of these tinies have a USI, and some have hardware SPI, one has hardware I2C master, some have no hardware I2C master support at all and need to use softwire). There are also now two candidates for the USI Wire library - the other one is in issue #125 |
This is now fixed in my fork of TinyWireM ( I think ) |
The incorrect return status of requestFrom() might be reported next .... ;-) |
What needs to be changed to fix that? (ie, do you have a working version of TinyWireM with that fix?) |
I wonder what TinyWireM library should work, I've tried the version from Adafruit but it does not seem to work. I use a piece of the I2C Scanner code to check if it works.
It always return 3, I found info about that here
The text was updated successfully, but these errors were encountered: