NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » UART interrupt issues
May 19, 2011 by gcharris |
This is my first foray into interrupts. Basically I'm looking to send a character from my computer to the microcontroller via serial, have it trigger an interrupt and modify a global variable that will be used as control other aspects of my project. I asn't able to get it to work, so I tried to just do a simple loopback of text typed in. I stripped down the file to the absolute bare minimum and I still cannot get any return output to my terminal. Any thoughts as to where I'm going wrong? Thanks Grant
|
---|---|
May 19, 2011 by Noter |
You have to check the status register to see if a byte has been received before getting it from UDR0. Likewise, you have check it again to see if it is idle before writing to UDR0.
|
May 19, 2011 by Noter |
Oops, since you are in an interrupt you don't need to check to see if the character is ready to read. You still need to check before writing and may need to move your write logic back to the main loop. I don't know if you can write before leaving the interrupt routine. |
May 19, 2011 by Noter |
Actually, I am wrong on both counts. Before using the interrupt, the receive interrupt must be enabled. My chip runs at 18432000hz so I also have to reset the baud rate after calling uart_init(). The final problem is that you must not return from you main() so I added the while loop.
|
May 19, 2011 by gcharris |
Awesome, thanks. I'll try it out later tonight once I get home. |
May 20, 2011 by gcharris |
Worked wonderfully, thanks |
Please log in to post a reply.
Did you know that using an alternating excitation voltage can reduce the noise in many sensor measurements? Learn more...
|