atmega128 usart 프로그램에서 write함수에 대해서 질문드려요

콩수니의 이미지

안녕하세요 atmega128과 리눅스와 usart 간단한 usart 통신 프로그램을 짜고있는데요

궁굼한것과 잘안되는점이 있어서 질문드립니다.
먼저 atmega128쪽은 인터럽트 방식으로 하는 usart통신을 구성하였습니다
일부 소스를 제외하고 메인 소스와 수신쪽 소스입니다

메인 소스부분
----------------------------

    while (1) {                                   
    PORTA.0=0xff;
    delay_ms(500);    
    PORTA.0=0;                                 
    delay_ms(500); 
    }

---------------------------
수신부분
interrupt [USART0_RXC] void usart0_rxc(void) 
{
 
    ch = UDR0; 	    // 수신 버퍼로부터 데이터 읽어 char ch 에 저장    
    PORTA =0xff; 
    delay_ms(3000); 
 
 
	UCSR0B |= 0x20;  
}

간단히 보시면 알겠지만 감빡 거리다가 신호가 오면 3초가 불이 계속 켜져있는 프로그램입니다
그리고 c 소스로 atmega128쪽에 usart 통신을 하려합니다.
리눅스에서 실행할 c 소스
#include <stdio.h>
#include "Serial.h"
 
int main(){
 
int nSerial;
char a='a';
nSerial = OpenAtmega(); //"Serial.c에서 만든 함수입니다. 연결을 해주고 serial값을 넘겨줍니다.
write(nSerial,'a',5); 
return 0;
}

-----------------------------
위에 소스 처럼 하면 usart쪽에서 제가 원하는 반응이 옵니다
근데 궁굼한건
write(nSerial,a,5); 이함수에서 5를 1이나 2,3,4로 하면 안됩니다. 5이상에 숫자를 하면 되더군요.
5가 보낼 버퍼에 크기로 알고있는데 잘 모르겠네요

그리고 만약 atmega128쪽 수신 소스를 아래와 같이 수정하면 if문을 걸었습니다,

interrupt [USART0_RXC] void usart0_rxc(void) 
{
 
    ch = UDR0; 	    // 수신 버퍼로부터 데이터 읽어 char ch 에 저장    
   if(ch=='a'){ 
   PORTA =0xff; 
    delay_ms(3000); 
   }
 
    UCSR0B |= 0x20;  
}

문자 a가올때만 작동하도록 하였습니다
그리고 리눅스 c에서 write(nSerial,'a',5); 라고 작성하고
실행하면 atmega가 반응이 없어요
인코딩쪽 문제인가요??

결국 2가지 질문입니다
1.write()함수에 세번째 인자가 정확히 어떤 역할을하는지?
2.리눅스 c에서 'a' 라고 신호를 보냈을때 atmega에서 if(ch=='a') 라고 해놓았을때 신호를 받고도 왜 같다고 하지 않는지.
입니다.

간단한거같은데 다소 질문이 길어졌네요.
답변 부탁드립니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.