Re: UART Transmission TX inside ISR
"Matthias Weingart [email protected] [msp430]" <[email protected]> Mon, 10 Oct 2016 10:34:06 +0000 (UTC)
| Newsgroups | gmane.comp.hardware.texas-instruments.msp430.discuss |
|---|---|
| Organization | private site |
| Message-ID | <[email protected]> |
Hi xilverbolt, you are receiving a byte and just send it. UartSendChar() is typically waiting for the sending UART to be free again - and will block your interrupts and CPU for this time - maybe not a good idea. You should at least enable the interrupts before calling ParseRXData (EINT()). However, in case the sending and transmitting UART are both working at the same speed, this will never happen. Another point: I would not call subroutines from the interrupt, this need much more cycles e.g. for saving all registers to stack. In a short int- routine, as in your example, only a few registern are needed to be pushed to the stack and popped. However maybe the compiler is good one and is inlining your subroutine automatically. Another advantage is, you will see what happen in only a few lines - e.g. that UartSendChar() is blocking your code. Encapsulation of code in subroutines is often a good idea, but sometimes not. In case you just want to copy a byte from uarta to uartb - this can be done with the DMA only - just code for the setup is required, no active code during execution of the task required and no blocking of the CPU, for my opinion the best solution - however you need some time to find out the right setup bits ;-). It is possible to have a additional rx interrupt that is handling the buffering of the bytes only. Matthias "xilverbolt-/[email protected] [msp430]" <[email protected]>: > I'm curious if someone can explain to me the (negative?) effects of > trying to send UART bytes directly from my Interrupt Service Routine. > Is this bad design practice because now my ISR will take longer to > execute? Should I be using DMA to TX data here? Thanks in advance. > > > static void ParseRxData(const uint8_t rx_byte) > { > // Only Allow ASCII Characters to be loaded into buffer > // This will drop CR/LF etc, won't go in gRxBuffer > if (rx_byte >= 0x20) > gRxBuffer[gWrIndex++] = tolower(rx_byte); // stuff lowercase > only into buffer > > > UartSendChar(rx_byte); > > > if (rx_byte == 0x0A) // End of Command > { > gRxBuffer[gWrIndex] = 0; // Add null pointer to end > gFlagCmdReady = true; // Set Global Flag Ready Command > gWrIndex = 0; > } > } > > > > > //********************************************************************** > ******** // > //This is the USCI_A1 interrupt vector service routine. > // > //********************************************************************** > ******** #if defined(__TI_COMPILER_VERSION__) || > defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_A1_VECTOR > __interrupt > #elif defined(__GNUC__) > __attribute__((interrupt(USCI_A1_VECTOR))) > #endif > void EUSCI_A1_ISR(void) > { > uint8_t RXData; > switch(__even_in_range(UCA1IV,USCI_UART_UCTXCPTIFG)) > { > case USCI_NONE: break; > case USCI_UART_UCRXIFG: > RXData = EUSCI_A_UART_receiveData(EUSCI_A1_BASE); > ParseRxData(RXData); > break; > case USCI_UART_UCTXIFG: break; > case USCI_UART_UCSTTIFG: break; > case USCI_UART_UCTXCPTIFG: break; > } > } > ------------------------------------ Posted by: Matthias Weingart <[email protected]> ------------------------------------ To unsubscribe from the msp430 group, send an email to: [email protected]