Steps: Attach the Atmel-ICE ribbon cable to the Atmel ICE using the connector on the body of the Atmel-ICE marked AVR to the ICSP pins on the body of the Arduino board.
Note: Please remember to use the AVR port and NOT the SAM port or connection when pinning it in.
Connect the ICSP header of the Arduino MEGA 2560 to the 6-pin (3 2) header located at the other end of the ribbon cable. Make sure the key pointing at the USB connector side of the Arduino MEGA by the 6-pin connector at the end of the ribbon cable. To confirm the relationship, look at the pictures below.
On most lines, the red wire designates the first pin; however, in this case, the red wire is connected to the middle pin of the 6-pin connector on the Arduino board. Make sure the connection’s tip is towards the controller while using the board.
Pin 1 of the ICSP header on the Arduino MEGA is marked with a small dot
Arduino IDE Settings for Arduino board:
Go to tools -> Boards -> Arduino AVR Boards -> Arduino Mega or Mega 2560.
Arduino IDE Settings for ATMEL-ICE Debugger:
Select the programmer you are using to flash the code.
Tools – > Programmer – > Atmel – ICE (AVR)
Steps to flash code in Arduino Board using IDE through ICSP :
Write an Example blink code and check for no errors
Go to – > Sketch – > Upload Using programmer – > or Ctrl+shift+u