UART interrupt based on MCF52235
[email protected] Mon, 2 Jun 2008 18:57:14 -0600 (MDT)
| Newsgroups | gmane.comp.hardware.motorola.microcontrollers.coldfire |
|---|---|
| Message-ID | <49330.123.239.241.180.1212454634.squirrel@www.accordelectronics.com> |
Dear All
I am currently using the UART polled in MCF52235. But one of the product I
need to used interrupt based. I had done initializarion and all necessory
changes. But still it could not genrate interrupt. I need interrupt on
each charactor received and each charactor transmitted. Can any body help
me on urgent basis.
Below in Initilization , vetctor declarations and isrs
regards
Sanjay Morab
==== Initialization
void uart_init(void)
{
/*
* Initialize all three UARTs for serial communications
*/
register uint16 ubgs;
/*
* Set Port UA to initialize URXD0/UTXD0
*/
MCF_GPIO_PUAPAR = 0
| MCF_GPIO_PUAPAR_RXD0_RXD0
| MCF_GPIO_PUAPAR_TXD0_TXD0;
MCF_GPIO_PUBPAR = 0
| MCF_GPIO_PUBPAR_RXD1_RXD1
| MCF_GPIO_PUBPAR_TXD1_TXD1
| MCF_GPIO_PUBPAR_RTS1_GPIO; // Set GPIO for RTS1
MCF_GPIO_PUCPAR = 0
| MCF_GPIO_PUCPAR_RXD2_RXD2
| MCF_GPIO_PUCPAR_TXD2_TXD2;
MCF_GPIO_DDRUB |= MCF_GPIO_DDRUB_DDRUB2; // Set Direction out
/*
* Reset Transmitter
*/
MCF_UART0_UCR = MCF_UART_UCR_RESET_TX;
MCF_UART1_UCR = MCF_UART_UCR_RESET_TX;
MCF_UART2_UCR = MCF_UART_UCR_RESET_TX;
/*
* Reset Receiver
*/
MCF_UART0_UCR = MCF_UART_UCR_RESET_RX;
MCF_UART1_UCR = MCF_UART_UCR_RESET_RX;
MCF_UART2_UCR = MCF_UART_UCR_RESET_RX;
/*
* Reset Mode Register
*/
MCF_UART0_UCR = MCF_UART_UCR_RESET_MR;
MCF_UART1_UCR = MCF_UART_UCR_RESET_MR;
MCF_UART2_UCR = MCF_UART_UCR_RESET_MR;
/*
* No parity, 8-bits per character
*/
MCF_UART0_UMR = (0
| MCF_UART_UMR_PM_NONE
| MCF_UART_UMR_BC_8 );
MCF_UART1_UMR = (0
| MCF_UART_UMR_PM_NONE
| MCF_UART_UMR_BC_8 );
MCF_UART2_UMR = (0
| MCF_UART_UMR_PM_NONE
| MCF_UART_UMR_BC_8 );
/*
* No echo or loopback, 1 stop bit
*/
MCF_UART0_UMR = (0
| MCF_UART_UMR_CM_NORMAL
| MCF_UART_UMR_SB_STOP_BITS_1);
MCF_UART1_UMR = (0
| MCF_UART_UMR_CM_NORMAL
| MCF_UART_UMR_SB_STOP_BITS_1);
MCF_UART2_UMR = (0
| MCF_UART_UMR_CM_NORMAL
| MCF_UART_UMR_SB_STOP_BITS_1);
/*
* Set Rx and Tx baud by SYSTEM CLOCK
*/
MCF_UART0_UCSR = (0
| MCF_UART_UCSR_RCS_SYS_CLK
| MCF_UART_UCSR_TCS_SYS_CLK);
MCF_UART1_UCSR = (0
| MCF_UART_UCSR_RCS_SYS_CLK
| MCF_UART_UCSR_TCS_SYS_CLK);
MCF_UART2_UCSR = (0
| MCF_UART_UCSR_RCS_SYS_CLK
| MCF_UART_UCSR_TCS_SYS_CLK);
/*
* Mask all UART interrupts
*/
MCF_UART0_UIMR = 0;
MCF_UART1_UIMR = 0;
MCF_UART2_UIMR = 0;
/*
* Calculate baud settings
*/
ubgs = (uint16)((SYSTEM_CLOCK*1000000)/(UART_BAUD19200 * 32));
MCF_UART0_UBG1 = (uint8)((ubgs & 0xFF00) >> 8);
MCF_UART0_UBG2 = (uint8)(ubgs & 0x00FF);
ubgs = (uint16)((SYSTEM_CLOCK*1000000)/(UART_BAUD19200 * 32));
MCF_UART1_UBG1 = (uint8)((ubgs & 0xFF00) >> 8);
MCF_UART1_UBG2 = (uint8)(ubgs & 0x00FF);
MCF_UART2_UBG1 = (uint8)((ubgs & 0xFF00) >> 8);
MCF_UART2_UBG2 = (uint8)(ubgs & 0x00FF);
MCF_INTC0_ICR13 = MCF_INTC_ICR_IL(2);
MCF_INTC0_IMRL &= ~MCF_INTC_IMRL_MASK13;
MCF_INTC0_ICR14 = MCF_INTC_ICR_IL(2);
MCF_INTC0_IMRL &= ~MCF_INTC_IMRL_MASK14;
MCF_INTC0_ICR15 = MCF_INTC_ICR_IL(2);
MCF_INTC0_IMRL &= ~MCF_INTC_IMRL_MASK15;
MCF_UART0_UIMR = ( MCF_UART_UIMR_TXRDY |
MCF_UART_UIMR_RXRDY_FU );
MCF_UART1_UIMR = ( MCF_UART_UIMR_TXRDY |
MCF_UART_UIMR_RXRDY_FU );
/*
* Enable receiver and transmitter
*/
MCF_UART0_UCR = (0
| MCF_UART_UCR_TX_ENABLED
| MCF_UART_UCR_RX_ENABLED);
MCF_UART1_UCR = (0
| MCF_UART_UCR_TX_ENABLED
| MCF_UART_UCR_RX_ENABLED);
MCF_UART2_UCR = (0
| MCF_UART_UCR_TX_ENABLED
| MCF_UART_UCR_RX_ENABLED);
}
---- Vector
#ifdef __GNUC__ /* { */
#define sr %sr
#define _irq_handler irq_handler
#define _timer_handler timer_handler
#define _uart0_isr uart0_isr
#define _uart1_isr uart1_isr
#endif /* } __GNUC__ */
.global VECTOR_TABLE
.global _VECTOR_TABLE
.global start
.extern ___SP_INIT
.extern _asm_startmeup
.extern _asm_exception_handler
.extern _irq_handler
.extern _timer_handler
.extern _irq1_handler
.extern _irq4_handler
.extern _irq7_handler
.extern _irq11_handler
.extern _uart0_isr
.extern _uart1_isr
.text
vector4D: .long _uart0_isr
vector4E: .long _uart1_isr
=== ISRS
__declspec(interrupt) void uart0_isr(void);
__declspec(interrupt) void uart1_isr(void);
void
uart_isr(int unit)
{
int dev = unit;
uint8 ch;
uint8 usr;
usr = MCF_UART_USR(dev);
/* UART receiver */
if (usr & MCF_UART_USR_RXRDY)
{
ch = MCF_UART_URB(dev);
/* discard character if there was an error */
if ( !(usr & (MCF_UART_USR_RB |
MCF_UART_USR_FE |
MCF_UART_USR_PE |
MCF_UART_USR_OE )) )
{
// receiber
}
else
{
MCF_UART_UCR(dev) = MCF_UART_UCR_RESET_ERROR;
}
}
/* UART transmitter */
if (usr & MCF_UART_USR_TXRDY)
{
MCF_UART_UCR(dev) = MCF_UART_UCR_TX_ENABLED;
ch = //xh to send
MCF_UART_UTB(dev) = ch;
}
}
/* FUNCTION: uart0_isr()
*
* interrupt handler for UART #0
*
* PARAMS: none
*
* RETURN: none
*/
__declspec(interrupt)
void
uart0_isr(void)
{
uart_isr(0);
}
/* FUNCTION: uart1_isr()
*
* interrupt handler for UART #0
*
* PARAMS: none
*
* RETURN: none
*/
__declspec(interrupt)
void
uart1_isr(void)
{
uart_isr(1);
}
---
[email protected] Send a post to the list.
[email protected] Join the list.
[email protected] Join the list in digest mode.
[email protected] Leave the list.