- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi.
I have a problem with reading from a UART. I have attached a code file.
When I try to receive data using GetChar() function,. I can't read more than 3 bytes.
I am running a for loop to get all the bytes in a buffer. Anybody who have a solution?
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should concentrate on receiving a complete string before you make any other actions. The logic behind your do-while loop will start to send repeatedly when part of your message is received. Using _GetRxBufferSize is quite correct and will work as expected.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No ideas out there? 😉
Best regards -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- 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 should concentrate on receiving a complete string before you make any other actions. The logic behind your do-while loop will start to send repeatedly when part of your message is received. Using _GetRxBufferSize is quite correct and will work as expected.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I have now made a functionality which reads all bytes first (I have test this in main, it works flawless, but does not work in the sendATcommand function), and then goes to the do while statement (comparing statement). But it unfortunately does not work.
(look at the sendATcommand2)
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way , GPRS_1_PutString(ATcommand), should be in the while(1) statement. 😉 It should send out repeatedly until it receive the correct answer.
Best regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
while(1) {
GPRS_1_PutString(ATcommand);
CyDelay(2000);
if(GPRS_1_GetRxBufferSize() != 0) {
response = GPRS_1_GetChar();
if(response =='\r')
break;
i++;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi again:
I have made some research and I find out it probably would be best to use an interrupt routine, to get a string.
I have changed the code, so it gets all the bytes, when Rx is interrupted. The code does not work, I am not sure how to call an interrupt routine from a function (sendATcommand2) .
Best regards. Hope you can help me 😉
- 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
Thanks for the response.
I have read your comments. What the code should do is .
1. Send ATcommand. (line 125)
2. Get back the response (line 104)
3. Compare the response with the ATcommand. (line 131, 138)
4. If there is a match break (continue to next statement)
5. if there is not a match repeat the process (SendATcommand again, this why I use else to break). (line 143)
By the way, the ReadString function repeat sending <0>, even though I expect OK back. (using bray terminal).
- 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
Hi Bob.
Haha, that's Ok.
It seems that, when I put a character in the buffer - it never leaves the ReadString function. It reads the characters and returns back to GPRS_1_GetRxBuffersize() wait.
What if I am waiting for a Connect OK, to be received should I use \n or something else.
Best Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would suggest you to check what string exactly is received using the debugger. Whether it is a \n or a \r or both (or none) you will see. You may even alter the ReadString() to have the delimiter as a parameter in case you need that. At least I would #define the delimiter for easiest adaption.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Again
I have check with the debugger - it returns /r. This part works now.
I have difficulties writing a code, which keeps sending ATCommand, until the correct answer has been received. .
AT the moment it first sends ATcommand (line 137)
and then waits until received data. How can I make it keep sending ATcommand until the right answer has been received.
Thanks . 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can do that exactly as you wrote:
Repeat
Send AT-command
until answer satisfies
Since C-language has no Repeat-Until statement you need a small modification
Do
Send AT-Command
while Not(answer satisfies)
😉
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi.
I found a much easier way to do the job.
I have a question more (if thats Ok). I want to use a Timer, to count the time.
I want to use a timer in this task.
Like: if (strstr(resp, "<EOM>") != NULL && Timer_1_ReadCounter() > 929496720 )
{
do this....
}
else do something else.
if I get <EOM> and the time is under 17.896s -- it should execute the statement. At the moment it doesnt work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We cant tell with just this code snippet what the timer config is
and when you init it and what you do if it rolls over.....
Consider posting your project, makes life easier to troubleshoot.
“File” Creator
“Create Workspace Bundle”
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content