3 Replies Latest reply on Dec 21, 2014 5:55 PM by Electrumpet

    What are the allowed UART speeds on Edison (using breakout and Arduino IDE)

    Electrumpet

      Dear all,

       

      I am looking for the fastest baudrate possible on the Edison (UART1) and I saw some behaviour that suggests that certain speeds are allowed while others are not.

       

      I can use the board at 115200, 230400, 460800, 921600 but for example not at 600000 but I can use it at 500000. When I use a speed that is not supported the board will automatically pick 115200 as its speed (I checked with a scope). If I look at the hardware guide it suggests that speeds up to 3.686 Mbps are possible which suggest exactly four times the speed that I can see working. I tried that speed but it jumps back to 115.200 bps which also happens at 1.843 Mbps.

       

      Can anybody enlighten me here?

       

      Best, Hans.

        • 1. Re: What are the allowed UART speeds on Edison (using breakout and Arduino IDE)
          KurtE

          I am not sure these are the only valid Baud rates that the hardware can do, but if you look at the Arduino IDE code for the deviced (TTYUART.cpp)

          You see in the begin function:

          switch(dwBaudRate){
                  case 50:
                      _dwBaudRate = B50;
                      break;
                  case 75:
                      _dwBaudRate = B75;
                      break;
                  case 110:
                      _dwBaudRate = B110;
                      break;
                  case 134:
                      _dwBaudRate = B134;
                      break;
                  case 150:
                      _dwBaudRate = B150;
                      break;
                  case 200:
                      _dwBaudRate = B200;
                      break;
                  case 300:
                      _dwBaudRate = B300;
                      break;
                  case 600:
                      _dwBaudRate = B600;
                      break;
                  case 1200:
                      _dwBaudRate = B1200;
                      break;
                  case 1800:
                      _dwBaudRate = B1800;
                      break;
                  case 2400:
                      _dwBaudRate = B2400;
                      break;
                  case 4800:
                      _dwBaudRate = B4800;
                      break;
                  case 9600:
                      _dwBaudRate = B9600;
                      break;
                  case 19200:
                      _dwBaudRate = B19200;
                      break;
                  case 38400:
                      _dwBaudRate = B38400;
                      break;
                  case 57600:
                      _dwBaudRate = B57600;
                      break;
                  case 115200:
                      _dwBaudRate = B115200;
                      break;
                  case 230400:
                      _dwBaudRate = B230400;
                      break;
                  case 460800:
                      _dwBaudRate = B460800;
                      break;
                  case 500000:
                      _dwBaudRate = B500000;
                      break;
                  case B576000:
                      _dwBaudRate = B576000;
                      break;
                  case 921600:
                      _dwBaudRate = B921600;
                      break;
                  case B1000000:
                      _dwBaudRate = B1000000;
                      break;
                  case B1152000:
                      _dwBaudRate = B1152000;
                      break;
                  case B1500000:
                      _dwBaudRate = B1500000;
                      break;
                  case B2000000:
                      _dwBaudRate = B2000000;
                      break;
                  case B2500000:
                      _dwBaudRate = B2500000;
                      break;
                  case B3000000:
                      _dwBaudRate = B3000000;
                      break;
                  case B3500000:
                      _dwBaudRate = B3500000;
                      break;
                  case B4000000:
                      _dwBaudRate = B4000000;
                      break;
                  default:
                      _dwBaudRate = B115200;
                      break;
              }
          

          So I hope that helps

          Kurt

          • 2. Re: What are the allowed UART speeds on Edison (using breakout and Arduino IDE)
            Electrumpet

            Hi KurtE,

             

            Yes, this was it. Thanks for pointing this out. I had seen this before but your reaction triggered me to look again and there seems to be a mistake in the code. There are case switches with a B before the number which prevented the higher baudrates. Be careful though because I now cannot connect to my board after attempting the 4000000 baudrate. Before that everything went fine till 3000000.

             

            It worked well at 3500000 as well.

             

            There is another problem concerning the UART though and I think I have seen something similar described with SPI. The Serial.write command directed at an array of bytes will not spit out the numbers directly after each other but with a gap of about 50 micro seconds in between. Are there any solutions to this within the Arduino environment? Other library perhaps?

             

            Best, Hans.

            • 3. Re: What are the allowed UART speeds on Edison (using breakout and Arduino IDE)
              Electrumpet

              Dear all,

               

              I did some more testing and it seems that the gaps only apply to the Edison sending data as in Serial.write and Serial.print. When the Edison receives data from the serial bus it is super fast it seems. I connected a teensy board to the Edison sending 8 bytes of data in a Serial.write operation at a baudrate of 3500000, which would take 18 microseconds and is in practice 23 microseconds (oscilloscope). The teensy does not have the 'gap problem' of 50 microseconds between bytes that the Edison seems to have. The Edison had no problems keeping up following though (I lowered the logic level from the teensy simply with voltage dividing resistors). The read operation from the bus takes even less time at on average 8 microseconds for a bus read of 8 bytes.

               

              I guess there is some routine somewhere in the Arduino/Edison IDE that deliberately waits for about 50 microseconds between byte sends. I looked through the Edison Arduino cores and could not find where the problem hides. It is remarkable that two Serial.print(byte) operations in succession seem to have exactly the same delay. Hopefully somebody else can find the problem here?

               

              Luckily my test showed that the Edison is very suitable to connect to peripheral micro controllers. In my case two teensy's collecting data from a sensor array and a position / gestural device respectively and thus I will now be able to send a large bulk of sensor data with very low latency over WIFI to my computer. This is very promising for more complex wireless electronic musical instruments that require low latency operation.

               

              I used this small sketch to test and the oscilloscope to verify the signal.

               

              char receiveArray[] = { 0, 0, 0, 0, 0, 0, 0, 0 };

              long timeBefore = 0;

              long timeAfter = 0;

              int readTime = 0;

               

              void setup() {

                Serial1.begin(3500000); // 460800, 921600

                Serial.begin(115200);

              }

               

              void loop() {

                while (Serial1.available() == 8) {

                timeBefore = micros();

                Serial1.readBytes(receiveArray,8);

                timeAfter = micros();

                readTime = timeAfter - timeBefore;

                  Serial.println(readTime);

                }

                delayMicroseconds(1);

              }

               

              And on the teensy

               

              byte EdisonUartTest [8] = { 1, 2, 3, 4, 5, 6, 7, 8 };

               

              void setup() {

                // initialize serial communications at 9600 bps:

                Serial1.begin(3500000);

              }

               

              void loop() {

                for (byte i = 0; i < 256; i++) {

                  EdisonUartTest [7] = i;

                  Serial1.write(EdisonUartTest, 8);

                  delay(1000);

                }                   

              }