Página 1 de 1
so quero usar a interrupçao da serial Uart1 no keil....

Enviado:
03 Abr 2011 18:45
por cristian
rapaz q p**** é essa cara
so quero receber um dado pela serial via interrupçao onde estou errando ???
o ARM é o LPC2138 simulando no proteus
- Código: Selecionar todos
// UART1 interrupt service function
//******************************************************************************/
__irq void UART1_int (void) {
/* write code here */
Fusart1=1;
VICVectAddr = 0; /* Acknowledge Interrupt */
}
main()
{
VPBDIV = 1; /* A FREQ DOS PERIFERICOS É IGUAL AO CCLK*/
IODIR1=0xFF000000;
IOCLR1=0xFFFFFFFF;
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 78; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1DLM = 0;
U1LCR = 0x03;
VICVectAddr7 = (unsigned long)UART1_int;
VICVectCntl7 = 20|7; /* use it for UART1 Interrupt */
VICIntEnable = 1 << 7; /* Enable UART1 Interrupt */
U1IER = 3;
while(1)
{
if(Fusart1)
{
Fusart1=0;
sendchar('C');
}
}
}

Enviado:
04 Abr 2011 09:07
por fabim
Bom.
Depois que você configurar o pinsel.
Depois que você fizer a jogada de ler o dado serial, "obrigatoriamente na int ou em qualquer outro lugar", depois de voce ler obrigatoriamente a U1IIR, e etc..
Ai nos conversamos..

Enviado:
04 Abr 2011 11:13
por cristian
o pinsel ta errado ?
tem que testar o U1IIR, mesmo ja usado um IRQ vetrorada ?
- Código: Selecionar todos
// UART1 interrupt service function
//******************************************************************************/
__irq void UART1_int (void) {
/* write code here */
BufRx1=U1RBR;
Fusart1=1;
U1IIR=0X01;
VICVectAddr = 0; /* Acknowledge Interrupt */
}

Enviado:
04 Abr 2011 11:28
por fabim
- Código: Selecionar todos
void UART1Handler (void) __irq
{
BYTE IIRValue, LSRValue;
BYTE Dummy = Dummy;
IENABLE; /* handles nested interrupt */
IIRValue = U1IIR;
IIRValue >>= 1; /* skip pending bit in IIR */
IIRValue &= 0x07; /* check bit 1~3, interrupt identification */
if ( IIRValue == IIR_RLS ) /* Receive Line Status */
{
LSRValue = U1LSR;
/* Receive Line Status */
if ( LSRValue & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
{
/* There are errors or break interrupt */
/* Read LSR will clear the interrupt */
UART1Status = LSRValue;
Dummy = U1RBR; /* Dummy read on RX to clear
interrupt, then bail out */
IDISABLE;
VICVectAddr = 0; /* Acknowledge Interrupt */
return;
}
if ( LSRValue & LSR_RDR ) /* Receive Data Ready */
{
/* If no error on RLS, normal ready, save into the data buffer. */
/* Note: read RBR will clear the interrupt */
UART1Buffer[UART1Count] = U1RBR;
UART1Count++;
if ( UART1Count == BUFSIZE )
{
UART1Count = 0; /* buffer overflow */
}
}
}
else if ( IIRValue == IIR_RDA ) /* Receive Data Available */
{
/* Receive Data Available */
UART1Buffer[UART1Count] = U1RBR;
UART1Count++;
if ( UART1Count == BUFSIZE )
{
UART1Count = 0; /* buffer overflow */
}
}
else if ( IIRValue == IIR_CTI ) /* Character timeout indicator */
{
/* Character Time-out indicator */
UART1Status |= 0x100; /* Bit 9 as the CTI error */
}
else if ( IIRValue == IIR_THRE ) /* THRE, transmit holding register empty */
{
/* THRE interrupt */
LSRValue = U1LSR; /* Check status in the LSR to see if
valid data in U0THR or not */
if ( LSRValue & LSR_THRE )
{
UART1TxEmpty = 1;
}
else
{
UART1TxEmpty = 0;
}
}
IDISABLE;
VICVectAddr = 0; /* Acknowledge Interrupt */
}
/*****************************************************************************
** Function name: UARTInit
**
** Descriptions: Initialize UART0 port, setup pin select,
** clock, parity, stop bits, FIFO, etc.
**
** parameters: portNum(0 or 1) and UART baudrate
** Returned value: true or false, return false only if the
** interrupt handler can't be installed to the
** VIC table
**
*****************************************************************************/
DWORD UARTInit( DWORD PortNum, DWORD baudrate )
{
DWORD Fdiv;
if ( PortNum == 0 )
{
PINSEL0 = 0x00000050; /* RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / baudrate ; /*baud rate */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03; /* DLAB = 0 */
U0FCR = 0x07; /* Enable and reset TX and RX FIFO. */
if ( install_irq( UART0_INT, (void *)UART0Handler, HIGHEST_PRIORITY ) == FALSE )
{
return (FALSE);
}
U0IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */
return (TRUE);
}
else if ( PortNum == 1 )
{
/* Default is Keil MCB2300 board */
PINSEL0 |= 0x40000000; /* Enable TxD1 P0.15 */
PINSEL1 |= 0x00000001; /* Enable RxD1 P0.16 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( Fpclk / 16 ) / baudrate ; /*baud rate */
U1DLM = Fdiv / 256;
U1DLL = Fdiv % 256;
U1LCR = 0x03; /* DLAB = 0 */
U1FCR = 0x07; /* Enable and reset TX and RX FIFO. */
if ( install_irq( UART1_INT, (void *)UART1Handler, HIGHEST_PRIORITY ) == FALSE )
{
return (FALSE);
}
U1IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */
return (TRUE);
}
return( FALSE );
}
/*****************************************************************************
** Function name: UARTSend
**
** Descriptions: Send a block of data to the UART 0 port based
** on the data length
**
** parameters: portNum, buffer pointer, and data length
** Returned value: None
**
*****************************************************************************/
void UARTSend( DWORD portNum, BYTE *BufferPtr, DWORD Length )
{
if ( portNum == 0 )
{
while ( Length != 0 )
{
/* THRE status, contain valid data */
while ( !(UART0TxEmpty & 0x01) );
U0THR = *BufferPtr;
UART0TxEmpty = 0; /* not empty in the THR until it shifts out */
BufferPtr++;
Length--;
}
}
else
{
while ( Length != 0 )
{
/* THRE status, contain valid data */
while ( !(UART1TxEmpty & 0x01) );
U1THR = *BufferPtr;
UART1TxEmpty = 0; /* not empty in the THR until it shifts out */
BufferPtr++;
Length--;
}
}
return;
}
/******************************************************************************
** End Of File
******************************************************************************/
int main (void)
{
UARTInit(1, 19200); /* baud rate setting */
while (1)
{ /* Loop forever */
if ( UART1Count != 0 )
{
U1IER = IER_THRE | IER_RLS; /* Disable RBR */
UARTSend( 1, (BYTE *)UART1Buffer, UART1Count );
UART1Count = 0;
U1IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
}
}
return 0;
}
é maizomeno isso ai ó... Molezinha.
Eu sempre faço na unha, mais os exemplos deixam melhor

Enviado:
04 Abr 2011 17:33
por cristian
e toda aquela parafernalha de configuraçao do VIC para usar vetorada a interrupçao
vc nao usa nao ?

Enviado:
04 Abr 2011 17:45
por cristian
aqui vc ja atribui valores a eles ? como
U1IER = IER_RBR | IER_THRE | IER_RLS;
é a mesmo flags que ta no datashet

Enviado:
12 Abr 2011 21:02
por okdok
Apernas um observação:
VICVectCntl7 = 20|7; // acho que assim está errado
VICVectCntl7 = 32|7; // acho que assim está certo