Electrical – Serial communication with microcontrollers AT89S52

assemblycommunicationmicrocontrollerserial

I have a problem, I need to connect two microcontrollers and programming one of those as a transmitter and the other as a receiver, I've tried to do this but it's not working, and I don't know why.

The serial communication need to be in Mode 0. The transmitter microcontroller has a dip-switch where I enter the data (a number) and I need to be displaying in Led's connected in the receiver microcontroller.

Here is the code for both, I hope you can help me, thanks.

……………..Transmitter……………..

       MOV     SCON, #00H;    MODE 0 AS A TRANSMITTER
HERE:  MOV     A, P1;         MOVE THE DATA ON P1(DIP-SWITCH) TO ACCUMULATOR
       CLR     TI;            CLEAR THE BIT TI
       MOV     SBUF, A;       MOVE THE DATA TO SBUF
       JNB     TI,$ ;         PAUSE UNTIL THE TI BIT IS SET
       SJMP    HERE

………………Receiver……………….

        MOV    SCON, #10H;    MODE O AS A RECEIVER                          
WAIT:   JNB    RI, WAIT;      PAUSE UNTIL THE RI BIT IS SET
        CLR    RI
        MOV    A, SBUF;       MOVE THE DATA SEND TO ACC        
        MOV    P1, A;         MOVE ACC TO P1 (LED'S)
        SJMP   WAIT

Best Answer

On an MCS-51 microcontroller (MCU) like the AT89S52, UART mode 0 is a synchronous clocked serial port.

In Mode 0...

(a) When you write a byte to the serial port register to start a transmission, the AT89S52 (a) generates 8 clocks on its TXD output and (b) shifts out 8 data bits on the RXD output.

(b) When you read a byte from the serial port register (SFR) to start a receive, the AT89S52 (a) generates 8 clocks on its TXD output and (b) shifts in 8 data bits on the RXD output.

(c) TXD is always a serial clock output. RXD is a serial data in/out line.

(d) Transmission and reception only happen when software reads/writes the SFR. A typical UART serial receive port is always listening. This UART is Mode 0 is not.

So Mode 0 is ideal for controlling serial-to-parallel logic chips as I/O expanders.

And Mode 0 is useless for communication between two microcontrollers. Use Mode 2 instead.