Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 2 of 2

Thread: Serial Communication Error on Teensy 3.0 -- Com Port Closes After Read/Write Failure

  1. #1
    Junior Member
    Join Date
    Apr 2014

    Serial Communication Error on Teensy 3.0 -- Com Port Closes After Read/Write Failure

    I am trying to talk to my Teensy using serial commands, but after several successful queries and responses, I see a Write Error, and then the Port can't be opened until I physically disconnect and reconnect the USB cable.

    This behavior occurs on Windows 7 both through the Arduino serial monitor and through a putty session with the Teensy's port, as captured in the pictures below. Occasionally I can repon the serial monitor or putty session after the error without getting a com port error, but it disappears often enough that it's a problem.

    Click image for larger version. 

Name:	arduino error.jpg 
Views:	470 
Size:	91.2 KB 
ID:	1837Click image for larger version. 

Name:	arduino error 2.jpg 
Views:	457 
Size:	70.6 KB 
ID:	1838Click image for larger version. 

Name:	putty error.jpg 
Views:	359 
Size:	50.8 KB 
ID:	1839Click image for larger version. 

Name:	putty error 2.jpg 
Views:	493 
Size:	18.6 KB 
ID:	1840

    It also happens on ubuntu 12.04 when I use the screen command (screen /dev/ttyACM0 9600) in a terminal session; I query the Teensy and get a response several times, but eventually the screen session terminates right after I send a query (displays [screen is terminating]). I don't get a "com port error" on this OS -- I can use the screen command again without reconnecting the cord.

    I've pared my code down to an edited version of the mac address program in this post: . My version, which I will attach to this post, edits the main loop to wait for a query from the user (a "?") before printing out the mac address. Eventually I will be interfacing with the Teensy through pyserial, and will be using this query/response technique for a variety of functions. I've narrowed down this problematic behavior to this simple code though, so I'd like to debug this first.

    Other information:
    This behavior occurs on multiple Teensy boards.
    If I have my device manager on Windows open when the write error occurs, I can see it (the device manager) refresh, which indicates that the com port has closed/disappeared. However, the Teensy is still visible on the same com port in the device manager list -- but I still can't talk to it without reconnecting the cable.

    This is my first project using Teensy, and I'd appreciate any help or advice. Is it a timing issue, or does it have to do with the transmit buffering on the Teensy's side? Thanks in advance!
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Apr 2014
    After further investigation, it looks to be an issue with the mac address code.

    I hooked up an FTDI USB TTL Serial cable and used the UART example code on this page: . This works perfectly, through both the regular USB cable (using Serial) and through the UART (using Serial1/HWSerial in that code).

    However, when I try to combine the Serial1 functionality with the mac address code, I see the same issue, where the Teensy seems to disappear and fails to respond.

    I am stepping through the mac code now, but would appreciate other people taking a look. I attached it above, but here it is again, in case you don't feel like downloading it. It's from this post:

    #include "mac.h"
    int SWVersion = 1020;
    void setup() {
    //  Serial.println("Reading MAC from hardware...");
    //  read_mac();
    //  Serial.print("MAC: ");
    //  print_mac();
    //  Serial.println();
    //  Serial.print("Finished.");
    void loop() {
      if (Serial.available()){
        int inbyte;
        inbyte =;
        if (inbyte == '?'){
    #include "mac.h"
    uint8_t mac[6];
    void read(uint8_t word, uint8_t *mac, uint8_t offset) {
      FTFL_FCCOB0 = 0x41;             // Selects the READONCE command
      FTFL_FCCOB1 = word;             // read the given word of read once area
      // launch command and wait until complete
      while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF));
      *(mac+offset) =   FTFL_FCCOB5;       // collect only the top three bytes,
      *(mac+offset+1) = FTFL_FCCOB6;       // in the right orientation (big endian).
      *(mac+offset+2) = FTFL_FCCOB7;       // Skip FTFL_FCCOB4 as it's always 0.
    void read_mac() {
    void print_mac()  {
      size_t count = 0;
      for(uint8_t i = 0; i < 6; ++i) {
        if (i!=0) count += Serial.print(":");
        count += Serial.print((*(mac+i) & 0xF0) >> 4, 16);
        count += Serial.print(*(mac+i) & 0x0F, 16);
    #include <Arduino.h>;
    extern uint8_t mac[6];
    void read_mac();
    void print_mac();
    To use a USB to Serial cable like mine, change Serial to Serial1 (or whichever port you're using) in the code.

    I've also tried baud rates of 9600 and 115200, with the same results all around.

    Thanks for your help!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts