Presentation is loading. Please wait.

Presentation is loading. Please wait.

임베디드 프로그래밍 Lecture #05 2017. 10. 29.

Similar presentations


Presentation on theme: "임베디드 프로그래밍 Lecture #05 2017. 10. 29."— Presentation transcript:

1 임베디드 프로그래밍 Lecture #05

2 목 차 UART 통신 테스트 UART Console 테스트 UART 장치 통신 테스트

3 UART 직렬 통신 (1) UART 직렬 통신 Universal Asynchronous Receiver/Transmitter
별도의 클록 라인이 없이 양 장치 간에 정해진 클록 속도에 맞추어 통 신하는 비동기식 직렬 통신 방식 동기식 직렬 통신 비동기식 직렬 통신 병렬 통신

4 UART 직렬 통신 (2) UART 직렬 통신 규칙(Rules) UART 직렬통신 Baud Rate Data bits
Synchronization bits Parity bits Baud rate UART 직렬통신 Baud Rate 전송 속도 - how fast data is sent over a serial line bits-per-second (bps) 로 표시 표준 baud rate: 1200, 2400, 4800, 9600, 9200, 38400, 57600,

5 UART 직렬 통신 (3) UART 직렬통신 data chunk 9600 8N1
9600 baud, 8 data bits, no parity, and 1 stop bit one of the more commonly used serial protocols “OK” 문자열 전송 비트열: LSB MSB

6 UART 직렬 통신 (4) UART 직렬 통신 – 연결 구조 및 전송 신호 TTL Serial Signals
RS-232C Serial Signals 신호선 연결 구조

7 UART Console 테스트 (1) UART Console 테스트 라즈베리파이는 기본적으로 UART 포트를 콘솔 포트로 설정
연결 방식: Usb-Serial Cable PC – terminal program Raspberrypi 3

8 UART Console 테스트 (2) UART Console 테스트 Console 로그인 화면

9 UART Console 테스트 (3) 기본 설정 UART 포트를 사용하기 위해 우선 Bluetooth 기능을 중지하여야 함.
라즈베리파이로 ssh 접속 $ sudo nano /boot/config.txt config.txt 파일 끝에 다음 두 줄 추가 후에 저장 # disable Bluetooth dtoverlay=pi3-disable-bt $ sudo systemctl disable hciuart $ sudo reboot

10 UART Console 테스트 (4) 기본 설정 Bluetooth 기능 재설정 라즈베리파이로 ssh 접속
$ sudo nano /boot/config.txt config.txt 파일 끝에 추가한 두 줄을 제거 # disable Bluetooth # dtoverlay=pi3-disable-bt $ sudo systemctl enable hciuart $ sudo reboot

11 UART Console 테스트 (5) 기본 설정 UART console 포트 사용 설정
raspi-config 툴을 사용하여 설정

12 UART Console 테스트 (6) 기본 설정 UART console 포트 사용 설정

13 UART Console 테스트 (7) 기본 설정 UART console 포트 사용 설정
/boot/cmdline.txt 파일에서 console 설정 확인

14 UART Console 테스트 (8) 아두이노를 활용한 UART console 테스트
아두이노를 USB-Serial 케이블을 대용으로 사용 아두이노는 다수의 UART 채널을 제공(Software UART 포함) PC RaspberryPi UART #0 Arduino UART #1 UART USB

15 UART Console 테스트 (9) 아두이노를 활용한 UART console 테스트 Arduino MEGA를 이용한 연결
USB 연결 Pin 연결 18 10 19 8 GND 39

16 UART Console 테스트 (10) 아두이노를 활용한 UART console 테스트
Arduino sketch 프로그래밍 : MultiSerial 예제 활용

17 UART Console 테스트 (11) 아두이노를 활용한 UART console 테스트 Arduino Serial 모니터 화면

18 UART 장치 통신 테스트 (1) 라즈베리파이의 UART 장치 통신 (1) 라즈베리파이는 외부 장치와의 UART 통신 가능
주로 통신 모뎀, 영상입력장치 등을 연결할 때에 사용 raspi-config 툴을 이용하여 console 포트 기능을 중지(disable) 하여야 함

19 UART 장치 통신 테스트 (2) 라즈베리파이의 UART 장치 통신 (2)

20 UART 장치 통신 테스트 (3) 아두이노와의 UART 통신 Arduino와의 UART 연결을 이용한 데이터 통신을 실험
연결 구조는 앞의 예제에서의 하드웨어 구성을 사용

21 UART 장치 통신 테스트 (4) 아두이노 프로그래밍 Arduino sketch 프로그램: MultiSerial 예제 활용

22 UART 장치 통신 테스트 (5) 라즈베리파이 프로그래밍 - 테스트 프로젝트 생성
NetBeans IDE에서 새로운 프로젝트 생성 프로젝트명: UARTComm_Test 프로젝트 속성 설정에서 라이브러리 추가 lib 디렉토리 생성 dio.jar 파일을 lib 디렉토리로 복사 프로젝트 속성에서 dio.jar 라이브러리 추가

23 UART 장치 통신 테스트 (6) 라즈베리파이 프로그래밍 uartcomm_test/UARTComm_Test.java 파일 작성
public UARTComm_Test(String controllerName) throws IOException { if (controllerName == null) controllerName = "ttyAMA0"; UARTConfig config; config = new UARTConfig( controllerName, 1, 9600, UARTConfig.DATABITS_8, UARTConfig.PARITY_NONE, UARTConfig.STOPBITS_1, UARTConfig.FLOWCONTROL_NONE ); uart = (UART)DeviceManager.open(config); in = new BufferedReader(Channels.newReader(uart, "UTF-8")); out = new BufferedWriter(Channels.newWriter(uart, "UTF-8")); uart.setReceiveTimeout(100); } package uartcomm_test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.nio.channels.Channels; import java.util.Scanner; import jdk.dio.DeviceManager; import jdk.dio.uart.UART; import jdk.dio.uart.UARTConfig; public class UARTComm_Test { private UART uart; private BufferedReader in; private BufferedWriter out;

24 public void run() throws IOException {
Scanner input = new Scanner(System.in); System.out.print("input message or 'q'(quit): "); byte[] message; for (String line = input.nextLine(); !line.equals("q"); line = input.nextLine()) { message = line.getBytes(); out.write(line); out.newLine(); out.flush(); System.out.println("Arduino: " + in.readLine()); } close(); private void close() throws IOException { in.close(); out.close(); uart.close(); /** args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here UARTComm_Test echo = new UARTComm_Test(args.length == 1 ? args[0] : null); echo.run(); }

25 UART 장치 통신 테스트 (7) 라즈베리파이 프로그래밍 - 설정 파일 추가 및 수정
“lib” 디렉토리에 장치 레지스트리 파일 및 보안 정책 파일 추가 build.xml 파일 수정

26 UART 장치 통신 테스트 (8) 설정 파일 – 장치 레지스트리 파일 실행시간에 장치 설정을 변경
# RPi3 header pins 1 = deviceType: gpio.GPIOPin, pinNumber:4, name:GPIO4, predefined:true 2 = deviceType: gpio.GPIOPin, pinNumber:7, name:GPIO7, mode:4, direction:1, predefined:true 3 = deviceType: gpio.GPIOPin, pinNumber:17, name:GPIO17, predefined:true 4 = deviceType: gpio.GPIOPin, pinNumber:18, name:GPIO18, mode:4, direction:1, predefined:true 5 = deviceType: gpio.GPIOPin, pinNumber:22, name:GPIO22, predefined:true 6 = deviceType: gpio.GPIOPin, pinNumber:23, name:GPIO23, mode:2, direction:0, predefined:true 7 = deviceType: gpio.GPIOPin, pinNumber:24, name:GPIO24, mode:2, direction:0, predefined:true 8 = deviceType: gpio.GPIOPin, pinNumber:25, name:GPIO25, mode:4, direction:1, predefined:true 9 = deviceType: gpio.GPIOPin, pinNumber:27, name:GPIO27, predefined:true 100 = deviceType: uart.UART, controllerName:ttyAMA0, name:ttyAMA0, baudRate:19200, dataBits:8, parity:0, stopBits:1, flowControl:0, predefined:true 300 = deviceType: spibus.SPIDevice, name:SPI0.0, controllerNumber:0, address:0, csActive:1, wordLength:8, clockFrequency:500000, clockMode:1, bitOrdering:1, predefined:true gpio.GPIOPin = initValue:0, controllerNumber:0, direction:0, mode:2, trigger:1, predefined:true uart.UART = baudRate:19200, parity:0, dataBits:8, stopBits:1, flowControl:0, predefined:true

27 UART 장치 통신 테스트 (9) 설정 파일 – 보안 정책 파일 // policy for DIO framework
grant { // Very permissive permissions permission jdk.dio.DeviceMgmtPermission "*:*", "open"; permission jdk.dio.gpio.GPIOPinPermission "*:*"; permission jdk.dio.i2cbus.I2CPermission "*:*"; permission jdk.dio.spibus.SPIPermission "*:*"; permission jdk.dio.uart.UARTPermission "*:*"; };

28 UART 장치 통신 테스트 (10) build.xml 파일 수정

29 UART 장치 통신 테스트 (11) 프로젝트 속성 설정 수정 Sources / Run 속성 수정

30 UART 장치 통신 테스트 (12) 원격 실행 NetBeans Output 화면에서는 데이터 입력을 지원하지 않음
터미널 화면에서 실행 라즈베리파이로 ssh 접속 바이너리 배포 디렉토리로 이동 $ cd ~/NetBeansProjects/UARTComm_Test java 명령을 이용하여 실행 $ java -Djdk.dio.registry=dist/lib/dio.properties-raspberrypi -Djava.security.policy=dist/lib/java.policy -jar dist/UARTComm_Test.jar

31 UART 장치 통신 테스트 (13)


Download ppt "임베디드 프로그래밍 Lecture #05 2017. 10. 29."

Similar presentations


Ads by Google