Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] AT89S52 receive is not working - 8051 RI interrupt Need urgent help

Status
Not open for further replies.

mprabu20

Newbie
Joined
Dec 31, 2023
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
14
Hi experts,

I am using AT89S52 microcontroller to implement a generic relay board. I am using RS232 to communicate.
when we sent data from laptop, RI interrupt is not being raised, and receive is not working. If I try only transmit its working fine. When I simulate on keil its working. But it fails on proteus simulation and on hardware. Please some one help.

Here is my code.

Code:
#include <reg51.h>
/* ---------------------------->This code is commented and working only transmission.
void main () {
    SCON = 0x50;
    TMOD = 0x20;
    TH1 = 0xFD;
    TR1 = 1;
    SBUF = 'Y';
    while (TI == 0);
    TI = 0;
}----------------------------------Till this commented
*/
volatile bit rx_flag = 0;
volatile char rdata = 'K';
void init_serial();
    void main() {
     init_serial();
    while ( 1 ) {
    //RI = 1;
        if (rx_flag == 1) {
            SBUF = rdata;
            while (TI == 0);
          //rdata++;
            TI = 0;
          
      rx_flag = 0;
        }
  }
}


void init_serial() {
    SCON = 0x50;
    TMOD = 0x20;
    TH1 = 0xFD;
    TR1 = 1;  
    ES = 1;       // Enable serial port interrupt
  EA = 1;       // Enable global interrupts
    //P3 = 0x03;
}

void serial_isr() interrupt 4 {
  
    if (RI) {
        rdata = SBUF;
        RI = 0;                // Clear the receive interrupt flag
        rdata++;/// = '7';
              rx_flag = 1;           // Set the flag to indicate that data has been received
    }
}
 
Last edited by a moderator:

HI,

what is "RI" interrupt?

"Ring indicator" signal form RS232?
In most cases this signal is not used at all.
Show your schematic.
You say "laptop". Does it provide a full featured RS232 interface?

I see you treat it as "Receive Interrupt".
We don´t see how you test it.
How can you be surre main() is running at all?
How can you be sure it does not hang on the "while (TI == 0) " line?
If you use port outputs for debugging you may easily see with a scope what happens.

Are you sure the RI and interrupt is correctly used?
You don´t provide a link to the datasheet, so we can´t validate.
There should be plenty of correctly working code examples in the internet. I assume the chip manufacturer provide some, as well as Keil.
Also: application notes and videos..


Klaus
 

Problem might be that neither TI isn't handled in serial interrupt routine nor interrupt is disabled during transmit. Processor can be caught in an endless interrupt.

However, as you say code is failing in Proteus as well, why not using debugger to see how and why it's failing?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top