from Cam Marshall original modbus

Dependencies:   mbed

Fork of Modbus by Cam Marshall

Revision:
4:5000041d2dc2
Parent:
2:5f360876388e
Child:
5:c712a10c9414
--- a/Modbus/portserial.cpp	Mon Mar 13 13:12:06 2017 +0000
+++ b/Modbus/portserial.cpp	Tue Mar 14 14:25:27 2017 +0800
@@ -37,8 +37,11 @@
 
 /* ----------------------- System Variables ---------------------------------*/
 //Serial pc(USBTX, USBRX);           // Cam - mbed USB serial port
-Serial ser3(D6, PC_11); //serial3
+Serial ser3(PB_10, PC_5); //serial3
 extern Serial pc;
+static uint8_t grx_buf=0;
+
+
 //Ticker simISR;                      // Cam - mbed ticker
                                     // we don't have the TX buff empty interrupt, so
                                     // we just interrupt every 1 mSec and read RX & TX
@@ -105,17 +108,28 @@
 	else
 		pc.printf("xTxDisable\n");
 
+
+	ser3.attach(NULL); //close all
+	
 	if(xRxEnable)
 		ser3.attach(&prvvUARTRxISR,Serial::RxIrq);
-	else
-		ser3.attach(NULL,Serial::RxIrq);
 	
-	/*if(xTxEnable)
+	if(xTxEnable)
+	{
 		ser3.attach(&prvvUARTTxReadyISR,Serial::TxIrq);
-	else
-		ser3.attach(NULL,Serial::TxIrq);*/
+		while(!ser3.writeable());
+		prvvUARTTxReadyISR();
+	}		
+	
+
 	//if(xTxEnable)
 		//¤£¥Î¦b³oÃä³]©wser3.write(tx_buf,TX_BUFF_LENGTH,serialTxCBEvent,SERIAL_EVENT_TX_COMPLETE);
+
+	//else
+	//{
+	//	ser3.attach(NULL,Serial::RxIrq);  //stanley  the test result find that this may disable RxIrq and TxIrq so have to enable TxIrq
+	//	ser3.attach(&prvvUARTTxReadyISR,Serial::TxIrq);  
+	//}
 }
 
 BOOL
@@ -144,7 +158,9 @@
      * by the protocol stack if pxMBFrameCBTransmitterEmpty( ) has been
      * called. */
     //ser3.putc( ucByte);
-	pc.printf("in put\n");
+	//pc.printf("p\n");
+	//pc.printf("%x",ucByte);
+
 	//stanley
 	//while(!ser3.writeable());
 	ser3.putc( ucByte);
@@ -158,9 +174,9 @@
     /* Return the byte in the UARTs receive buffer. This function is called
      * by the protocol stack after pxMBFrameCBByteReceived( ) has been called.
      */
-	pc.printf("in get\n");
-	if(ser3.readable())
-		*pucByte = ser3.getc();
+	//pc.printf("%x",grx_buf);
+	
+	*pucByte = grx_buf;//stanley
 
 	
 
@@ -175,7 +191,7 @@
  */
 static void prvvUARTTxReadyISR( void )
 {
-	pc.printf("in Tx_I\n");
+	//pc.printf("TR\n");
     pxMBFrameCBTransmitterEmpty();
 }
 
@@ -186,7 +202,11 @@
  */
 static void prvvUARTRxISR( void )
 {
-	pc.printf("in Rx_I\n");
+	//pc.printf("in Rx_I\n");
+
+	if(ser3.readable())	//stanlely RX ISR must contain getc
+		grx_buf=ser3.getc();
+
     pxMBFrameCBByteReceived();
 }