Not able to perform register level coding on Arduino MEGA (Atmega 2560)

I am trying to perform a bit flip operation on pin 25 of Arduino MEGA (2560) using register level coding. But there is no response from the board. The compiler doesn't reject it either.

Here is the code:

int main()
{
  DDRD|=1;
  while(1){
    PORTD^=(1<<0);
  }
}

I used this with setup() and loop() as well, to no avail. However, it works perfectly fine with digitalWrite and pinMode.
Is there something wrong with the code? Or does MEGA not allow this?

I moved your topic to an appropriate forum category @mahesh_namboodiri.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

Which pin 25 are you referring to?

Pin identified as 25 on the double row header is connected to PA3. Pin 25 on the actual chip is connected to PB6.

EDIT: From you code, PD0 is the I2C clock pin SCL which is designated pin 21.

1 Like

By pin 25 I mean 0'th pin of port D. I have used the following pin description for reference.

Datasheet

That's not the package pin out for a 2560.

Arduino pin numbers are for the (Mega...) boards, not related to chip pin numbers.

Also have a look at the Figure 1-3 label and you'll see that it's of a 2561. The 2560 pinout comes a few pages before.

The signal should be on Arduino pin PD0, lower right in the diagram below, if the posted snippet is the only relevant code in your program.

How will you detect the signal, which will appear in the MHz range?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.