- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I have some errors in my code.
I am doing a switch case, after receiving data from UART. The compiler isn't so happy doing a muliti character after case like: case 10<EOM>. What alternative could I do.
I have attached my code.
Thanks.
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You called handl() on line 71 w/o supplying a parameter.
After compile look at Notice List tab at bottom of screen for the Compiler output,
read the error, and double click it to highlight the line of offending code.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The CASE statement switches on a constant or a single literal.
http://www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm
So you need to encode the literal expression you have either to a single literal
or a numeric value.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You called handl() on line 71 w/o supplying a parameter.
After compile look at Notice List tab at bottom of screen for the Compiler output,
read the error, and double click it to highlight the line of offending code.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is the sequence "<EOM>" really consisting of the characters '<','E','O','M','>' or is it ment to be the ascii control character for end-of-message which is 0x19. I would suggest you to use the debugger to verify which characters are received.
Keep in mind that when you have got once a correct message you will have to reset your logic for a new message.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not sure, but some minor changes -
void handl(uint8 Rx) {
// delay
switch( Rx ) {
case 'A' :
Pin_1_Write(1); // set pin high ready to send;
CyDelay(5); // delay
UART_1_PutString("Tyv");
CyDelay(5); // delay
Pin_1_Write(0); // set pin low, ready to receive again.
break;
case 'B' :
UART_1_PutString("Validation");
UART_1_PutString("2");
break;
case 'C' :
Pin_2_Write(1); // Set Led hight
UART_1_PutString("Contact Server");
UART_1_PutString("3");
break;
}
}
void plccom( ) {
if(UART_1_GetRxBufferSize() != 0 ) {
Rxbuffer[i++] = UART_1_GetChar();
//UART_1_PutString(Rxbuffer);
}
Rx = ' ';
if (strstr(Rxbuffer, "10<EOM>") != NULL) Rx = 'A';
if (strstr(Rxbuffer, "1OK<EOM>") != NULL) Rx = 'B';
if (strstr(Rxbuffer, "1OK<EOM>") != NULL) Rx = 'C';
if (strstr(Rxbuffer, "1OK<EOM>") != NULL) Rx = 'D';
if ( Rx != ' ' ) handl( Rx );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi again
I got it to work thanks for the advise (In my way ;)).
I want one more application to work. If entering Case A (receiving 10<EOM>) I want to listen again to the UART, and then if the statement is true (receiving 10k<EOM>) enter case B.
The code is attached.
Best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You change the handl() to return a flag if EOM was invoked, set the flag in the EOM CASE,
and call the function again with Rx of 'B' if that is true after the first call to handl(). Clear the
flag after you execute the second CASE.
Just a little advice, indent your code, its difficult to read. Indents
occur on test statements, take a look at the attached file in Creator
as an example.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you not want to execute CASE A if 10<EOM> received ?
Or do you want to execute CASE A when 10<EOM> is received, then
if immediately following you get a 10K<EOM> execute CASE B ? Which
is the way the code works now.
List all possible conditions for executing CASE A and B.
The way to see this is to draw a flow diagram to work out the logic, then write the
code.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Exactly, I want to execute case A, when 10<EOM> is received, and then I am waiting on a confirm (1OK<EOM>) and when I receive this confirm, I should execute CASE B:
Pseudocode:
If received 10<EOM> execute CASE A,
wait for 1OK<EOM>, If 1OK<EOM> is received execute CASE B:
But at the moment that's not what the code is doing. When receiving 10<EOM> it correctly executes CASE A, but when I send 10K<EOM> , it does not execute CASE B, but continuing executing CASE A.
Best regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Set a breakpoint in the CASE statement code, say at line 25, and look at
Rx and the Rxbuffer, for the case where you think the buffer has "1OK<EOM>"
in it.
Note you typed
if (strstr(Rxbuffer, "1OK<EOM>") != NULL) Rx = 'B';
is "1OK<EOM>" supposed to be typed as "10K<EOM>",
eg the second letter is a zero, not the letter O ?
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok.
I have now tried to debug both using the PsoC3 debug tool and the printf (UART_PutString).
It seems that Rxbuffer doesn't get all the characters, when sending 1OK<EOM>. What I can see is that it cuts off the first byte, so this is whats inside the buffer OK<EOM>.-
Yes. it is 1OK<EOM> , I have changed that in the code.
Thank you 😉