Posted: Mon Jun 19, 2017 9:01 am Post subject: UART CHR(0)
Hallo,
I have a problem with the UART on a ATMEGA128.
I`m trying the calculate a CRC checksum, but sometimes I receive a chr(0).
This character terminates the string so the calculated checksum doesnŽ t match.
What can I do?
Here is the code:
Code:
for stringzaehler =1to29 if in_com2(stringzaehler)=0then
ergebnisstring=ergebnisstring +chr(000) else
ergebnisstring = ergebnisstring +str(in_com2(stringzaehler)) end if next stringzaehler
er=crc16(ergebnisstring(), 29)
lbyte = er and255 shift er,right,8
hbyte = er and255
(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.7.8 )
Don't work with strings but with array's.
You have to make you own receive routine that does something with the chr(0) and put the rest in the array.
Depends on you protocol of course if this can work.
Or determine the length of the string with LEN(mystring) and then calculate the crc over this length.
Ps have a look at HIGH and LOW function to split up the crc.
Ps ,ps or use overlay to split the word up in bytes.
Dim My_word As Word
Dim Low_byte As Byte At My_word Overlay
Dim High_byte As Byte At My_word + 1 Overlay _________________ www.evertdekker.comBascom code vault
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum