1

Arduino Nano Every schematic informs us that we can use ATMega4809's pins PF03 and PF02 to communicate via I2C.

ATMega4809 manual says in page 19 that in order to use those pins as I2C we need to use PORTMUX.

I'm not really an expert and I don't understand how to do that. Any help would be approciated.

2

In the Nano Every schematic, PF2 and PF3 are connected over to PA2 and PA3 respectively. That is, Arduino pin A5 and ATMega4809 pins PF03 and PA03 are connected together by PCB traces such that there's no distinction between them, PF03 doesn't have its own header pin anywhere distinct from PA03. They're both A5. Likewise for Arduino pin A4 and ATMega4809 pins PF02 and PA02.

The Nano Every was designed to be compatible with the original Nano boards that used the ATMega328P. On these boards the A5, analogRead-capable pin, is also the I2C/Wire clock signal. Likewise, A4, analogRead-capable pin, is also the I2C/Wire data signal.

On the ATMega4809 the I2C/Wire Master/Slave signals on PORTA routed to the A5 and A4 pins are not also analogRead-capable. That is, they are not connected to the analog-to-digital converter in the chip as they were in the Atmega328P on the old Arduino Nano boards.

To mirror the workings of the original Nano, where A4 and A5 were both analogRead pins and I2C/Wire Master/Slave pins, they connected A4 and A5 to pairs of ATMega4809 pins. One of these pins on PORTF is connected to make the Arduino pin analogRead-capable and the other pins on PORTA are connected to make the Arduino pin Wire/I2C Master/Slave capable. In other words, they used two AVR pins to synthesize a single Arduino pin capable of both functions that were available on that pin on the older Nano boards.

When it comes to using PORTMUX to switch choice of I2C pins, practically speaking, you won't be able to if you're looking to get alternate pins for TWI Master. PORTMUX lets you switch the I2C Master/Slave or just Master peripheral onto pins PC2 and PC3 instead of PA2 and PA3. But, in the Nano Every schematic, you can see these are not connected to anything. So if you wanted to do that, it would mean something like soldering wiring-wrap wire directly to the MCU pin, which would be difficult. And PC2 and PC3 are the only two other ATMega4809 pins that PORTMUX will route the hardware I2C Master/Slave peripheral to. So, practically speaking, if you want I2C any pins other than A4 and A5 on a Nano Every, it means using a software (bit-banged) implementation of I2C.

You asked (in comments) about the TWI support indicated on PF2 and PF3 in the ATMega4809 datasheet. I think I'd either been looking at an older datasheet or maybe disregarded those pins because of how they're hardwired over to PORTA on the Nano Every. The ATMega4809 has a "Dual TWI" mode apparently, where you can have just master mode on the pins that are normally both, and just slave mode on an alternate set of pins. In two configurations of PORTMUX under Dual TWI, the PF2 and PF3 are where the slave-only capability of the peripheral are broken out. With PORTC's TWI pins unconnected and PORTA's TWI pins hardwired to PORTF's TWI pins, it's unclear to me what advantage you could get out changing PORTMUX on an Arduino Nano Every.

7
  • Ok, thanks for the info. Even so, how can I force the I2C communication to use pins PF2 and PF3 instead of PA2 and PA3?
    – Miguel
    Mar 20 at 21:02
  • I probably wasn't clear enough in this part. In the Nano Every schematic, you can see that those pins are hard-wired together. That means, for example, Arduino pin A5 and ATMega4809 ports PF03 and PA03 are all the same node in the circuit connected together with copper traces. That is the significance of having the A5/SCL label applied to all three things.
    – timemage
    Mar 20 at 21:12
  • I understand that. I know that they are both connected but I'm doing some tests and I want to test an I2C communication from PF2 and PF3 pins. I think that it must be a way to swap the pins that will be used by, for example, the Wire library. That is what I'm searching for.
    – Miguel
    Mar 20 at 21:23
  • I get the impression that there's still something I haven't made clear. I did go back and reword things to try to things more direct, specifically that there are only two sets of pins that can have the I2C hardware support routed to, and only one of those sets is soldered to the chip. This is something I updated in the last paragraph.
    – timemage
    Mar 20 at 21:38
  • 1
    Interesting, I think I've been looking at several different editions of the datasheet. In the one you have liked above I see (S) and (MS), which I'm guessing are "slave" and "master". Will get back to you on it, maybe update the answer with what I find.
    – timemage
    Mar 20 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.