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.

Rx Tx Microcontroller to Microcontroller 8051 communication

Status
Not open for further replies.

JeffreyPeter

New Member
Hi, How to link two microcontrollers together do I have to use max232 or by directly coupling their rx tx terminals ?
Thanks in advance.
 
Thanks now I'm able to transmit between two MC .... :)
On what basis the four modes of 8051 is chosen ? I have chosen mode 2 as most of them hav used it....
 
Last edited:
The modes refer to the low level protocols (8/9 bit etc). If you set them the same between two MCUs then you won't have a problem until you try and interface to something that doesn't support that particular mode like a PC natively.
 
MAX232 chips are only used for converting TTL to RS-232. If you're interfacing MCU's together (which use TTL levels), a MAX chip is not needed.

Due to the limited source current of the 8051, I would definitely place a pull up resistor on both the TxD and RxD lines for sharper edges somewhere in the range of 470R - 1K in value).

For serial mode, I recommend using mode 1 (8-bit asynchronous with variable baud rate). Mode 2 limits you to baud rates Fosc / 32 (PCON.SMOD1 = 1) or Fosc / 64 (PCON.SMOD1 = 0).

As to your missing byte issue -

1) Are you writing to SBUF, then waiting for the TI flag to go high before writing the next byte to SBUF?

2) Are you also clearing the TI flag in software after sending each byte?

3) On the receive end, are you making sure to clear the RI flag after receiving each byte?

These bits need to be cleared between each byte regardless of whether or not interrupts are being used. Failing to check the TI flag prior to writing the next byte to SBUF will result in transmit bytes being overwritten, which would be one cause of missing bytes. Here are some code examples for some serial receive routines for the 8051 -

Code:
SerTx:		jnb	TI,SerTx		;wait here for TI flag to go high
		clr	TI			;TI flag high, clear TI flag
		mov	SBUF,#<TXBYTE>		;write transmitting byte to SBUF
		ret				;done

SerRx:		jnb	RI,SerRx		;wait here for RI flag to go high
		clr	RI			;RI flag high, clear RI flag
		mov	A,SBUF			;received byte to accumulator
		ret				;done

Quite honestly, I think serial receive should be done using interrupts since the uC has no way of knowing when data will be sent to it. It can be off doing something else instead of having to tie it to waiting for bytes to be sent to it.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top