Due not running "some" serial sketches

I just started a project with a DUE board, it includes serial communication, but it seems to be something wrong in the DUE serial library or i’m getting crazy. The sketch works on the CAN bus of the DUE using Collin80’s library. When i try to run this example

// Arduino Due - CAN Sample 1
// Brief CAN example for Arduino Due
// Test the transmission from CAN0 Mailbox 0 to CAN1 Mailbox 0
// By Thibaut Viard/Wilfredo Molina/Collin Kidder 2013

// Required libraries
#include "variant.h"
#include <due_can.h>

#define TEST1_CAN_COMM_MB_IDX    0
#define TEST1_CAN_TRANSFER_ID    0x07
#define TEST1_CAN0_TX_PRIO       15
#define CAN_MSG_DUMMY_DATA       0x55AAAA55

// CAN frame max data length

// Message variable to be send
uint32_t CAN_MSG_1 = 0;

void setup()
  // start serial port at 9600 bps:
  Serial.println("Type CAN message to send");
  while (Serial.available() == 0);
void loop(){

  while (Serial.available() > 0) {
    CAN_MSG_1 = Serial.parseInt();
    if (Serial.read() == '\n') {
      Serial.print("Sent value= ");

  // Initialize CAN0 and CAN1, baudrate is 1Mb/s
  CAN.init(SystemCoreClock, CAN_BPS_1000K);
  CAN2.init(SystemCoreClock, CAN_BPS_1000K);

  // Initialize CAN1 mailbox 0 as receiver, frame ID is 0x07
  CAN2.mailbox_set_mode(0, CAN_MB_RX_MODE);
  CAN2.mailbox_set_accept_mask(0, 0x7FF, false);
  CAN2.mailbox_set_id(0, TEST1_CAN_TRANSFER_ID, false);

  // Initialize CAN0 mailbox 0 as transmitter, transmit priority is 15
  CAN.mailbox_set_mode(0, CAN_MB_TX_MODE);
  CAN.mailbox_set_priority(0, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_accept_mask(0, 0, false);
  // Prepare transmit ID, data and data length in CAN0 mailbox 0
  CAN.mailbox_set_id(0, TEST1_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(0, CAN_MSG_1);
  CAN.mailbox_set_datah(0, CAN_MSG_DUMMY_DATA);
  CAN.mailbox_set_datalen(0, MAX_CAN_FRAME_DATA_LEN);

  // Send out the information in the mailbox

  // Wait for CAN1 mailbox 0 to receive the data
  while (!(CAN2.mailbox_get_status(0) & CAN_MSR_MRDY)) {

  RX_CAN_FRAME incoming;
  // Read the received data from CAN1 mailbox 0
  CAN2.mailbox_read(0, &incoming);
  Serial.print("CAN message received= ");
  // Disable CAN0 Controller

  // Disable CAN1 Controller

  Serial.print("End of test");

  while (1) {

I get nothing on the serial monitor, i stripped all the sketch looking for the failure and ended with this!

void setup() {


void loop() {

And still get nothing!, now if i put the Serial.print on the loop it works, repeatedly of course. I tried the AnalogInOutSerial example and it works great, tried the loopback test and it runs fine, flashed the 16u2 firmware and same thing, tried both USB ports, tried adding “delay(500)” between Serial.begin and Serial.print and nada. I’m out of ideas, anyone saw something similar? or have an idea what else to try?.

Read: http://arduino.cc/en/Guide/ArduinoDue

In particular:

Native port

Opening and closing the ''Native' port at the baud rate of 1200bps triggers a “soft erase” procedure: the flash memory is erased and the board is restarted with the bootloader. If, for some reason, the MCU were to crash during this process, it is likely that the soft erase procedure wouldn't work as it's done in software by the MCU itself.

Opening and closing the Native port at a baudrate other than 1200bps will not reset the SAM3X. To use the serial monitor, and see what your sketch does from the beginning, you'll need to add few lines of code inside the setup(). This will ensure the SAM3X will wait for the SerialUSB port to open before executing the sketch:

while (!Serial) ;

Thanks Nick, i tried that and it still the same, i started to check the board and i found that i didn't have 3.3v on the reset button, i soldered a jumper from pin 47 of the SAM3X to the reset button and it works now resetting it manually, but i still have one problem the loop seems to halt if i include "if (Serial.read() == '\n') {" i tried this

void setup() {

  // start serial port at 9600 bps:
  while (Serial.available() == 0);


void loop() {
  while (Serial.available() > 0) {
   int CAN_MSG_1 = Serial.parseInt();
    if (Serial.read() == '\n') {
      Serial.print("Sent value= ");

on a duemilanove and it does't work either. =(

What if you try to put a little delay between Serial.begin and the Serial.print ?

What if you try to put a little delay between Serial.begin and the Serial.print ?

i tried that up to 1000ms, but anyway it is printing "start' now, it just halts the loop whenever i include "if (Serial.read() == '\n') {" please note that it is happening with a Duemilanove too, i will try an older IDE version as i'm using the 1.5 beta.