Test

Dependencies:   mbed

Fork of Test_Serial_Api_Interrupt by Jens Altenburg

Files at this revision

API Documentation at this revision

Comitter:
sarahmarshy
Date:
Fri Dec 08 17:52:01 2017 +0000
Parent:
0:e5e3838890fd
Commit message:
Fix attach/detach TX IRQ

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e5e3838890fd -r a4bb6f6eacf0 main.cpp
--- a/main.cpp	Tue Nov 28 16:16:28 2017 +0000
+++ b/main.cpp	Fri Dec 08 17:52:01 2017 +0000
@@ -1,26 +1,28 @@
 #include "mbed.h"
-
-
-#define nSerialPatch    /* compiler switch for workaround */
-
+ 
+ 
+//#define nSerialPatch    /* compiler switch for workaround */
+ 
 DigitalOut myled(LED1);
-
+ 
 Serial     stComX(USBTX,USBRX);/*
 * Description :  UART communicatin (Txd(D1)/Rxd(D0)) USART2 to serial PC COM-Port  
 */
-
+ 
 unsigned char  bSizeData; /*
 * Description : number of transmission data
 */
-
+ 
 unsigned char *pUartData; /*
 * Description : pointer to data
 */
-
+ 
 unsigned char abString[] = "Hello World!\n\r"; /*
 * Description : test string
 */
 
+void vIsrTxComX(void);
+ 
 /* new data to UART */
 unsigned char SYS_vStartComX( unsigned char *pData, unsigned char bSize ){    /* new data to UART */
     unsigned char i;
@@ -28,17 +30,13 @@
     else{
         bSizeData = bSize;                                  /* number of transmission data */
         pUartData = pData;                      
-        stComX.putc(*pUartData);                            /* first data */
-        pUartData++;
-        bSizeData--;
-#ifdef nSerialPatch
-        USART2->CR1 |= USART_CR1_TXEIE;                     /* enable TXE interrupt */
-#endif
+        //Attach TX Interrupt
+        stComX.attach(&vIsrTxComX, Serial::TxIrq);
         i = 1;
         }
     return i;
     }
-
+ 
 /* TX ISR */
 void vIsrTxComX( void ){                       
     if(stComX.writeable()){                                 /* check stComX */
@@ -47,13 +45,10 @@
             pUartData++;
             bSizeData--;
             }
-#ifdef nSerialPatch
         else{
-            USART2->CR1 &= ~USART_CR1_TXEIE;                /* disable TXE interrupt */
+            //Detach TX interrupt, nothing left to send
+            stComX.attach(NULL, Serial::TxIrq);               /* disable TXE interrupt */
             }
-#else
-        stComX.putc('e');
-#endif
         }
     }
     
@@ -67,12 +62,11 @@
             }
         }
     }
-
+ 
 int main() {
 /*  establish serial interrupts */
     stComX.attach(&vIsrRxComX, Serial::RxIrq); 
-    stComX.attach(&vIsrTxComX, Serial::TxIrq);
-
+ 
 /* endless loop */
     while(1) {
         myled = 1;
@@ -80,4 +74,4 @@
         myled = 0;
         wait(0.2);
     }
-}
+}
\ No newline at end of file