Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

communication

Status
Not open for further replies.

chandu13

New Member
hi

i interfaced two 89c51 micro controllers using RS-232.

One controller for panel and one for remote.

From panel to remote aim sending the data.

my doubt is how to receive the data from remote

Here i need only one RI (receive interrupt)

how to use the receive interrupt.

Thanks

Regards

Chandu
 
Hi

Thanks for reply

In 89c51 there is only one interrupt set aside for serial communication.
This interrupt is used to both send and receive the data.
My problem is i need only receive interrupt while aim taking data from remote.
I don’t need transmit interrupt while sending the date to remote.

How to enable the receive interrupt and how to disable the transmit interrupt during the communication.

Regards

chandu
 
The solution to your problem is simple.

In the interrupt service routine you check first for the Receive Interrupt (RI == 1). Then check for the Transmit Interrupt Flag and set it equal to zero. Do not use an if..else structure, use the following template.

Code:
  if(RI == 1)
  {
    RI = 0 ;
    ....
  }
  if(TI == 1)
  {
    TI = 0 ;
    ....
  }
 
Last edited:
Hi

Thanks for the reply

Aim receiving the continuous data from remote.

When first data is come interrupt well occur it well go to the ISR (interrupt service routine)and it stores data in one variable. Immediately 2nd data well come at that time again interrupt well occur or it continues the ISR.

I have to store first 4 date items in 4 variables.

Regards

chandu
 
That's why something called handshaking exist!
If your data provider sends data faster than the receiver can handle, data will bo lost.
So be sure that the provider send slower than the receiver can handle or use handshaking. Receiver ask data, provider send data.

On the other hand, processing data in the receiver is done in a few µs. Sending 1 byte @9600baud cost 833µs. In that time you can execute a lot of code, so the ISR will certainly be finished before the next byte arrived in SBUF.

DO NOT FORGET TO CLEAR RI when you processed the received data (and TI if used) like Papabravo already told!

Did you read the tutorial I provide? I hope so :)
Did you read a little bit more? I don't think so because the next tutorial **broken link removed** handle interrupts. The whole concept of serial intrerupt is well explained there.
 
You need to store the incoming data in a FIFO queue. This can be implemented with an array of unsigned char. As indexes into the array you need a "get" pointer and a "put" pointer. Although not strictly required it is convenient to have count of the number of items in the queue.

The interrupt routine "puts" items (characters) into the queue and the application program takes them out whenever the count is greater than zero.
 
Keep also in mind that you don't need the interrupt at all. You can poll the RI flag at regular time and handle if necessary. If your program is controlled by a state machine, one state can be "CheckSerialInput". If the RI flag is set handle the SBUF data, clear the RI flag and quit that state.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top