There seems to be conflicting info about Mega and I2C bus. The page for Mega R3 says I2C is on pins TWI: 20 (SDA) and 21 (SCL). But there is nothing about that on the schematic. Instead it says those functions are on pins 44/43. I'd like to use IIC bus but it is a bit difficult now.
LMI:
There seems to be conflicting info about Mega and I2C bus. The page for Mega R3 says I2C is on pins TWI: 20 (SDA) and 21 (SCL). But there is nothing about that on the schematic. Instead it says those functions are on pins 44/43. I'd like to use IIC bus but it is a bit difficult now.
Classic mistake of confusing device chip pin numbers Vs abstracted Arduino virtual pin numbers. atmega chip number 44 is the same physical trace and signal as the arduino pin number 20 and of course chip #43 = arduino shield number 21. All arduino software reference documentation that refers to pin number(s) is referring to the the Arduino defined shield pin numbers. Also for your information both the newest rev Uno and Mega boards have added two new extra shield pins (above the Aref pin) that duplicate the SDA and SCL signals. This is so new shields designed that use I2C can work with both types of boards easier by using the same pins on the same connector.
That make sense?
Lefty
I see. This wasn't first time I made that mistake. I use normally always IC package numbers so those logical numbers just confuse.
LMI:
I see. This wasn't first time I made that mistake. I use normally always IC package numbers so those logical numbers just confuse.
Yes, very understandable. But you can see the advantage of the abstracted pin numbering that arduino uses? It allows sketches to be more portable between arduino boards that might use different AVR chip types, as in the same identical blink sketch using pin 13 works on both a 328p and 2560 based board, even though the actual hardware port/pin used is different for those two processors. Another advantage is that the abstraction allows the pin numbers used in your sketch to be a variable that can be changed during the running of the sketch.
It also carries some disadvantages such as speed of reading and writing to the I/O pins compared to performing direct port and pin reading and writing. You are of course free to use direct port I/O commands if you need the higher performance at the expense of losing a little 'portability' for your sketches.
Lefty
I have nothing against using logical pin numbers, it is helpful like you say. But when I build the my CPUs I like to use chip pin numbers.