so quero usar a interrupçao da serial Uart1 no keil....

Software e Hardware para linha ARM

Moderadores: 51, guest2003, Renie, gpenga

so quero usar a interrupçao da serial Uart1 no keil....

Mensagempor cristian » 03 Abr 2011 18:45

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');
}
}
}
Editado pela última vez por cristian em 04 Abr 2011 11:07, em um total de 1 vez.
cristian
Word
 
Mensagens: 570
Registrado em: 03 Nov 2006 08:15
Localização: serrinha-ba

Mensagempor fabim » 04 Abr 2011 09:07

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..
Mano, ve só.
Sou responsável pelo que escrevo!!! E não pelo que você entende !!!
fabim
Dword
 
Mensagens: 5001
Registrado em: 16 Out 2006 10:18
Localização: aqui uái!!!?

Mensagempor cristian » 04 Abr 2011 11:13

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 */
}
cristian
Word
 
Mensagens: 570
Registrado em: 03 Nov 2006 08:15
Localização: serrinha-ba

Mensagempor fabim » 04 Abr 2011 11:28

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
Mano, ve só.
Sou responsável pelo que escrevo!!! E não pelo que você entende !!!
fabim
Dword
 
Mensagens: 5001
Registrado em: 16 Out 2006 10:18
Localização: aqui uái!!!?

Mensagempor cristian » 04 Abr 2011 17:33

e toda aquela parafernalha de configuraçao do VIC para usar vetorada a interrupçao

vc nao usa nao ?
cristian
Word
 
Mensagens: 570
Registrado em: 03 Nov 2006 08:15
Localização: serrinha-ba

Mensagempor cristian » 04 Abr 2011 17:45

aqui vc ja atribui valores a eles ? como

U1IER = IER_RBR | IER_THRE | IER_RLS;

é a mesmo flags que ta no datashet
cristian
Word
 
Mensagens: 570
Registrado em: 03 Nov 2006 08:15
Localização: serrinha-ba

Mensagempor okdok » 12 Abr 2011 21:02

Apernas um observação:

VICVectCntl7 = 20|7; // acho que assim está errado

VICVectCntl7 = 32|7; // acho que assim está certo
okdok
Nibble
 
Mensagens: 61
Registrado em: 09 Ago 2007 11:49


Voltar para ARM

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x