# Serial packet transfer from RCM5600w to Crystalfontz LCD module

**URL:** <https://forums.digi.com/t/serial-packet-transfer-from-rcm5600w-to-crystalfontz-lcd-module/10581>\
**Category:** Rabbit\
**Created:** [March 2, 2011, 12:51am UTC](https://forums.digi.com/t/serial-packet-transfer-from-rcm5600w-to-crystalfontz-lcd-module/10581 "2011-03-02T00:51:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![howman](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@howman](https://forums.digi.com/u/howman)\
**Post date:** [March 2, 2011, 12:51am UTC](https://forums.digi.com/t/serial-packet-transfer-from-rcm5600w-to-crystalfontz-lcd-module/10581/1 "2011-03-02T00:51:16Z")

</div>

All, I have an issue trying to send serial packet data between an RCM5600W mini-core with deluxe dev kit (Serial Comm board) to a Crystalfontz CFA635 LCD module. I am using Dynamic C 10.64. The sample code puts.c transmits to hyperterm correctly, but the Crystalfontz LCD expects CRC checked packets. I have used their CRC algorithm to create the packet structure, but when I try to send it,the display and hyperterm do not read it correctly. I have tried a few different baud/bit combos, but nothing. Any ideas would be appreciated. Test code sample below.  
Thanks in advance.

```auto

#define CINBUFSIZE 31
#define COUTBUFSIZE 31
#include 

unsigned short get_crc(unsigned char count,unsigned char *ptr)
{
	unsigned short crc; //Calculated CRC
	unsigned char i; //Loop count, bits in byte
	unsigned char data; //Current byte being shifted
	crc = 0xFFFF; // Preset to all 1's, prevent loss of leading zeros
	while(count--){
		data = *ptr++;
		i = 8;
		do{
			if((crc ^ data) &amp; 0x01){
				crc &gt;&gt;= 1;
				crc ^= 0x8408;
			}
			else
				crc &gt;&gt;= 1;
				data &gt;&gt;= 1;
		} while(--i != 0);
	}
	return (~crc);
}

void main()
{
#define MAX_DATA_LENGTH 22
	struct command_packet{
		unsigned char command;
		unsigned char data_length;
		unsigned char data[MAX_DATA_LENGTH];
		unsigned short CRC;
	}packet;
   int ret;
	// Welcome message for display
   char initdisplay[] = "WiFi Msg Center";
  	packet.command = 31; //31 is command type to send to LCD
   /* data_length = length of string +2 for the row and col arg */
   packet.data_length = strlen(&amp;initdisplay[0]) + 2;
   packet.data[0] = 0; /* row to send to*/
   packet.data[1] = 0; /* col to send to*/
   strncpy(&amp;packet.data[2], initdisplay, strlen(initdisplay));
   printf(" packet.data[2] -&gt; [%d]: \"%s\"
", strlen(&amp;packet.data[2]), &amp;packet.data[2]);
   printf(" packet.data length: \"%d\"
", strlen(&amp;packet.data[2]));
   printf(" packet.data location: \"%x\"
", &amp;packet.data[2]);
   printf(" packet.data: \"%s\"
", &amp;packet.data[2]);
   /* calc CRC for entire packet */
   packet.CRC = get_crc(strlen(initdisplay) +4,(unsigned char*)&amp;packet.command);
//
   serCopen(19200);
	ret = serCwrite(packet,26);
	// first, wait until the serial buffer is empty
	while (serCwrFree() != COUTBUFSIZE);
	// then, wait until the Tx data register and the Tx shift register
	// are both empty
	while (BitRdPortI(SBSR, 3) || BitRdPortI(SBSR, 2));
	// now we can close the serial port without cutting off Tx data
	serCclose();
}

```
