اطلاعیه

Collapse
No announcement yet.

راه اتدازی وقفه دریافت در یوزارت0 در میکرو at91sam7x256

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    راه اتدازی وقفه دریافت در یوزارت0 در میکرو at91sam7x256

    سلام به همه دوستان
    بنده مدتی هست که درگیر راه اندازی وقفه دریافت بخش USART0در میکرو AT91SAM7X256 شدم :read:
    کد رو پایین گذاشتم. جالبه که در شبیه سازی KEIL جواب میده ولی وقتی روی میکرو پروگرم میکنم جواب نمیده... نمیدونم چرا. یک PDF آموزشی هم دقیقا در این مورد دانلود کردم که خیلی عالی و آموزنده بود ... تمام تنظیمات رو طبق اون PDF انجام دادم ولی در کدش در مورد تابع enableIRQ صحبت کرده بود که من نمیدونم این تابع رو از کجا بیارم! اصلا این تابع چی هست.
    فایل PDF رو هم اگر تونستم میزارم.
    میدونم که یک تاپیک با همین نام وجود داشته ولی در آخر اون موضوع حل نشد و من جواب سوالم رو نگرفتم. لطفا این تاپیک رو پاک نکنید :cry:
    خواهش میکنم راهنمایی کنید :cry2: واقعا دیگه جیزی به ذهنم نمیرسه



    [code=c]/*-------------------------------------------------------------------------------
    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.

    // 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)



    // 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


    // 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);
    sendchar(d);

    }





    }

    void usart0_irq_handler(void) __irq {
    int dummy;
    *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,
    // remove it from Receiver Holding Register and place into buffer[]
    d = getkey();
    d = d+15;
    //sendchar(d);
    AT91C_BASE_AIC->AIC_EOICR = AT91C_BASE_US0->US_CSR;
    dummy = AT91C_BASE_AIC->AIC_IVR;
    AT91C_BASE_AIC->AIC_ICCR = (1 << AT91C_ID_US0);

    AT91C_BASE_AIC->AIC_EOICR=0;

    //}
    }












    [/code]

    #2
    پاسخ : راه اتدازی وقفه دریافت در یوزارت0 در میکرو at91sam7x256

    اینم لینک دانلود برای pdf ایی که گفته بودم :

    http://uplod.ir/tibclfrxw82c/at91sam7_serial_communications.pdf.htm

    دیدگاه


      #3
      پاسخ : راه اتدازی وقفه دریافت در یوزارت0 در میکرو at91sam7x256

      قا من متوجه اشتباهم شدم
      وقفه مربوط به IRQ رو فعال نکرده بودم...
      حالا دیگه برنامه وارد روتین وقفه میشه ولی مشکل اینجاست که:
      من یک متغیر تعریف کردم از نوع GLOBAL. داده ایی که از کامپیوتر دریافت میشه در این متغیر ذخیره میشه و وقتی وارد روتین وقفه میشیم میخوام مثلا 10 واحد به این متغیر اضافه بشه و وقتی از وقفه خارج شدیم، این مقدار جدید به کامپیوتر ارسال بشه.... ولی نمیدونم چرا این متغیر در داخل روتین وقفه به عنوان همون متغیر GLOBAL ایی که تعریف کرده بودم شناخته نمیشه!!! :eek:
      کسی با این مشکل آشنایی داره؟
      اینم کدش :
      [code=c]/*-------------------------------------------------------------------------------
      USART0 receive interrupt
      --------------------------------------------------------------------------------*/
      /*-------------------------------------------------------------------------------

      8 bits
      Baud rate : 9600
      --------------------------------------------------------------------------------*/

      #include <AT91SAM7X256.H>
      #include <stdio.h>
      #include "delay.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 *h;
      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);




      ////////////
      AIC_ConfigureInt(AT91C_ID_IRQ0);
      AIC_EnableInt(AT91C_ID_IRQ0); // enable IRQ0 interrupt
      ///////////

      //------------ LCD config -------------------------------//
      lcd_init();
      lcd_clear();
      cursor_off();
      delay_ms(10); // me
      //-----------------------------------------------------//
      while(1){
      //while((*AT91C_US0_CSR&2)!=2); // wait till usart gets ready for send
      //*AT91C_US0_THR=d+15;
      lcd_clear();
      delay_ms(10);
      lcd_gotoxy(1,1);
      lcd_putsf("Hi"
      //delay_ms(100);

      *AT91C_PIOB_SODR = (1<<28);
      delay_ms(2000);
      *AT91C_PIOB_CODR = (1<<28);
      delay_ms(2000);


      h[0] = getkey();

      lcd_clear();
      delay_ms(100);
      lcd_gotoxy(1,1);
      lcd_putsf("Recieved data :"
      sprintf(buffer,"%f",h[0]);
      lcd_gotoxy(2,1);
      lcd_putsf(buffer);
      delay_ms(1000);

      sendchar(h[0]);
      delay_ms(10);



      }





      }

      void usart0_irq_handler(void) __irq {
      volatile unsigned int dummy;
      extern float *h;
      dummy = AT91C_BASE_AIC->AIC_IVR;
      dummy = AT91C_BASE_US0->US_RHR;
      *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,


      h[0] = 1+ h[0];




      AT91C_BASE_AIC->AIC_ICCR = (1 << AT91C_ID_US0);

      AT91C_BASE_AIC->AIC_EOICR=0;
      AT91C_BASE_AIC->AIC_EOICR= AT91C_BASE_AIC->AIC_EOICR;
      AT91C_BASE_AIC->AIC_EOICR = AT91C_BASE_AIC->AIC_ISR;
      AT91C_BASE_AIC->AIC_EOICR = AT91C_BASE_US0->US_CSR;
      //}
      }












      [/code]

      دیدگاه


        #4
        پاسخ : راه اتدازی وقفه دریافت در یوزارت0 در میکرو at91sam7x256

        با سلام
        اون خط extern اول تابع وقفه به نظرم اضافست، شاید همونم داره ایجاد مشکل می کنه، با توجه به اینکه توابع تو یه فایل هستن، extern؟
        The healthy human mind doesn't wake up in the morning thinking this is his last day on earth.

        دیدگاه

        لطفا صبر کنید...
        X