본문 바로가기

[ATMEL]/SAMD21

ATSAMD21 Arduino M0 보드 테스트 - 시리얼 포트

ATSAMD21 Arduino M0 보드 테스트 - 시리얼 포트

Arduino 기본 예제로 시리얼 포트 출력을 해 봤는데... 정상 출력이 안된다.
무엇이 문제 일까?

void setup() {
  Serial.begin(115200);
}


void loop() {
  // read the analog in value:
  sensorValue = analogRead(A0);

  Serial.println(sensorValue);

  delay(200);
}


자료를 찾아보니 Arduino Zero 는 3개의 시리얼 포트를 사용할 수 있고 SDAMD21의 USB 를 이용한 CDC 포트는 SerialSUB 라는 클래스 이름으로 등록 되어 있고 UART0 ( PA10(TX), PA11(RX))는  Seial1으로 등록되어 있다.




초기화시에 필요한 UART를 등록해서 사용하면 된다.



void setup() 
{
  // initialize serial communications at 9600 bps:
  
  Serial1.begin(9600);   //PA10(TX), PA11(RX)
  
  SerialUSB.begin(9600); //SAMD21 CDC native serial
}


void loop() {
  // read the analog in value:
  sensorValue = analogRead(A0);

  Serial1.print(sensorValue);
  SerialUSB.println(sensorValue);

  delay(200);
}

반응형