12-06-2009 11:47 AM
I need to send out serial transmissions continuosly at different time periods and between the transmissions I also need to look for data being recieved.
At the moment I have got things working by first setting up my serial coms port and then feeding this into 3 seperate while loops where data is sent out at different times. Loop 1 running at 80ms loop 2 at 160ms and loop 3 at 340ms. Data is read back in loop 2 after a wait period of 20ms.
This config works sort of ok but occasionally I loose data on the read.
Is there a better way of doing this?
Solved! Go to Solution.
12-06-2009 12:31 PM
send out the data in just one loop and wait only as long as you need for the next transmit,
Don't use wait until multiple ms because that one has an upredictable first wait.
use a compare with the system clock each 10 ms, or use a wait multiple of 20 ms and check if you need to send something.
Reading is done in a separate while and only the data you expect and is available, so check for Number of bytes available
good luck
12-07-2009 02:25 AM
Hi Albert
I have put the time function into a loop as suggested and also put a check for multiple time that triggers a case statement. The main loop would hold the fastest serial write with the case statement holding the first delayed serial write and so on.
Problem is the case statement does not function at an exact multiple of the main loop and an error slowly builds.
Thanks Jack
12-07-2009 03:26 AM
12-07-2009 03:53 AM
I have taken out the two of the wait until multiple so just the one. What is happening is that the 2 outputs are in sync when first started but when the case resets at 50 the count goes out by 1 and then after next 50 count it goes out by 2 and so on with error increasing.
There is something really obvious I am missing here,
thanks Jack
12-07-2009 08:56 AM
Hi
Indeed, you don't have to reset the starttime.
And only if you run more than I believe 49 days you should take care of the reset of the timing.
And make sure that all messages are sent within the time connected to the wait multiple.
even better take the gmd (in this case 20ms) to have as much time to sent stuff.
12-15-2009 01:09 AM
Albert
Thanks for solution and sorry for delay in reply, works a treat. Had to do a bit of juggling with the serial read because I found it had to always follow one specific write or errors occasional appeared in the read data.
Cheers
Jack