I'll add that I also submitted a PR (to a private repository) to update the contents of the two tutorial pages on that list, but since that PR hasn't been merged yet I didn't strike those list items out.
mcmahad:
Why does Arduino deprecate and hide the use of main(), and instead create the setup() and loop() functions?
launch the IDE and type this
int main()
{
Serial.begin(115200);
Serial.println(F("It all works fine!"));
Serial.flush();
return 0;
}
click to compile and upload to your Arduino Uno. Open the Serial monitor at 115200 bauds. you'll see it works.
But the point was an attempt to make it easy for new comers and it does a pretty good job at that because the code above does not configure my arduino pins, timers, etc... to make it easy for me. that's what they perform in main() and then call your setup() and the loop() in an infinite loop (and a few more things on the side).
Well you think hard first before disabling interruptions... but yes if you want something atomic then you need to disable the interruptions that could modify what you are playing with.
gfvalvo:
A much bigger problem than a non-standard macro is the fact that operation is non-atomic. Hence, it is not interrupt-safe.
Why does interrupt safety matter here? Are there any interrupts in the Arduino Core that write to the PORTD register?
If there's user code updating PORTD in both the main loop and in an ISR, that's a different situation, but then it's up to the user to make sure there are no race conditions in his/her code. (But I wouldn't expect that to be the default assumption in an introductory discussion of direct port manipulation.)
PieterP:
Why does interrupt safety matter here? Are there any interrupts in the Arduino Core that write to the PORTD register?
Pieter
Perhaps in a library that's being used? I would make it atomic to be absolutely certain of the result. If there were a conflict, it would be a real pain to debug.
gfvalvo:
Perhaps in a library that's being used? I would make it atomic to be absolutely certain of the result. If there were a conflict, it would be a real pain to debug.
That's a good point. I could see the Servo library causing problems, for instance.
Perhaps in a library that's being used? I would make it atomic to be absolutely certain of the result. If there were a conflict, it would be a real pain to debug.
If that is the case, then you'll have to disable interrupts for each library call, which in my honest opinion is going to cause more issue
I have the impression some of you total miss the context.
Read where this line come from, and than decide if you really would like to read about interrupt safeness in that article: Arduino Reference - Arduino Reference
PieterP:
Don't quote me on this, but IIRC, the UART operates independently of the GPIO registers.
When the UART sends something out the Tx pin does change state, right ?
So you are at risk of writing back an old value on Tx which could impact a module (BT, GPS, GPRS,...) connected on pins 0 and 1 (Serial). Eg your read PORTD and see a 0 for Tx, then there is a Serial interrupt that sets Tx to a 1, then your code resume and perform the mask and write back the 0 into Tx)
hzrnbgy:
If that is the case, then you'll have to disable interrupts for each library call, which in my honest opinion is going to cause more issue
Fortunately, you're wrong. You only need to disable interrupts in non-ISR code when you want an absolutely safe read / modify / write of a PORT register.
noiasca:
I have the impression some of you total miss the context.
Read where this line come from, and than decide if you really would like to read about interrupt safeness in that article: Arduino Reference - Arduino Reference
I think it’s relevant to mention you need to be careful as those pin masking stuff are not atomic (except writing on PINx when you flip a pin with a direct write).