本帖最后由 foxmail-364565 于 2015-7-30 14:17 编辑 getc 只能收一个字节. scanf 需要字符串以换行符结尾. 如题,就是非阻塞方式接收一个字符串,感谢回复. STM32里有线路空闲中断,Mbed里没用到.
unsigned char Cnt = 0;
unsigned char UART_RXD[32];
Timeout UARTtimeout;
void UARTtimeoutFunc()
{
pc.printf("length = %d UART Revice OK\r\n",Cnt);
Cnt = 0;
}
void callback()
{
char buf[32];
UART_RXD[Cnt++] = pc.getc();
UARTtimeout.attach(&UARTtimeoutFunc, 0.010);
}
int main()
{
//Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4);
//pc.format(8,SerialBase::None,1);
////pc.baud(115200);
timer.attach(&attime, 0.2);
//event.fall(&trigger);
set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
Dac = 0.3;
tri = 0.7;
pc.attach(&callback);
while(1)
{
//pc.printf("length = %d\r\n",Cnt);
wait_ms(1000);
// pc.printf("Too hot! (%f)\r\n", temperature.read());
}
}
嗯,以前用8位的单片机时就是这样做的.
不能一直回复这样刷帖,警告,否则扣除金币了
http://www.freescaleic.org/module/forum/thread-600203-1-1.html
原来是用HAL库的,
但是MBed可以写出去单片机型号无关的代码,就想偷下懒.