Hi All, I am using TI MSC1212Y5 8-bit micro controller. It has 2 serial ports. I am trying to operate them independently. I am able to transmit the data on both ports. But I am unable to receive the data from second serial port(UART1). I have written simple interrupt driven routines for both ports. Also please tell me is it possible to use printf with both ports. Bcoz currently I am able to use printf with only one port. The code which I am using for the first problem above is as-
Thank you.
#include "reg1212.h" #include "stdio.h"
#define SET 1 #define RESET 0
unsigned char ch_0,ch_1; extern unsigned char port;
void init_port(); void send_out_0(unsigned char); void init_port1(); void send_out_1(unsigned char out1);
unsigned char port;
void main() {
init_port(); init_port1(); flag=0; // IE=0x60; // IP=0x60;
EA=1; while(1) {
//Read character from UART1 and Transmit over UART0 while(!ch_1); send_out_0(ch_1); ch_1=0;
//Read character from UART0 and Transmit over UART1 while(!ch_0); send_out_1(ch_0); ch_0=0;
}
void init_port() { P3DDRL|=0x07; //Define port3 for alternate fucntions P3.0=RXD and P3.1=TXD
SCON=0x50; //Rcv enable mode2 1 start bit 8Data bits 1 Stop bit. RCAP2H=0xFF; //To generate baud rate of 9600 ..clk 25Mhz RCAP2L=0xAD; T2CON=0x34; //timer2 enabled for Baud generation of both Rx and Tx ES0=1; //Enable serial0 INTR // EA=1; // TI_0=1; //To initiate first character Xmission
//----------------------------------------ISR for UART0------------------------------------------------------------
void serial_Intr_0(void)interrupt 4 { if(RI_0==1) { ch_0=SBUF0; RI_0=0;
else if(TI_0==1) {
TI_0=0;
} }
void send_out_0(unsigned char out) { SBUF0=out; while(TI_0==0); //Wait while char is Xmitted TI_0=0; }
void init_port1() { P1DDRL|=0x70; SCON1=0x50; TH1=0XEC; //9600 Baud rate CKCON|=0x10; TMOD|=0X20; //Timer1 mode 2 TR1=1; ES1=1; // TI_1=1; // EA=1;
void send_out_1(unsigned char out1) {
SBUF1=out1; while(TI_1==0); //Wait while char is Xmitted TI_1=0;
//-----------------------------------------ISR for Serial INTR 1(UART1)-------------------------------------------------- void serial_Intr_1(void)interrupt 7 {
if(RI_1==1) { ch_1=SBUF1; RI_1=0;
else if(TI_1==1) { TI_1=0;
Have you tried to search on this forum about the use of printf with multiple serial ports? If you search for existing answers, people don't have to spend time to answer again, and again ;)
By the way: Have you read the instructions how to post source code? Whenever you make a post, the input form have a description about how to include source.
Thanx a lot. I will read those threads. But could you please tell me whats wrong with my INTR driven routine which I have posted above?
"which I have posted above?"
You posted it but, as already mentioned, you didn't read the instructions on how to post source code - so it's illegible.
The instructions are quite clear & easy: www.danlhenry.com/.../keil_code.png
Don't manually re-type the code into the post - use only copy-and-paste;
Note that TABs don't work (well) - use spaces instead,
and don't forget to check it in the 'Preview'...
Hello all, I have copied and pasted the code here ..Pls let me know what's wrong with this INTR routine..coz I am unable to receive data on second serial port. RI_1 is not activating at all.
#include "reg1212.h" #include "stdio.h" #define SET 1 #define RESET 0 unsigned char ch_0,ch_1; extern unsigned char port; void init_port(); void send_out_0(unsigned char); void init_port1(); void send_out_1(unsigned char out1); unsigned char port; void main() { init_port(); init_port1(); flag=0; // IE=0x60; // IP=0x60; EA=1; while(1) { //Read character from UART1 and Transmit over UART0 while(!ch_1); send_out_0(ch_1); ch_1=0; //Read character from UART0 and Transmit over UART1 while(!ch_0); send_out_1(ch_0); ch_0=0; } } void init_port() { P3DDRL|=0x07; //Define port3 for alternate fucntions P3.0=RXD and P3.1=TXD SCON=0x50; //Rcv enable mode2 1 start bit 8Data bits 1 Stop bit. RCAP2H=0xFF; //To generate baud rate of 9600 ..clk 25Mhz RCAP2L=0xAD; T2CON=0x34; //timer2 enabled for Baud generation of both Rx and Tx ES0=1; //Enable serial0 INTR // EA=1; // TI_0=1; //To initiate first character Xmission } //-----------------ISR for UART0- void serial_Intr_0(void)interrupt 4 { if(RI_0==1) { ch_0=SBUF0; RI_0=0; } else if(TI_0==1) { TI_0=0; } } void send_out_0(unsigned char out) { SBUF0=out; while(TI_0==0); //Wait while char is Xmitted TI_0=0; } void init_port1() { P1DDRL|=0x70; SCON1=0x50; TH1=0XEC; //9600 Baud rate CKCON|=0x10; TMOD|=0X20; //Timer1 mode 2 TR1=1; ES1=1; // TI_1=1; // EA=1; } void send_out_1(unsigned char out1) { SBUF1=out1; while(TI_1==0); //Wait while char is Xmitted TI_1=0; } //----------------------------ISR for 1(UART1)-------------------------------------------------- void serial_Intr_1(void)interrupt 7 { if(RI_1==1) { ch_1=SBUF1; RI_1=0; } else if(TI_1==1) { TI_1=0; } }
Ameya, You must read the comments regarding printf as recommended by Per...
See http://www.keil.com/support/docs/788.htm
Thanks a lot Tamir, Yes I have gone through the printf related links and the problem of using printf with both ports has been solved.
But now my problem is i am not able to receive data on second serial port. RI_1 is not setting high at all. I have tried using _getkey() function.. but its poling function. I want INTR driven routine. Could you please suggest me any solution???Why my INTR driven routine is not working?
"Am I not adorable...?"
Tamir,
Whenever I read one of your posts I have an unmaskable urge to interrupt my normal operation and execute a five minute romp!
Keep romping!
Miss Embededd, Are you my STR9? that would explain why the darn this keeps crashing :) :) :)
Ameya, I am not a C51 guy actually, but did you check that your peripherals (UART, interrupt controller (do you even have one???) are configured to generate an interrupt for the second UARTs? did you check your interrupt masks?
Each romp takes five minutes.
You add one post each 4 minutes.
There is no option except for re-entry!
you should see me bake a cake :)
Ooooooohhhhhhhhhh ... I can't take any more!