im working on a pendant that communicates between Grbl and the pc. its interupt driven so im not using the hardware serial libraries and im having trouble comparing some strings that contain numbers.
i usually use String objects so im sure its a simple issue due to lack of c knowledge.
the problem is the commented out "if " lines. if i compare to just the "$" it works fine but when i try the numbers if fails.
$1=200.0
$2=200.000
...
$130=200.000 (z max travel, mm)
$131=200.000 (z max travel, mm) im trying to find these 3 lines out of a list of similar.
$132=200.000 (z max travel, mm)
Please read the second and third posts by Nick Gammon at the top of this Forum on the proper way to post here, especially the use of code tags for source code. Also, how can we possibly help with only a snippet of code. That's like standing one inch away from the Empire State building and asking me how it looks.
Don't post snippets. We're all sick of wasting time looking at them - when people post snippets, particularly when they're militant about not posting the whole program, it's usually not the snippet. It may be the snippet here, but who knows whatall you're doing elsewhere - you could be doing something wrong that could be effecting your code here - for example with how you're defining the global variables, or how you've set the registers elsewhere in the code.
Have you verified the contents of GrblPositionBuffer at the point where the newline is detected? (including checking that there aren't any non-printable characters that you won't see on serial monitor - use something like hterm)
You have far too much stuff in that ISR. The code in an ISR should complete within a a number of microseconds - 100 µsecs would be very long.
In the function Pc_Write() you have this line
while (!( UCSR0A & (1<<UDRE0))); // wait while register is free
First, why would you want to wait WHILE it is free.
If you really mean wait UNTIL it is free - first, what is going to clear it while interrupts are disabled and second, how is the delay going to affect the time you are inside the ISR.
And how could we see any of this without the complete program?
Personally I wouldn't use String inside an ISR - I don't think it is re-entrant. I'm not sure about memset either.
Plus what Robin2 said about the ISR being too long. Your main loop doesn't do much. Why can't you set a flag and process the incoming data there? Then you don't need to write your own serial handlers.
bbrown:
im working on a pendant that communicates between Grbl and the pc. its interupt driven so im not using the hardware serial libraries and im having trouble comparing some strings that contain numbers.
What stops you using hardware serial libraries when using interrupts. I use both interrupts and the serial library in just about every project without any problems.
stowite:
What stops you using hardware serial libraries when using interrupts. I use both interrupts and the serial library in just about every project without any problems.
+1 This was my first thought when I read the post.