zizi110
Member level 1

Hi all,
i am trying to run receive interrupt in usart0 in AT91SAM7X256 microcontroller.
i red a lot doc about it , but yet i could't fix it
can any one help me please?
this is the code.
this code is running in keil simulator very well, but when i program it on micro , it does not work
i am trying to run receive interrupt in usart0 in AT91SAM7X256 microcontroller.
i red a lot doc about it , but yet i could't fix it
can any one help me please?
this is the code.
this code is running in keil simulator very well, but when i program it on micro , it does not work
Code:
/*-------------------------------------------------------------------------------
USART0 receive interrupt
--------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------
8 bits
Baud rate : 9600
--------------------------------------------------------------------------------*/
#include <AT91SAM7X256.H>
//#include <intrinsics.h>
#include <stdio.h>
#include "delay.h"
#include "usart.h"
//#include "irq_enable.h"
//#include "usart.h"
//#include "aic.h"
#define LCD_PORT_A //CHAR LCD pins definition
#define LCD_RS 3
#define LCD_E 5
#define LCD_DB4 6
#define LCD_DB5 7
#define LCD_DB6 8
#define LCD_DB7 9
#include "lcd.h"
void usart0_irq_handler(void) __irq; // function prototype for USART0 handler
//global variables
float d;
char buffer[]={0,0,0,0,0};
int main ()
{
//*AT91C_PMC_PCER = (1<<AT91C_ID_IRQ0 );
AT91C_BASE_PIOB->PIO_PER = (1<<27)|(1<<28);
AT91C_BASE_PIOB->PIO_OER = (1<<27)|(1<<28);
AT91C_BASE_PMC->PMC_PCER = (1<<AT91C_ID_US0); // step1: activate usart0 clock
AT91C_BASE_PIOA->PIO_PDR = AT91C_PA0_RXD0 | AT91C_PA1_TXD0; //step2: disable I/O pin on PA0 and PA1
AT91C_BASE_PIOA->PIO_ASR = AT91C_PIO_PA0 | AT91C_PIO_PA1; //step3: activate peripheral A select register for PA0 and PA1 for using usart0 on this pin
AT91C_BASE_PIOA->PIO_BSR = 0; //step4: disable peripheral B
// At this point, we have the USART0 peripheral clock turned on and the two pins (RXD0 and TXD0 ) are
//associated with the USART0 peripheral.
// Set up the Advanced Interrupt Controller (AIC) registers for USART0
AT91C_BASE_AIC->AIC_IDCR = (1<<AT91C_ID_US0); // Disable USART0 interrupt in AIC
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_US0] = (unsigned int)usart0_irq_handler; // Set the USART0 IRQ handler address in AIC
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_US0] =(AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 0x4 ); // Set the int source type and pri
AT91C_BASE_AIC->AIC_IECR = (1<<AT91C_ID_US0); // Enable the USART0 interrupt in AIC
// Control Register - Reset then Disable the Receiver/Transmitter
AT91C_BASE_US0->US_CR = AT91C_US_RSTRX | // reset receiver
AT91C_US_RSTTX | // reset transmitter
AT91C_US_RXDIS | // disable receiver
AT91C_US_TXDIS; // disable transmitter
AT91C_BASE_US0->US_MR = (AT91C_US_PAR_NONE | 0x3 << 6); // no parity 8-bit characters
AT91C_BASE_US0->US_IER = 0x0000;
AT91C_BASE_US0->US_IDR = 0xFFFF;
AT91C_BASE_US0->US_BRGR= 0x138; // CD = 0x138 (312 from calculation) FP=0 (not used)
AT91C_BASE_US0->US_RTOR= 0; // receiver time-out (disabled)
AT91C_BASE_US0->US_TTGR= 0; // transmitter timeguard (disabled)
AT91C_BASE_US0->US_FIDI= 0; // FI over DI Ratio Value (disabled)
AT91C_BASE_US0->US_IF= 0; // IrDA Filter value (disabled)
// Final Preparations for USART0 Interrupt Processing
AT91C_BASE_US0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN ; // enable the USART0 receiver
AT91C_BASE_US0->US_IER = AT91C_US_RXRDY; // enable RXRDY usart0 receive interrupt
AT91C_BASE_US0->US_IDR = ~AT91C_US_RXRDY; // disable all other interrupts except RXRDY
AT91C_BASE_AIC->AIC_IECR = (1<<AT91C_ID_US0);
while(1){
//while((*AT91C_US0_CSR&2)!=2); // wait till usart gets ready for send
//*AT91C_US0_THR=d+15;
*AT91C_PIOB_SODR = (1<<28);
delay_ms(2000);
*AT91C_PIOB_CODR = (1<<28);
delay_ms(2000);
lcd_gotoxy(1,1);
lcd_putsf("Recieved data :");
sprintf(buffer,"%f",d);
lcd_gotoxy(2,1);
lcd_putsf(buffer);
delay_ms(1000);
}
}
void usart0_irq_handler(void) __irq {
volatile unsigned int dummy;
AT91C_BASE_AIC->AIC_EOICR = AT91C_BASE_US0->US_CSR;
dummy = AT91C_BASE_AIC->AIC_IVR;
*AT91C_PIOB_SODR = (1<<27);
delay_ms(500);
*AT91C_PIOB_CODR = (1<<27);
delay_ms(500);
//if ((AT91C_BASE_US0->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY) {
// we have a receive interrupt,
d = getkey();
d = d+15;
sendchar(d);
AT91C_BASE_AIC->AIC_ICCR = (1 << AT91C_ID_US0);
AT91C_BASE_AIC->AIC_EOICR=0;
//}
}