I have a custom board but based on the M0 boards with a SAMD21 18G (will need to wait till 2023 for mass production as new IC's are expected only then
). But it leaves more time to focus on the software. I want to use PA12 and PA13 for i2c. The step before that is that I test the pins by connecting an LED. That is where I stumbled upon this strange phenomenon:
// global:
#define sclLED 38 // PA13
#define sdaLED 22 // PA12
// in setup:
pinMode(sclLED, OUTPUT);
pinMode(sdaLED, OUTPUT);
// in loop:
digitalWrite(sdaLED, LOW);
digitalWrite(sclLED, HIGH);
delay(500);
digitalWrite(sdaLED, HIGH);
digitalWrite(sclLED, LOW);
delay(500);
Actually nothing happens to my LEDs...
Of course this can be due to a lot of different causes, but interestingly enough this works like a charm:
// in setup:
REG_PORT_DIR0 |= (1 << PIN_PA12) | (1 << PIN_PA13); // pinmode, setting pins in direction register to output
REG_PORT_OUT0 &= ~((1 << PIN_PA12) | (1 << PIN_PA13)); // setting pins low
// in loop:
REG_PORT_OUT0 |= (1 << PIN_PA12);
REG_PORT_OUT0 &= ~(1 << PIN_PA13);
delay(500);
REG_PORT_OUT0 |= (1 << PIN_PA13);
REG_PORT_OUT0 &= ~(1 << PIN_PA12);
delay(500);
(Of course I could simplify the code above using a bitwise XOR, but that is not the point right now).
Therefor it must be some software issue...
In variant.cpp PA12 is supposed to be D22 and PA13 should be D38.
The 'normal' Arduino code does work for:
#define sclLED 13 // PA16
#define sdaLED 11 // PA17
However also for PA22 and PA23 only the lower level direction register code works (D33, D32).
Interesting isn't it? Of course for testing I don't see any problems with my second solution, but it might confuse other people (in my case students that will work with my software), so I would prefer the normal Arduino solution.