This may be something i have stared at for hours and missing the obvious, but here goes.
Communicating with a 7 segment 4digit display with its own RS232 controller.
Using a Terminal program i can send working commands to the display via a pc / Rpi.
I then used the following code in the Arduinio IDE with a Mega 2560 and it works great.
If i want to change the 4 digits displayed, i can do so but have to use an online CRCcalculator to get the CRC addition.
This works perfectly, for simple 4 digits of a known fixed value.
However i would like to create 4 random digits and then apply the CRC and send.
Arduino Mega Code:
byte message2[] = {0xFE, 0x0B, 0x01, 0x01, 0x01, 0x14, 0x01, 0x01, 0x01, 0x01, 0xFF, 0x54, 0x66 }; // displays 1111 on the display.
Serial1.write(message2, sizeof(message2));
Those between **** **** in the above code will be my random generated numbers and then the appropriate CRC at the end will of course be changed.
I have tried many examples online and none seem to work, what am i missing,?
The other values in this statement( outside of the **** ****) control the card in the display and will stay the same.
Any help would be awesome, i am pulling whats left of my hair out.
Thanks in advance,
Paul
Manufacturer datasheet includes this code for CRC : Copied exactly, however i have found other mistakes in the packet so i would expect others.
unsigned int CRC16(unsigned char *ptr,unsigned int count)
{
unsigned int crc=0;
unsigned char i;
while (count>0)
{count--;
crc=(crc^(((unsigned int)*ptr)<<8));
for(i=0;i<8;i++)
{
if(crc&0x8000)crc= ((crc<<1)^0x1021);
else crc<<=1;
}
ptr++
}
return crc;
}
