Last active
November 19, 2018 20:47
-
-
Save plusangel/802efbc98232c1f95c6b485783c1730a to your computer and use it in GitHub Desktop.
RIOT-OS serial comm in arduino m0 pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include "board.h" | |
#include "msg.h" | |
#include "thread.h" | |
#include "periph/uart.h" | |
#define PC_UART UART_DEV(1) | |
#define BAUDRATE (115200U) | |
static kernel_pid_t main_thread_pid; | |
static void rx_cb(void *uart, uint8_t data) | |
{ | |
//printf("receive\n"); | |
msg_t msg; | |
msg.type = (int)uart; | |
msg.content.value = (uint32_t)data; | |
//printf("[callback]: %d\n", data); | |
msg_send(&msg, main_thread_pid); | |
} | |
int main(void) | |
{ | |
printf("UART test\n"); | |
printf("=========\n"); | |
uart_init(PC_UART, BAUDRATE, rx_cb, (void *)PC_UART); | |
main_thread_pid = thread_getpid(); | |
msg_t msg; | |
//char* myarray = "ab"; | |
for(;;) | |
{ | |
msg_receive(&msg); | |
printf("[main thread]: %c\n", (char)msg.content.value); | |
//uart_write(PC_UART, (const uint8_t*)myarray, strlen(myarray)); | |
} | |
return 0; | |
} | |
/* | |
void setup() { | |
Serial1.begin(115200); | |
delay(1000); | |
} | |
void loop() { | |
Serial1.print("a"); | |
delay(100); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment