We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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 (...). */
Normally, when you are new to a microcontroller, you study the User's Manual in order to understand how it works; at least try to understand the few lines of code you are modifying. I suggest you to Please read the manual and try to understand what the following lines on top of your main mean....
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) */ ALTSEL0P3 |= 0x0C00; /* Configure port pins for serial interface 0 */
Thanks, but what dou u mean wiht Please read the manual? Please can u give me some detailed information? Sono italiano come te, almeno credo dal nome. Grazie comunque Bruno, rifletterò su quello che mi hai scritto...
Have you checked SYSCON3, bit ASC1DIS ? I use the XC167CI and there the default value of ASC1DIS is 1(see errata sheet not user manual) Best Regards Bernd Paul
Thanks, and even I am using the XC167CI. I have to put it in the #ifndef preprocessor?
Hello Domenico, I know you are Italian like me. Please read the manual means Read The F***ing Manual: it makes no sense to help you if you are not trying to help yourself. Please look carefully at the Keil example you copied and try to understand it with the use of the XC manual: not only ASC0 registers are to be initialized, but Port registers connected to ASC0 too; in case of ASC0, you have to initialize port 3 bits 10 and 11 in order to use the serial interface; for ASC1 you must act in a similar way, please READ the manual to see how... Sorry if I am so direct, but I don't really think I really help you if I only give you a "ready to eat" solution. E se vuoi parlare con noi di Keil ed Infineon, siamo a tua completa disposizione, i nostri dati sono nella pagina dei distributori italiani di Keil.... ma solo dopo aver letto i Manuali! Ciao Bruno
Thanks, seguirò il tuo consiglio. E solo dopo aver letto tutto il manuale (1000 pag circa) ti scriverò!!