NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Interrupt driven USART comms, problem when passing received char
April 03, 2011 by jeuhrn |
This is how I have my interrupt routine set up:
y is basically just a counter that lets me know the connection is alive. ctrl_chr() is supposed to check for certain control characters I know are in the strings I'm passing, the basics of it looks like this:
And the ctrlchr character is just junk. Am I missing something fundamental here? |
---|---|
April 04, 2011 by Ralphxyz |
I think you need to give us more detail. What exactly is your problem. What is not happening, when, where? Is it a problem compiling or running or what. Hopefully with more details you will get an answer. Ralph |
April 04, 2011 by bretm |
If you're saying you're receiving garbage characters, first I'd strip down the interrupt routine to the minimum--just echo back and do nothing else. Until you get that working, everything else just confuses the issue. I definitely wouldn't do anything with the LCD inside a USART interrupt routine. You need the interrupt to get in and out very fast, and the LCD routines are relatively slow. If the ISR doesn't go fast enough you will lose data. I would just have the interrupt put the data somewhere where the main routine could get to it and have the main routine do the LCD stuff. |
April 05, 2011 by jeuhrn |
It echo's back, that works fine. I've taken it all out and started trying to implement some ring buffer routines from Dean on avrfreaks forums. Babysteps. =) |
April 05, 2011 by jeuhrn |
Ok, I think I'm on to something here. There's nothing junky about the USART, there is however something funky about writing to the LCD. These are my control characters
This is just a sample function that i have looping while(1) in my main() right now to test this
This generates the output
Meaning that outside the loop I can read the i'th position of my array and write it to the LCD, inside the loop this produces junk, meanwhile the lcd_goto_position() function manages to make sense of the incrementing variable. Is there any reason why using the incrementing variable in the for loop should produce garbage characters, while directly referencing the char array with an integer works? |
April 05, 2011 by bretm |
Yes, there is a reason. See this thread for the background. |
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...
|