8051 cannot get serial port 1 to work

@ work I am programming an extended 8051 softcore on a cyclone FPGA chip in C. The Keil website sent me here, so I hope I am asking in the right place.

Our hardware has an additional POF (plastic optical Fiber) connector connected to serial port 1. It is never used.  But we have found a purpose for it. We also have boards on the other end of the POF which translate it back to RS232. We know that these boards work.

In my current setup I attempting to echo bytes which are received on serial port 0 (which works) on serial port 1 and vice versa. But nomather what I try I cannot get the serial 1 interrupt to fire. As far as I know I have the relevant SFR's set up properly.

extern void serial_init1(void) {
	uint8 i=BUFFER_SIZE;
	//SCON = 0x50; // SERIAL CONTROL // different registers needed here

	for(; i!=0 ; i-=1 ) {
		txBuffer1[i]=0;
		rxBuffer1[i]=0; }

	tx_in1 = 0;
	rx_in1 = 0;
	tx_out1 = 0;
	rx_out1 = 0;
	tx_buffer_empty1 = 1;
	rx_serial_buffer_empty1 = 1;
	tx_buffer_size1 = 0;
	SerialAvailable1 = 0;

	//S1RELH = 0x03;
	//S1REL = 0xFD;

	IEN2 = 0;
	IEN2 |= ES1;

	S1CON = 0;   /
	S1CON |= REN1;
	S1CON |= SM11; 
}

And EA (enable all interrupts) is set after calling this function. I cloned all serial functions of serial port 0 and adjusted the registers.

The interrupt looks as follows:

void ISR_serial1(void) interrupt serial1_vector using 2 {
	IEN2 &= ~ES1;
	P4 ^= 0xCC;
	if(S1CON & RI1) {
		P0 ^= 0xCC;
		S1CON &= ~RI1;
		rxBuffer1[rx_in1++] = SBUF1;
		SerialAvailable1++; }

	if(S1CON & TI1) {
		S1CON &= ~TI1;
		P8 ^= 0xCC;
		if (tx_out1 == tx_in1 ) {
			tx_buffer_empty1 = 1;
			tx_buffer_size1--; }
		else SBUF1 = txBuffer1[tx_out1++]; } // put the next uint8 in SBUF
	IEN2 |= ES1; }

 I have also tried to manually load an a byte in S1BUF to trigger the ISR. I am turning on LEDs on 3 ports for visual feedback. No LED will burn. serial1_vector is defined as 16 which corresponds with the correct vector address 0x83.

I've been told that serial port 1 has worked in the past in assembly code. I have looked into the code and the interrupt code was filled but unused, but all other functions to send and read bytes were stripped. And it was turns off (IEN2 bit 0 was off).

The functions to send and read bytes:

extern void serialWrite1(uint8 c) {
	IEN2 &= ~ES1;

	tx_buffer_size1++;
	if (tx_buffer_empty1 == 0) {
		txBuffer1[tx_in1++] = c; }
	else {
		tx_buffer_empty1 = 0;
		SBUF1 = c; }

	IEN2 |= ES1; }

extern uint8 serialRead1(void) {
	uint8 c;
	IEN2 &= ~ES1;
	if(SerialAvailable1 > 0) SerialAvailable1--;
	c = rxBuffer1[rx_out1++];
	IEN2 |= ES1;
	return c; }

In the main loop I only echo bytes:

void main() {
	bit PIGS_CAN_FLY;
	
	init();

	PIGS_CAN_FLY =  true;

	print("I am serial port 0 and I work fine");
	print1("I am serial port 1 and I work fine");// does not work at all

	while(PIGS_CAN_FLY == true) { // start mainloop

		//CAN(); 
		//roundRobinTasks();
		
		//newWals();
		//letterRol(); } }

		if(!lightHandlerT) {
			lightHandlerT = 5;
			P6 ^= 0xcc; }

		if(SerialAvailable) {
			unsigned char b;
			b = serialRead();
			print("\r\necho\r\n");
			serialWrite(b);
			serialWrite1(b); }

		if(SerialAvailable1) {
			unsigned char b;
			b = serialRead1();
			print("\r\necho1\r\n");
			serialWrite1(b);
			serialWrite(b); } } }

Of course it may be that our hardware is bugging. But to verify that, I first need to know If I have taken every step in software.

Am I making a mistake?

Parents
  •  I'm trying to make a program in the 8051 machine language that allows me to ... remained connected during the tests so I can't blame lack of power. ... ;serial INT push PSW setb RS0 ;all serial functions use bank 1. jbc RI,rxdf jbc TI ... mov R0,#RXBUFS+17 clr RS0 ret ;Get byte as A from receiver stack. getrx:

Reply
  •  I'm trying to make a program in the 8051 machine language that allows me to ... remained connected during the tests so I can't blame lack of power. ... ;serial INT push PSW setb RS0 ;all serial functions use bank 1. jbc RI,rxdf jbc TI ... mov R0,#RXBUFS+17 clr RS0 ret ;Get byte as A from receiver stack. getrx:

Children
  • I'm trying to make a program in the 8051 machine language that allows me to ... remained connected during the tests so I can't blame lack of power. ... ;serial INT push PSW setb RS0 ;all serial functions use bank 1. jbc RI,rxdf jbc TI ... mov R0,#RXBUFS+17 clr RS0 ret ;Get byte as A from receiver stack. getrx:

     UART or Serial communication in 8051 microcontroller and PC.  But when comes to a Microcontroller, we cannot afford to dedicate many pins for  To establish communication between a controller and PC, we must use serial I/O protocol  whereas for mode 1 and 3 it is determined by means of timer 1 .

    www.mcdvoice.com

More questions in this forum