HI.
I'm trying to use port manipulation with arduino DUE.
I had no problems with mega 2560, but the syntax changed...
I found a very simple example on the forum to toggle pin 2, but it doesn't work.
What is the correct syntax?
Thank you for your help.
(If you have others examples, it can help me...)
(I have already post on the specific due forum, but I'm not sure this forum is very reactif ...)
Patrick
void setup() {
// put your setup code here, to run once:
pinMode (2,OUTPUT);
}
void loop() {
// This will create a mask with a one in a 32 bit number to set this bit 27 of PORTB
REG_PIOB_SODR |= (0x01 << 25); // Turn on the LED
delay(1000);
REG_PIOB_CODR |= (0x01 << 25); // Turn off the LED using the CODR register
}
You need a second delay after the last line.
What is happening is that the last line executes,
then the code re-enters the loop() section and immediately executes the first line.
You will not see the flash.
I would have expected to see something along these lines (note that the pinMode function takes the number of the pin conected to the LED as its first parameter)
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Krug, are you trying to say that direct port manipulation shouldn't be used? I agree that you should use the framework functions as much as possible but there may be situations where you do require direct port writes. The fantastic thing about the Arduino framework is that it does allow that.