I decided to try 1M baud initially on the standard Serial port. The code I used is as follows:
void setup()
{
Serial.begin(1000000);
}
void loop()
{
unsigned int a = 0;
do
{
Serial.println(a);
} while (++a > 0);
}
I didn't even consider using the standard Serial Monitor application built into the IDE and instead grabbed a copy of PuTTY and set the serial port up at 1000000 baud.
At this baud rate, the Arduino had no issues and PuTTY correctly decoded the serial stream without issue. So, if 1M is good, then 2M should be twice as good, right?
Well, not exactly. at 2,000,000 baud the per character rate is twice the rate, but the overall throughput actually dropped visibily. By my crude measurements, the throughput dropped by about 15%. But, it is good to know that Arduino can push serial bits out at a respectable speed.
One side effect to note is that the IDE must override the Serial baud rate in order to program the device. When running at these very fast serial rates, it can be a bit hit and miss. If you have trouble, press the reset button and release it just before the compile finishes and you will help it recover. Another alternative would be to use an external ISP programmer.
Another thing to keep in mind is that the IDE and PuTTY are both going to try and use the same COM port. The IDE will use it for programming the chip. PuTTY will use it to monitor the serial output. In order for the IDE to be able to program the chip, it must be able to open the serial port. So, you will have to terminate PuTTY before attempting to reprogram the Arduino.
I have read a lot of complaints lately about trying to debug Arduino code with the serial port output. While upping the serial speed will not help in situations where interrupts are disabled or where time required to output debug data adversely affects the running code, being able to output the data orders of magnitude faster is certainly going to help in general. If you are doing a lot of edit, compile, flash, run cycles, it might be better to use an ISP programmer so that PuTTY or whatever serial terminal application you use can stay connected to the debug serial port.
In my work with faster embedded processors, 2-3M baud is about the limit even on these devices with much faster core and peripheral clocks. The Freescale K60 for example is running at 96 MHz in my configuration and at 2M baud on the debug port, I still get data loss, but it is solid at 1M baud. I think that for high speed output or where you need to output debug information during interrupt processing, it may be a better choice to use SPI for debug output to a dedicated device that can capture and save the output such as a PC with a USB/SPI interface or another Arduino that can write to a storage device such as an SD card.
No comments:
Post a Comment