View previous topic :: View next topic |
Author |
Message |
medicb
Joined: 01 Aug 2009 Posts: 3
|
Posted: Wed Dec 06, 2017 2:32 am Post subject: Receiving 32 data bytes via UART without CR and LF - hex val |
|
|
Hi all 🙂 I need to receive packet 32 bytes of data from UART but there are not exist CR and LF on end of line. The transmit data are in one sequence without any breaks: 4 bytes of unchanging data, 12 data bytes (6 pairs of 2 bytes), 12 data bytes (6 pairs of 2 bytes), 2 bytes reserved data and 2 bytes checksum data. I can't operate on single bytes, I need to pair them. I should operate on hex values. I tried to use the WAITKEY command to wait for the first four characters and later INPUTBIN command for receive rest of data but the received data is not stable. The reading starts in random places and the data are received and converted into dec values - it's wrong for me. Example: if I have to receive "00" and "1C" I getting "0" (not "00") and "28". Second example: I should receive "01" and "23" and connect these two bytes into "0123" (hex) but I getting "0" and "35" (dec). Have no idea, please help me.
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
Tiny
Joined: 10 Nov 2010 Posts: 101 Location: The Netherlands
|
Posted: Wed Dec 06, 2017 7:06 am Post subject: |
|
|
Hello,
are the 4 byte of unchanging data always the first 4 of the 32 bytes?
use the usart interrupt and capture the received byte into a 4 byte buffer (use fifo priciepe) and compare then in your main routine after the compare is oké.
buffer the the other 28 bytes.
regards Tiny |
|
Back to top |
|
|
medicb
Joined: 01 Aug 2009 Posts: 3
|
Posted: Wed Dec 06, 2017 8:31 am Post subject: |
|
|
Yes, the first 4 bytes are always the same.
424D001C0051009100A500350060006D37E010C903EC0064001C000E93000734 |
|
Back to top |
|
|
Madf
Joined: 13 Nov 2011 Posts: 179 Location: Moscow
|
Posted: Wed Dec 06, 2017 3:07 pm Post subject: |
|
|
If send:
Code: | Dim A as Dword
Printbin A |
If receive:
Code: | Dim A as Dword
Inputbin A |
Or use standart operator print with semicolon in end.
|
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Dec 06, 2017 5:31 pm Post subject: |
|
|
hi
you can
1) read the help file about ischarwaiting
2) if yes you fill an array of byte
3) you can manipulate it with a lot of command as
CHR(N)
CHARPOS
FORMAT
FUSING
INSTR
LCASE
LEFT
LEN
LTRIM
MID
RIGHT
RTRIM
SPACE
SPC
SPLIT
STR
STRING
TRIM
UCASE
Bon courage
JP |
|
Back to top |
|
|
|