I'am working with at91sam7x256 and in my program the usart interrupt dosen't work correctly ! I communicatinon with atmel but it isn't fix yet.
thise is my program...pleas help me
www.4shared.com/.../usart16__2_.html
my mail :salehi.elc@gmail.com
1- we really successfully enable lcd without interrupt and without work with serial !!!
we wrote handle serial for use LCD..in other language we only work with I/O for run LCD...
2_ I don't know why you think that we are lying???why we should lie to you??? only for one homework we 2 month tray to resolve it's problem?? i am sorry for ourself!!
this is our code:
#include <at91sam7x256.h> #include <lib_at91sam7x256.h> unsigned char test = 48; void Usart0IrqHandler(void); // function prototype for USART0 handler volatile AT91PS_PMC pPMC = AT91C_BASE_PMC; // pointer to PMC data structure volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; volatile AT91PS_USART pUsart0 = AT91C_BASE_US0; volatile AT91PS_AIC pAIC = AT91C_BASE_AIC; // pointer to AIC data structure volatile AT91PS_SYS pSYS=AT91C_BASE_SYS; int main(void){ test=70; pPIO->PIO_PDR = (AT91C_PA0_RXD0 | AT91C_PA1_TXD0); pPMC->PMC_PCER = (1<<AT91C_ID_US0); // enable usart0 peripheral clock pPIO->PIO_ASR = (AT91C_PIO_PA0 | AT91C_PIO_PA1); // define peripheral A select regidtry pPIO->PIO_BSR = 0; // define peripheral B select regidtry pUsart0->US_CR = (AT91C_US_RSTRX | // reset receiver AT91C_US_RSTTX | // reset transmitter AT91C_US_RXDIS | // disable receiver AT91C_US_TXDIS); // disable transmitter pUsart0->US_MR = (AT91C_US_PAR_NONE | // no parity 0x3 << 6); // 8-bit characters pUsart0->US_IER = 0x0000; // no usart0 interrupts enabled (no effect) pUsart0->US_IDR = 0xFFFF; // all usart0 interrupts disabled pUsart0->US_BRGR = 0x139; // CD = 0x139 (313 from above calculation) // FP=0 (not used) pUsart0->US_RTOR = 0; // receiver time-out (disabled) pUsart0->US_TTGR = 0; // transmitter timeguard (disabled) pUsart0->US_FIDI = 0; // FI over DI Ratio Value (disabled) pUsart0->US_IF = 0; // IrDA Filter value (disabled) pAIC->AIC_IDCR = (1<<AT91C_ID_US0); // Disable USART0 interrupt in AIC pAIC->AIC_SVR[AT91C_ID_US0] = (unsigned int)Usart0IrqHandler; // Set the USART0 IRQ handler address in AIC // Source Vector Register[6] pAIC->AIC_SMR[AT91C_ID_US0] =(AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | 0x4 ); // Set the int source type and pri // in AIC Source Mode Register[6] pAIC->AIC_IECR = (1<<AT91C_ID_US0); // Enable the USART0 interrupt in AIC // enable the USART0 receiver and transmitter pUsart0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN; // enable the USART0 receive interrupt pUsart0->US_IER = AT91C_US_RXRDY; // enable RXRDY usart0 receive interrupt pUsart0->US_IDR = ~AT91C_US_RXRDY; // disable all other interrupts except RXRDY test=70; do{ }while(1); } void Usart0IrqHandler(void){ int statuse; statuse= pUsart0->US_CSR; test=pUsart0->US_RHR; pUsart0->US_THR=test; if (AT91F_US_TxReady(AT91C_BASE_US0)==0) do{ }while(AT91F_US_TxReady(AT91C_BASE_US0)==1); AT91C_BASE_AIC->AIC_EOICR = 0; return ; }
perhaps you can find some little error in our program but none of them doesn't about our problem!!
and some important part of our start up:
UND_Stack_Size EQU 0x00000000 SVC_Stack_Size EQU 0x00000100 ABT_Stack_Size EQU 0x00000000 FIQ_Stack_Size EQU 0x00000000 IRQ_Stack_Size EQU 0x00000080 USR_Stack_Size EQU 0x00000400 IRQ_Handler ldr r14, =AT91C_BASE_AIC ; ldr r0, [r14, #AIC_IVR] ;bx r0 ;sub r14, r14, #4 ;stmfd sp!, {r0-r3, r12, r14} ;ldr r14, =AT91C_BASE_AIC ;ldr r0, [r14, #AIC_IVR] ;bx r0 ; ldr r14, =AT91C_BASE_AIC ; str r14, [r14, #AIC_EOICR] ; ldmfd sp!, {r0-r3, r12, pc}^ ;Save interrupt context on the stack to allow nesting */ SUB lr, lr, #4 STMFD sp!, {lr} MRS lr, SPSR STMFD sp!, {r0,r1,lr} ; Write in the IVR to support Protect Mode */ LDR lr, =AT91C_BASE_AIC LDR r0, [r14, #AIC_IVR] STR lr, [r14, #AIC_IVR] ; Branch to interrupt handler in Supervisor mode */ MSR CPSR_c, #ARM_MODE_SVC STMFD sp!, {r1-r4, r12, lr} MOV lr, pc BX r0 LDMIA sp!, {r1-r4, r12, lr} MSR CPSR_c, #ARM_MODE_IRQ | I_BIT ; Acknowledge interrupt */ LDR lr, =AT91C_BASE_AIC STR lr, [r14, #AIC_EOICR] ; Restore interrupt context and branch back to calling code LDMIA sp!, {r0,r1,lr} MSR SPSR_cxsf, lr LDMIA sp!, {pc}^ ; Reset Handler EXPORT Reset_Handler
Do you honestly find that clear & easy to read?!
When you're struggling with tricky problms like this, the last thing you need is a scruffy layout to make things harder!
So, here's your ISR:
void Usart0IrqHandler(void){ int statuse; statuse = pUsart0->US_CSR; test = pUsart0->US_RHR; pUsart0->US_THR = test; if( AT91F_US_TxReady(AT91C_BASE_US0)==0 ) do{ }while( AT91F_US_TxReady(AT91C_BASE_US0)==1 ); AT91C_BASE_AIC->AIC_EOICR = 0; return ; }
The first thing you need to do is to provide comments to describe what you're doing and - more importantly - why.
Why is 'test' global?
Is a 'while' loop really a good idea inside an ISR?
Ali,
According to this post, you do not need to write to the AIC_EOICR register unless it was invoked by SW.
www.embeddedrelated.com/.../2874.php
Here is another resource for serial comms. The code looks very familiar to what you have posted, so you should be able to compare yours to this one and solve your problem...
www.sparkfun.com/.../at91sam7 serial communications.pdf
dear Andy. your advise is right! I should comment all of my code..but now I think that I can description here!!
the test is the a bit that receive and it get from US_RHR registry !!
after that we sent test bit with writ in US_RHR registry!!
it is very simple!
and about that -> "...According to this post, you do not need to write to the AIC_EOICR register unless it was invoked by SW...."
yes is right but my problem doesn't for it..i check it! not difference from to bo or not to be of AIC_EOICR in code!
and about it: "..Here is another resource for serial comms. The code looks very familiar to what you have posted, so you should be able to compare yours to this one..."
I read all of it beforehand..and if i can write this program it is for this resource!
it is a very good resource but it doesn't have a good description a bout interrupt,
in this resource the all of thing about normal usart explain very exactly and step by step but when the interrupt subject start it explain that very short and obscure..
I.....
forfeit, give up, throw overboard, waive, forgo, forego, abandon, drop out, fall by the wayside, drop by the wayside, throw in, throw in the towel, quit, chuck up the sponge (like this one!!!), discontinue, stop, cease, give up, quit, lay off, spare, part with, dispense with, release, relinquish, resign, free, pass, hand, reach, pass on, turn over, vacate, resign, renounce, leave office, quit, step down, resign, surrender, cede, deliver, yield, waive, foreswear....
ooooops!! :-o WHAT is MEANING OF YOU ????
No, you can't - it makes no sense!
I think that i found problem!! the problem is exactly keil compiler . i changed my compiler to IAR . THE KEIL HASE BUG!
THE KEIL HASE BUG!
Sue them, then. They cost you days of fruitful work, misery and tears. Yes?
You might, of course, be right - but that is of no use at at all if you can't describe precisely what the alleged bug is!