How do I get Parameters with UART Receive

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
antrc_3264986
Level 3
Level 3

I have implemented a semaphore based uart task as specified by the PSoC 101: Lesson 2-1b. However, I want some commands to allow the user to enter parameters. Is there an example that allows the user to enter parameters after selecting a command?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hi,

Can you try this idea and see?

1. Generate an interrupt every time a character is received.

2. Start forming the packet till carriage return is not received

3. Once the packet is ready, give the semaphore from ISR. This will unblock the UART_Processtask

5. Separate the command and parameters in the UART_Processtask

The sample project is attached with this comment. Let us know in case of any clarifications.

Regards,

Bragadeesh

Regards,
Bragadeesh

View solution in original post

0 Likes
3 Replies
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Could you please elaborate your request? A simple test case would be helpful to understand your requirement.

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes

Bragadeesh,

The user would select a command with a single keystroke. That command would require input, such as a numeric value. So, the command would be to set a parameter and there is the need for a user response, which is the numeric value.

The semaphore design only allows a single character to be entered and a getchar() receives the command character. The UART task is blocked at xSemaphoreTake(). Next the task processes the single command character.

How do I get the parameter value from the UART? Is there example code that I can use?

The polling code allowed the building of a user response string. A call to a function getUserReponse() could block the command processing until a turnaround character LF. A flag would be set in the UART task and the getUserResponse() would unblock. The command processor function would then process the user response string (i.e. sscanf the parameter value).

With the semaphore design I cannot block the UART task.

Is this enough to go on? Thanks.

0 Likes
lock attach
Attachments are accessible only for community members.

Hi,

Can you try this idea and see?

1. Generate an interrupt every time a character is received.

2. Start forming the packet till carriage return is not received

3. Once the packet is ready, give the semaphore from ISR. This will unblock the UART_Processtask

5. Separate the command and parameters in the UART_Processtask

The sample project is attached with this comment. Let us know in case of any clarifications.

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes