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

Problem with Serial I/O - S0BUF remains empty

Hello,

I'm trying to write a Function that reads a character from RS232 (trival?). I'm using 80c552, Serial_Mode=1.
I think the baudrate is set correct (I can transmit data to the PC).

The Problem is, S0BUF is allways empty.
I tried it on the simulator too.

I paste my code:

CLR RI
JNB RI,$ ; waiting for character
MOV R7, S0BUF ; <- here S0BUF is ALLWAYS 0x00
RET

Any ideas? I thought Serial i/o will be trival...

  • Any ideas? I thought Serial i/o will be trival...

    Often the most mundane will give you the strangest effects

    1) have you scoped on RxD?
    2) Is REN in SCON set?

    Erik

  • Please do a simple loopback test on both the ends (PC and your 80c552). This will isolate the problem much better.

    Can you post the complete code, if possible?

  • What about :

    JNB RI,$ ; waiting for character
    CLR RI
    MOV R7, S0BUF ; <- here S0BUF is ALLWAYS 0x00
    RET

  • 1. Thank you for all the answers!
    2. RxD is allways 1
    3. The complete code of the function

    char rs232_getChar(){
    #pragma asm
    CLR RI
    JNB RI,$
    #pragma endasm
    return S0BUF;
    }
    

    4. I tried allready putting the line CLR RI before and after the JNB RI,$ line

    5. REN is set - S0CON=0x50 (after ini.)

    6. I'm using eval. version of Keil software (i'm a student) and work mainly with the software simulator. I own Phytec Eval. Board with 80c552 on it. Maybe that helps...

  • 3. The complete code of the function

    how about the initialize code?

    BTW
    pragma asm
    CLR RI
    JNB RI,$
    #pragma endasm
    woul, if I did it, be
    RI = 0;
    while (!RI);

    Erik

  • RxD is allways 1

    So there is no signal at the receive pin ?

  • The initialisation function:

    char rs232_ini(unsigned int br, unsigned char modus){
    	unsigned int th_tl;
    
    	//Initialisierung von Timer
    	if (modus%2){ //nur bei den Modis, wo Timer gebraucht wird
    		switch (br){ //nur bestimmte Werte möglich, sonst Fehler
    
    			case 2400: th_tl = 0xF400; break;
    			case 4800: th_tl = 0xFA00; break;
    			case 9600: th_tl = 0xFD00; break;
    			case 19200: th_tl = 0xFD00; PCON = PCON | 0x80; break;
    			default: return 1;
    		}
    		if (timer_ini(1,2,th_tl)!=0) return 3;
    	}
    	if (modus>4) return 2;
    	modus = modus << 6;
    
    	//Initialisierung der RS232 schnittstelle
    	S0CON = modus | 0x10; // modus + reciver enable
    
    	return 0;
    }
    

    I'm trying to debug this with the Keil Software-Simulator of 80c552.
    In "Logic Analyzer" RxD is allways 1, but S0IN changes (there I can see correct values of the characters).
    The character gets lost on the way to S0BUF...

    I changed it in the "erik malunds"-way, but it does not help.