en 129
/
RasPiUsartTest
usart test
main.cpp
- Committer:
- nameless129
- Date:
- 2014-06-30
- Revision:
- 0:8848a3fcb99c
File content as of revision 0:8848a3fcb99c:
#pragma import __use_all_ctype #include "mbed.h" #include <stdlib.h> Serial pc(USBTX, USBRX); Serial pi(p9, p10); // tx, rx bool f_rcev = 0; unsigned int c_rcev = 0; char uartBuff[1000]; char uartRcev[1000]; void callback() { char buf = 0; buf = pi.getc(); uartBuff[c_rcev] = buf; if(uartBuff[c_rcev] == '\r' ) { uartBuff[c_rcev+1] = 0; memcpy(uartRcev,uartBuff,sizeof(uartRcev) ); memset(uartBuff,0,sizeof(uartBuff)); c_rcev = 0; f_rcev = 1; } else { c_rcev++; } } int main(void) { pi.baud(115200); pc.baud(115200); pi.attach(&callback); while (1) { if(f_rcev == 1) { // printf("\033[2J"); // printf("\033[1;1H"); // printf("%s\r\n",uartRcev); puts(uartRcev); f_rcev = 0; } } }