Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: tracking_ball_0516 tracking_ball_0516
Revision 3:57962324a4a0, committed 2021-05-29
- Comitter:
- helenh
- Date:
- Sat May 29 09:28:16 2021 +0000
- Parent:
- 2:a668eb71516b
- Child:
- 4:82765e1fd9db
- Commit message:
- s
Changed in this revision
| Serial_Transport.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Serial_Transport.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Serial_Transport.cpp Mon May 24 08:56:23 2021 +0000
+++ b/Serial_Transport.cpp Sat May 29 09:28:16 2021 +0000
@@ -25,6 +25,8 @@
+Serial pc(SERIAL_TX, SERIAL_RX);
+
//对环形数组的操作
//判断是否为空
unsigned char Serial_class::HasRecv(void)
@@ -75,7 +77,7 @@
{
infor_struct.recv_buff[infor_struct.count]=recv;
infor_struct.value*=10;
- infor_struct.value+=recv-0x30;
+ infor_struct.value+=(recv-0x30);
infor_struct.count++;
}
break;
@@ -94,16 +96,21 @@
//采用中断方式接收串口信息,设置中断处理函数
void Serial_class::Do_Recv()
{
- //pc.baud(115200);
+
//临时存储接收的字符串
//char buff[RECV_BUFFER_SIZE];
char tem;
+ pc.printf("interupt begin");
//unsigned char length;
//unsigned char i;
//
// pc.printf("successful");
+
+ //调试用
- while (s_port->readable() == true)
+ while(true)
+ {
+ while(s_port->readable() == true)
{
//先读取到临时存储区。
@@ -113,8 +120,8 @@
//依次写入环形数组。
tem=s_port->getc();
Add_Char(tem);
- //pc.printf("%c",tem);
- //pc.printf("successful");
+ pc.printf("received char is %c",tem);
+ pc.printf("read successful");
//rw_mutex.lock();
//for(i=0;i<length;i++)
//{
@@ -123,7 +130,10 @@
//
//}
//rw_mutex.unlock();
- }
+ }
+ *pled = !(*pled);
+ ThisThread::sleep_for(200);//wait(0.100);
+ }
}
@@ -187,11 +197,11 @@
*/
-
-
//构造函数
Serial_class::Serial_class(PinName tx, PinName rx)
-{
+{
+ pc.baud(115200);
+ pc.printf("begin building function");
//调用
//Serial_class::Serial_Porting_Init(tx,rx);
//this->state = 0;
@@ -200,7 +210,7 @@
//设置串口参数
this->s_port->baud(115200);
this->s_port->format(8, SerialBase::None, 1);
- //设置状态机初始值
+ //设置初始值
//this->Init_Infor_struct();
this->infor_struct.state=0;
this->infor_struct.count=0;
@@ -209,10 +219,12 @@
//this->pcircle_Struct=&circle_Struct;
//初始化环形数组
//Init_Circle_Struct(pcircle_Struct);
-
+ pled=new DigitalOut(LED1);
+ *pled=1;
//关联s_port串口接收中断处理程序为成员函数Do_Recv
- s_port->attach(callback(this,&Serial_class::Do_Recv),Serial::RxIrq);
+ //s_port->attach(callback(this,&Serial_class::Do_Recv),Serial::RxIrq);
+ this->m_thread.start(callback(this,&Serial_class::Do_Recv));
}
//初始化
@@ -232,13 +244,12 @@
}
//
-//unsigned int Serial_class::ReadInfor()
-//{
-// unsigned char result;
-// result=infor_struct.value;
-// infor_struct.state=0;
-// return result;
-//}
+unsigned int Serial_class::ReadInfor()
+{
+ unsigned char result;
+ result=infor_struct.value;
+ return result;
+}
//
--- a/Serial_Transport.h Mon May 24 08:56:23 2021 +0000
+++ b/Serial_Transport.h Sat May 29 09:28:16 2021 +0000
@@ -2,6 +2,9 @@
#define _Serial_Transport_H
#include "mbed.h"
+#include "Serial.h"
+#include "Thread.h"
+
//#define RECV_BUFFER_SIZE 100
#define INFOR_BUFFER_SIZE 20
@@ -50,6 +53,8 @@
//Mutex rw_mutex;
//char buff[RECV_BUFFER_SIZE];
Serial * s_port;
+ DigitalOut * pled;
+ Thread m_thread;
};