Hello,
I'm using the XC164CS-32, 40 MHz, and I'm experiencing some problems with the ASC0 port where it seems that its not synchronizing with the program I wrote in C#. The application I wrote will send out at least 6 ASCII characters, but no more than 9.
#define TIMEOUT_100MS 31250 #define EBCMOD0_SETTING 0x1820 #define EBCMOD1_SETTING 0x003F #define FCONCS1_SETTING 0x0031u #define TCONCS1_SETTING 0x0181u #define ADDRSEL1_SETTING 0xB000u #define PORT1_HIGH_DIRECTION_SETTINGS 0x0F #define PORT1_LOW_DIRECTION_SETTINGS 0xFF #define PORT3_DIRECTION_SETTINGS 0xB620 #define PORT4_DIRECTION_SETTINGS 0x00FC #define PORT9_DIRECTION_SETTINGS 0x0001 #define SYS_RDY P1H_P0
void main(void) { char temp_string[9] = "\0"; char label[3] = ""; int i = 0; ASC0_FDV = 0x003B; /* load ASC0 fractional divider register */ ASC0_BG = 0x000E; /* load ASC0 baud rate time reload register */ ASC0_CON = 0x88D1; /* load ASC0 control register */ DP1L = PORT1_LOW_DIRECTION_SETTINGS; DP1H = PORT1_HIGH_DIRECTION_SETTINGS; ALTSEL0P3 = 0x2720; ASC0_TIC = 0x01B9u; ASC0_RIC = 0x01F9; DP3 = 0xB620; P3_P10 = 1; P1H_P3 = 0; /* Disable the loopback relays */ ASC0_RXFCON = 0x0607; ASC0_RXFCON = 0x0605; GPT12E_T3CON_T3R = 1; /* Start the timer T3 */ printf ("Initialized\n"); setup(); update();
while (1) { if (GPT12E_T3 > TIMEOUT_100_MS) { GPT12E_T3 = 0; /* Reset the timer */ update(); }
// if ( (ASC0_FSTAT & 0x0F) != 0) if ( (ASC0_FSTAT & 0x0F) > 6) { gets(temp_string, 9); if (strcmp(temp_string, "status") == 0) printstat(); else if (strlen(temp_string) < 8) { printf("sync error. purging RX buffer...\n\n"); for (i = 0; i < 100; i++) ASC0_RBUF = 0x0; ASC0_RXFCON = 0x0607; ASC0_RXFCON = 0x0605; }
else { label[0] = temp_string[6]; label[1] = temp_string[7]; label[2] = '\0'; printf("\nInput: %s \n", temp_string); printf("\nhex label: %s \n",label); if (strcmp(label,"38") == 0) { // some code } if (strcmp(label,"72") == 0) { // some code } if (strcmp(label,"8A") == 0) { // some code } strcpy(label,""); ASC0_RXFCON = 0x0607; ASC0_RXFCON = 0x0605; } } }
My problem lies in the following IF statement:
if (ASC0_FSTAT & 0x000F) != 0)
For some strange reason, it's not getting the first two characters that I send to it via RS232 and it seems to be some kind of synchronization problem.
I thought I would change the situation by replacing the != 0, but when I try making it greater than 6 (> 6), it will hang and will no received data is coming in.
Does any one see a problem and can help me out?
Steve