This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Trying to use serial port 2 (ASC1)

I'm trying to program the serial port 2 on the XC161CJ infineon. But i can't achieve any interesting results.
Ok, i've written code like this below, but, when i open the window serial #2, and i try to write something, nothing happen and seems that the XC161CJ goes to stall.
Someone could please help me to understand how can i accept input from serial #2? thanks!



#include <stdio.h> /* standard I/O .h-file */
#include <XC161.h> /* special function register XC161 */
#include <math.h>
#include <string.h>


signed char _getkey (void) {
char c;

while (!ASC1_RIC);
c = (char) ASC1_RBUF;
ASC1_RIC = 0;
return (c);
}


/****************/
/* main program */
/****************/
void main (void) { /* execution starts here */
/* initialize the serial interface */
#ifndef Monitor /* do not initialize if you use Monitor-166 */
P3 |= 0x0400; /* SET PORT 3.10 OUTPUT LATCH (TXD) */
DP3 |= 0x0400; /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT) */
DP3 &= 0xF7FF; /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */
ASC0_TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */
ASC0_RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */
ASC0_BG = 0x40; /* SET BAUDRATE TO 9600 BAUD @ 20MHz */
ASC0_CON = 0x8011; /* SET SERIAL MODE */
ALTSEL0P3 |= 0x0C00; /* Configure port pins for serial interface 0 */

ASC1_TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */
ASC1_RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */
ASC1_BG = 0x40; /* SET BAUDRATE TO 9600 BAUD @ 20MHz */
ASC1_CON = 0x8011; /* SET SERIAL MODE */
#endif


while (1)
{
char nome[10];
int i=-1;

nome[0]='a';

do
{
i++;
nome[i]=_getkey();
}
while (nome[i]!=0x0A);
printf("il tuo nome è %s",nome); /* An embedded program does not stop and */
/* ... */ /* never returns. We've used an endless */
} /* loop. You may wish to put in your own */
} /* code were we've printed the dots (...). */

0