Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

UART CHR(0)

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
medifa

Bascom Member



Joined: 19 Jun 2017
Posts: 1

PostPosted: Mon Jun 19, 2017 9:01 am    Post subject: UART CHR(0) Reply with quote

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 = 1 to 29
            if in_com2(stringzaehler)=0 then
               ergebnisstring=ergebnisstring + chr(000)
            else
               ergebnisstring = ergebnisstring + str(in_com2(stringzaehler))
            end if
         next stringzaehler
         er=crc16(ergebnisstring(), 29)

         lbyte = er and 255
         shift er,right,8
         hbyte = er and 255

 


(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.7.8 )
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2156

netherlands.gif
PostPosted: Mon Jun 19, 2017 9:58 am    Post subject: Reply with quote

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.com Bascom code vault
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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