I try my best to translate the manual as the manual is originally written in Chinese language. The manual is too simple and not really provides the details.
serial port setting:
- 1 start bit + 8 data bit + 1 stop bit, no parity
- baud rate: 4800 baud
- 5 bytes format, 60 packages per second, bit 7 is the synchronous bit
byte 1:
- bit 7: synchronous bit, as 1
- bit 6: 1=instruction for pulse sound
- bit 5: 1=SpO2 decrease, 0=OK
- bit 4: 1=searching time too long, 0=OK
- bit 3-0: signal strength (0-8), represent signal strength of pulse
byte 2:
- bit 7: synchronous bit, as 0
- bit 6-0: pulse wave diagram
byte 3:
- bit 7: synchronous bit, as 0
- bit 6: pulse rate bit 7
- bit 5: 1=search pulse, 0=OK
- bit 4: 1=sensor error, 0=OK
- bit 3-0: pulse bar diagram
byte 4:
- bit 7: synchronous bit, as 0
- bit 6-0: pulse rate, (bit 6 to bit 0)
byte 5:
- bit 7: synchronous bit, as 0
- bit 6-0: SpO2
OK - it has only one stop bit. It appears that various manufacturers use their own protocol.
60 packets per second x 5 bytes per packet x 10 bits per byte = 3000 bits per second which, at 4800bps, means 30 (or fewer - depends on pace) idle bit-times between packets.
I would capture 10 bytes, scan them for the first initial byte (>127) and then look at the following 4 bytes for your data.
EDIT: 9 bytes would guarantee one complete packet.
Last edited by dhouston; - 16th June 2009 at 18:10.
Hmm, seems that is like the pdf I posted. Is it the same module?
Based on the infos and the idea of Dave's:
Hope this will get you started. Don't forget the defines for the Hserout command to set it at 9600.Code:array var byte[9] temp var byte i var byte j var byte get_new_data: SerIn2 PORTB.7,16572,[str array\9] for i=0 to 8 temp=array[i] if temp.7=1 then goto send_at_9600 next i hserout ["Not found!",13,10] goto get_new_data for j=i to i+4 hserout [array[j]] next j goto get_new_data end
Ioannis
You need only scan the first five bytes to find the start of a packet. And you can save one step on each loop.Code:for i=7 to 39 STEP 8 if array[0].i=1 then goto send_at_9600 next i
Last edited by dhouston; - 17th June 2009 at 17:03.
Thanks for the suggestions, but the result I get is still not correct.
Have anyone tried to send an endless stream of bytes to PIC and then resend the stream back to PC? Will the input bytes same as the output bytes?
Please post you complete code as is now.
Of course the PIC will send the correct bytes as received, why shouldn't??
Ioannis
Bookmarks