2016年3月14日 星期一

Raspberry Pi UART speed changing.

This is done on a RPI2 with Jessie, Rasbpian installed.

Changing UART baud rate, using "stty" command.
$ stty -F /dev/ttyAMA0
speed 115200 baud; line = 0;
-brkint ixoff -imaxbel iutf8
-iexten

The result without baudrate set, is showing the current baud rate.
Next is to change it.
$ stty -F /dev/ttyAMA0 230400
stty: /dev/ttyAMA0: unable to perform all requested operations

Seems speed cannot be changed, result still showing in previous baudrate (115200 baud in my case).

Then try a lower speed UART, 57600 baud:
$ stty -F /dev/ttyAMA0 57600
" some scrambled text shown....".  As terminal is still setting at 115200 baud.
Changing my Teraterm's baudrate to 57600 baud and type "Enter" several times, and I can see the normal prompt showing.  i.e. baudrate changed to 57600 successfully.

Next you can try setting back to 115200 baud with same prcedure.  It works for me.

Then try increasing the UART input clock to make faster UART speed possible.
$ sudo vi /boot/config.txt
Insert in last line:
init_uart_clock=16000000

Save the file, and sudo reboot.

System rebooted, and scrambled text appeared which should be boot up logs.
Now try changing the Teraterm terminal's baudrate to 4 times faster, 460800 baud.
Normal text can be seen again.

After logged in, check UART speed using command again:
$ stty -F /dev/ttyAMA0
speed 460800 baud; line = 0;
-brkint ixoff -imaxbel iutf8
-iexten

New speed shown!!!

Wait!  The UART option of my FTDI USB-to-UART cable shows maximum of 921600 baud.
I think I shall have a try.  Changing the /boot/config.txt line to:
init_uart_clock=32000000

Reboot again, scrambled text appear again!  Teraterm setting change to 921600 baud, maximum for my FTDI chip & Win 10 driver.  Normal text appeared again, the speed is now near 1M baud:
$ stty -F /dev/ttyAMA0
speed 921600 baud; line = 0;
-brkint ixoff -imaxbel iutf8
-iexten

Now try if this speed can really transfer large files.  Using my favourite zmodem protocol.
Install the sz & rz in Raspbian:
sudo apt-get install lrzsz

Zmodem sending file from Win 10 PC to RPI2, at average data rate is 57.5kB/s.
Since this is in bytes of unit, N81, should include at least 1 start bit, 8 data bit and 1 stop bit.
So, exclude any zmodem rate control headers, the baud rate must be >575k baud.
15% of 107,466,570 bytes; for 4:40 minutes or 280 seconds.
i.e. 57.57kB/s.

Then sending file from RPI2 back to PC, speed is now 68.2kB/s.
Faster than transferring in other direction.  The same file compared, no problem found.

(Note: if the file size is too large, you may escape the transfer by pressing CTRL-X repeatedly on the receiving side after pressed ESC key.)

This file transfer method is good when you are writing programs where size is at most several tens of KB.  If file size too big, better use RJ45 LAN port where transfer rate can be up to 11MB/s.

2016年3月9日 星期三

RPI2 power supply.

Without any hardware peripheral attached to a Raspberry Pi 2 (RPI2) unit.
No display, LAN connection to WIFI router, RPI2 actually consume not much power (as comparing to normal Android phones).

I have two Samsung mobile phone travel adapter (of same model).   It is rated 5.0V @1.0A, as it is not one for those high-end phone models.  With an AC power meter and USB current/power meter, it shows that the power consumption of adapters can be around 7.5W.  With about 78% power efficiency when full loaded.  So, they have some output capability of about 5.0V @1.15A.

Usually, those phone adapters have no load self cut-off feature, so that it consumes almost no power when there is no loading.

I used this Samsung adapter for RPI2, and do some measurements.  Power is measured using my AC power meter.  Samsung 5.0V, 1.0A USB AC-DC adaptor + 1.5m switched USB cable.

1. 5.0V AC-DC adaptor powered, without connection to RPI2.  AC-DC adaptor is without LED typed.
Power = 0.00W (No load power lost)

2. Just power ON, FTDI USB-to-UART cable connected without logging in RPI2, or just logged in & stayed for a minute.
Power = 1.73W

3. "sudo init 3" command issued, X server shut down.
Power = 1.70W

4. Minutes after "sudo poweroff" command issued, and "[__timestamp__] reboot: Power down" shown.
RED power LED on RPI2 still shown.
Power = 0.55W

When I am typing text in Linux command prompt, the total power usage is only around 2.5W.

The use of 5.0V on RPI2 seems only powers the HDMI part, without HDMI output.  Other part of 3.3V & 1.8V are generated by the on-board switching power buck DC-DC, some input power variation is no problem to the system.  So, I believe a normal Li-ion battery can power the RPI2; providing 3.5V - 4.3V to micro-USB power port should be fine for RPI2's operations.