计算CRC校验码 Calculate CRC check code

(made public for all to learn and help - ABG)

What is wrong with my answer at

Regarding the code you supplied,
I see something in it that can't be right:

  • while (length--)

Is length a variable?
If so, where is its type and its initial value declared?
If it is a function, what is its argument?

  • CRC_value ^= *data_value++;

Where is the variable data_value declared, and how does it get its value?


This is a defined function. I didn't truncate the previous function name definition



image
I use the program in your tutorial, using Bluetooth on my mobile phone, to send the calculated CRC to HC05 through Bluetooth on my mobile phone, and then receive the data (386B 6B 38) by the serial assistant. However, there is a series of data in front that I did not send out, and I do not need the previous data. I don't know where the previous series of data came from? Don't know if you can't let this string of data go out? So I have changed a way to calculate CRC. My CRC is calculated by the code block I sent you before. It can be expressed, and there will be no redundant data.

I know where the problem is and it has been solved. Thank you.

请将你的解决方案发上来,可以帮助其他有类似问题的人,谢谢。

1 Like

It's a shame I can't read Chinese.

I also don't know where that Modbus component came from.

How to display any hexadecimal data separately, one byte at a time (that is, two hexadecimal digits in a group or eight bits in a group)
for example:DFF Decomposition into 0D FF (with spaces in the middle)
AD Decomposition into 00 AD (with spaces in the middle)
My idea is to first convert the hexadecimal data into a standard two-byte hexadecimal number, and then display the converted two-byte data byte by byte by space.
But I don't know how to use APP INVENTOR to realize this process?

Look in the math blocks for data type conversion.

Beware, the binary conversion will give you a text string of 0's and 1's, not the compressed value you would expect.

However, you can take the text length of the binary representation, and pad on the left to 16 binary digits, then convert to hex 8 bits at a time.

This project has some of those techniques, even before MIT added bit manipulation blocks.

https://groups.google.com/g/mitappinventortest/c/Mnmk2wfTFK8/m/CkUsAbLtBgAJ

I can't access the link you sent :rofl:

Modbus is my extension. It is built on the same library as SerialOTG and provides ModbusRTU and ModbusTCP communication over serial, BT and TCP/IP. The function to calculate CRC is included.
See: ModbusRTU extension - #12 by rkl099

Here an extension for CRC16

Here's a draggable block you can use in AI2:


It has loads of bit manipulation in it.
Attribution:
by flodmotorgrodan@gmail.com at
https://groups.google.com/g/mitappinventortest/c/5m-W5pVW1u4/m/F4_0buoeAgAJ

The rest of the project:
1_5
5_5
128



IEEE754.aia (5.2 KB)





Estou com o mesmo problema. Você conseguiu gerar o CRC16 correto?

crc16.aia (6.2 KB)

https://community.appinventor.mit.edu/t/can-someone-help-me-reproduce-this-code-using-the-blocks/60372/15

There are several CRC16 algorithm, this extension receives the data in ASCII and gives the result in CRC16/CCITT-FALSE

https://crccalc.com/

What CRC16 algorithm are you using?

Sorry but I searched a lot and I couldn't understand how generate the "crc16" of a text?

Example text:
00020126580014br.gov.bcb.pix0136123e4567-e12b-12d1-a456-426655440000
5204000053039865802BR5913Fulano de Tal6008BRASILIA62070503***6304

Generated CRC:
0x1D3D.

is used for calculating the CRC, the polynomial '1021' (hexa) and initial value 'FFFF' (hexa), which corresponds to the CRC "CRC-16-CCITT-FFFF”.

thanks.

You say you convert the text:
00020126580014br.gov.bcb.pix0136123e4567-e12b-12d1-a456-426655440000
5204000053039865802BR5913Fulano de Tal6008BRASILIA62070503***6304

and you get: 0x1D3D
using:
poly: 1021 and init: FFFF

But on this website we see that this text generates: 80BF

I achieved. Thanks!