라즈베리파이-UART
Posted 2016. 10. 5. 14:49라즈베리파이2로 진행
일단 프로그램으로 들어가기 전에 라즈베리파이 setting상태를 점검해보자.
Raspberry Pi는 기본적으로 UART를 콘솔이 사용하도록 설정되어 있다.
제어 프로그램이 UART를 사용하려면 콘솔이UART를 잡고 있지 않도록 설정해 줄 필요가 있다.
현재 사용하고 있는 STM32보드와 시리얼 통신을 해보자.
1. cmdline.txt 파일 수정 : SD를 열어보면
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
으로 설정되어있다. 'console=ttyAMA0,115200' 부분을 삭제해준다.
2./etc/inittab 파일도 수정
$sudo nano /etc/inittab
'ttyAMA0'가 있는 라인 맨 앞줄에 #을 붙여준 후 저장 -> 수정 후 나가기(Ctrl+x) - >저장 y 엔터
$sudo reboot
테스트 프로그램을 작성해보자.
wringPI 기반으로 작업하였다.
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <wiringPi.h>
#include <wiringSerial.h>
int main ()
{
int fd ;
int count ;
unsigned int nextTime ;
if ((fd = serialOpen ("/dev/ttyAMA0", 9600)) < 0)
{
fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
return 1 ;
}
if (wiringPiSetup () == -1)
{
fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ;
return 1 ;
}
nextTime = millis () + 300 ;
for (count = 0 ; count < 256 ; )
{
if (millis () > nextTime)
{
printf ("\nOut: %3d: ", count);
fflush (stdout);
serialPutchar (fd, count);
nextTime += 300;
++count;
}
delay (3) ;
while (serialDataAvail (fd))
{
printf (" -> %3d", serialGetchar (fd)) ;
fflush (stdout);
}
}
printf ("\n");
return 0;
}
'MAKE. > 라즈베리파이' 카테고리의 다른 글
라즈베리파이-UART (0) | 2016.10.05 |
---|---|
라즈베리파이3-GPIO (0) | 2016.09.07 |
라즈베리파이2-SPI통신 (0) | 2016.09.04 |
라즈베리파이2-터치스크린 케이스& (0) | 2016.07.23 |
라즈베리파이2-공식 7인치 터치스크린 (0) | 2015.11.29 |
라즈베리파이2-라즈비안설치 (0) | 2015.11.25 |
- Filed under : MAKE./라즈베리파이
- Tag : uart, 라즈베리파이
- 0 Comments 0 Trackbacks