MCF52235 UART interrupt help for a NOOB

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MCF52235 UART interrupt help for a NOOB

1,723 次查看
cmag
Contributor I
Technically I guess I'm not a noob, but it's been a very long time since I had to do this, so all real knowledge is gone.
 
Can someone point me to a resource that would have a good step by step example on how to enable and utilize an interrupt for when the UART receives a byte.  I did this about two years ago and haven't touched a microcontroller since so I don't for the life of me remember how to do this.
 
I've looked around and havent found anything very simple to understand, and thus far you guys have been tremendously helpful.
 
Thanks,
 
cmag 
标签 (1)
0 项奖励
回复
1 回复

550 次查看
mjbcswitzerland
Specialist V
Hi cmag

Here is basic code for configuration and reception by interrupt. I have left out the actual UART configuration for speed, parity etc. but the rest shows the most important steps (UART0 only):

Code:
// Configure the pins for UART usePUAPAR |= ((PRIMARY_FUNCTION_Q << BIT_0_Q_SHIFT) | (PRIMARY_FUNCTION_Q << BIT_1_Q_SHIFT)); // Set TX/RX on UA// Enter interrupt handlerIC_ICR_0_13 = UART0_INTERRUPT_PRIORITY;                          // define interrupt level and priorityfnSetIntHandler(UART0_VECTOR, (unsigned char *)_SCI0_Interrupt); // enter the handler routineIC_IMRL_0 &= ~(UART0_PIF_INT_L | MASK_ALL_INT);                  // unmask interrupt source//configure speed and mode...// enable rx (tx is enabled only during transmission)UCR_0 = UART_RX_ENABLE;UIMR_UISR_0 = (ucEnabledState[Channel] |= (UART_RXRDY_MASK)); // this register can not be read so we keep a backup of its content!!// interrupt on character receptionstatic __interrupt__ void _SCI0_Interrupt(void){    unsigned char ucState;    while ((ucState = (UIMR_UISR_0 & UART_INTERRUPTS)) != 0) {           // while interrupts present        if (ucState & UART_RXRDY_MASK) {            fnSciRxByte(UTB_RB_0, 0);                                    // receive data interrupt - read the byte        }        if (ucState & UART_TXRDY_MASK) {            fnSciTxByte(0);                                              // transmit data empty interrupt - write next byte        }    }}

This is a small extract from the uTasker project. The UART interface supports interrupt or DMA operation and optional HW and SW flow control. You may like to look at the project (link below) because the code if free for non-commercial work and fully supported (http://www.uTasker.com/forum/). It also works in the uTasker simulator which allows the analysis of UART code, including interrupt operation on a virtual M5223X without needing to work on the hardware.
The uTasker project comes with complete TCP/IP stack, OS and device drivers for the M5223X chips - it allows firmware updates via Ethernet (web browser) so can save lots of time as well as aiding simple learning.

Regards

Mark

www.uTasker.com




0 项奖励
回复