13 Communication Serial ChinShiuh Shieh http bit kuas
智慧電子應用設計導論(1/3) Communication - Serial Chin-Shiuh Shieh (謝欽旭) http: //bit. kuas. edu. tw/~csshieh Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 1
Communication • Built-in – UART – SPI – TWI/I 2 C • Software – UART – One. Wire –… Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 2
Advanced Communications • • PC Smart Phone/Bluetooth Internet/ Wi. Fi, Ethernet Wireless UART GSM GPS … Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 3
Serial -Functions • • • if (Serial) available() begin() end() find. Until() flush() parse. Float() parse. Int() Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 4
Serial –Functions (cont) • • • peek() println() read. Bytes() read. Bytes. Until() set. Timeout() write() serial. Event() Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 5
Example – available/read void setup() { Serial. begin(9600); Serial 1. begin(9600); } void loop() { Serial 1. println("Hello, Arduino!"); delay(500); while(Serial. available()) { Serial. print(char(Serial. read())); } delay(500); } Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 6
Example – find/parse void setup() { Serial. begin(9600); } void loop() { if(Serial. find("Speed=")){ Serial. println(Serial. parse. Int()); } } Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 7
RS-232 Programming on PC • My personal choice – Borland C++ Builder 5. 0 – Com. Port Library version 2. 64 by Paul Doland – TMS Instrumentation Workshop by TMS Software • http: //bit. kuas. edu. tw/~csshieh/teach/101 A /mc/advanced/index. html#PCC Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 8
Example – TMSIW_02 • http: //bit. kuas. edu. tw/~csshieh/teach/101 A/mc/a dvanced/pcc 02. zip on PC void setup() { int i; Serial. begin(9600); for(i=0; i<8; i++)pin. Mode(14+i, OUTPUT); } void loop() { unsigned char x; int i; while(Serial. available()) { x=Serial. read(); for(i=0; i<8; i++) {digital. Write(14+i, bit. Read(x, i)); } Serial. write(analog. Read(A 0)/4); delay(100); } } Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 9
Example – TMSIW_03 • http: //bit. kuas. edu. tw/~csshieh/teach/101 A/mc/a dvanced/pcc 03. zip on PC void setup() { Serial. begin(9600); } void loop() { Serial. write(analog. Read(A 0)/4); delay(100); } Autumn, 2014 C. -S. Shieh, EC, KUAS, Taiwan 10
- Slides: 10