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;
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?