Go Down

Topic: Using Serial Monitor with Native Port (Read 7203 times) previous topic - next topic

wholder

So far, I've only been able to use the Serial Monitor when I use the Programmer Port to talk to the Zero.  If I use the Native Port, nothing I print in the sketch seems to print out in the Serial Monitor window.  Is this by design, or am I missing something?

Wayne

Dirk67

#1
Jun 18, 2015, 08:51 am Last Edit: Jun 18, 2015, 09:02 am by Dirk67
did you try the serial1 function as well ?

on the updated product page there is written a lot about the serial ports:
http://www.arduino.cc/en/Main/ArduinoBoardZero

Quote
...
Atmel Embedded Debugger:

The Atmel Embedded Debugger (EDBG) implements a JTAG interface in order to program the on-board SAMD21 and is also connected to hardware serial of the microcontroller. This means that the 'Serial' class responds to the programming port of the board. The Arduino Zero has been designed in collaboration with ATMEL, and the on-board EDBG can be used through ATMEL Studio to get full access to the microcontroller memories to help debug your code.

Note:

in contrast to some Arduino boards (e.g. Uno), when you open the serial monitor and the board is connected through the Programming Port the board does not automatically reset. You can reset the board manually if you wish to restart your sketch, for example in order to see something that is printed in the setup() function.
...
Quote
...
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. These pins are connected to the Serial1 class.
...
reading that,
there is no way yet to use the native port as serial monitor, I think (?)
maybe later there will be introduced some "serialUSB"-class or something like that ?
("virtual USB" like on the leonardo ?)
arduino powered car relais / car "micro PLC" / with USB --> http://goo.gl/ofWFW3

cmaglie

To see data on the Native port you must use SerialUSB

So to recap we have:

Serial - Programming Port (the path is SAMD->uart->EDBG->usb->PC)
Serial1 - Serial uart on pins 0 and 1
SerialUSB - Native Port, this is an emulated serial port (USB-CDC)

If you are using SerialUSB and you want to see the very first data sent by the micro it's handy to put this snippet of code at the beginning of the sketch to make the CPU wait for someone to open the serial monitor:


  SerialUSB.begin(9600);
  while (!SerialUSB) {
    ; // wait for serial port to connect
  }


of course if you use this trick the sketch will not start until you open the serial monitor (i.e. it won't work standalone).
C.

cmaglie


on the updated product page there is written a lot about the serial ports:
http://www.arduino.cc/en/Main/ArduinoBoardZero
[.....]
there is no way yet to use the native port as serial monitor, I think (?)
 USB" like on the leonardo ?)
Dirk, you're right the doc page must be updated, I'll keep a note for that, thanks for spotting this out!
C.

Dirk67

#4
Jun 18, 2015, 04:39 pm Last Edit: Jun 18, 2015, 04:42 pm by Dirk67
I think on the "Guide" page ("getting started") it is written right (?) :
--> http://www.arduino.cc/en/Guide/ArduinoZero#toc4
arduino powered car relais / car "micro PLC" / with USB --> http://goo.gl/ofWFW3

cmaglie

Indeed it is in the getting started, but I guess it should be mentioned also on the product page.
C.

Rfuzer

I'm using the native port as emulated serial port (USB-CDC) with "SerialUSB" to write/read data from Serial Monitor. When I send a first message this code works well, but, when I send some others messages, the recived data are lost as if the buffer does not supply a message.

Here is my simple code:


void setup()
{

  SerialUSB.begin(115200);
  while (!SerialUSB) ;

}

void loop()
{
   String  aux = " ";
      SerialUSB.flush();
      while( SerialUSB.available() > 0 )
      {   
         char c = SerialUSB.read();
         aux += c;
      }
      if(aux != " ")
         SerialUSB.println(aux);

}

Rfuzer

SOLVED!

I solved my problem comment this line code in samd21_device.c:


uint8_t UDD_Recv_data(uint32_t ep, uint32_t len)
{
   TRACE_DEVICE(printf("=> UDD_Recvdata : ep=%d\r\n", (char)ep);)

->   //if (len>64) len=64;
   usb_endpoint_table[ep].DeviceDescBank[0].ADDR.reg = (uint32_t)&udd_ep_out_cache_buffer[ep];
->   //usb_endpoint_table[ep].DeviceDescBank[0].PCKSIZE.bit.MULTI_PACKET_SIZE = len;
   usb_endpoint_table[ep].DeviceDescBank[0].PCKSIZE.bit.BYTE_COUNT = 0;
   udd_OUT_transfer_allowed(ep);
   TRACE_DEVICE(printf("=> UDD_Recv_data : data=%lu\r\n", (unsigned long)data);)

   /* Wait for transfer to complete */
   while (!udd_is_OUT_transf_cplt(ep));
   /* Clear Transfer complete 0 flag */
   udd_clear_OUT_transf_cplt(ep);

   return udd_ep_out_cache_buffer[ep][0];
}



I discovered that when sending a string with a size x, the next string of the same size was read correctly. But if the next string had different size was not read correctly. So I commented the line where it was setted the size of the string to be read, getting this with a constant size. Now I have a 64 bytes size string that I can read without problems.

cmaglie

Hi Rfuzer,

thank you for sharing your solution, that's really valuable!

The UDD_Recv_data function has definitely a problem, we are investigating for a final fix.

Thanks!
C.

adamj537

#9
Jul 09, 2015, 12:21 am Last Edit: Jul 09, 2015, 08:09 pm by adamj537
Did Rfuzer's fix get loaded into the Arduino core yet?

EDIT:  As of Arduino 1.6.5, it does not appear to be in the core.

-Adam J.

Go Up