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.
#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) & 0x01){
crc >>= 1;
crc ^= 0x8408;
}
else
crc >>= 1;
data >>= 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(&initdisplay[0]) + 2;
packet.data[0] = 0; /* row to send to*/
packet.data[1] = 0; /* col to send to*/
strncpy(&packet.data[2], initdisplay, strlen(initdisplay));
printf(" packet.data[2] -> [%d]: \"%s\"
", strlen(&packet.data[2]), &packet.data[2]);
printf(" packet.data length: \"%d\"
", strlen(&packet.data[2]));
printf(" packet.data location: \"%x\"
", &packet.data[2]);
printf(" packet.data: \"%s\"
", &packet.data[2]);
/* calc CRC for entire packet */
packet.CRC = get_crc(strlen(initdisplay) +4,(unsigned char*)&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();
}