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.

Strange glitch

Status
Not open for further replies.

labrat31

New Member
I have almost finished writing a program to receive and transmit strings of data. It reads a 4 byte data string from UART and sends it to RAM then transmits the data from RAM in a 4 byte string back over UART. It also has a timer so it will not lock up or loose sync if it reads 3 or 5 bytes. It works ok say 90% of the time other then this glitch, when I send data to the micro from a computer continuously with a delay in between strings say 100 mS sometimes it will miss a string and the ports flick on and off quickly even though I have no reference to ports in the program. Anyone know what this could be??
 
Last edited:
hi lab,
Is the 'sync' Timer on interrupts.??

Post your program
 
Code:
;
;#####  Receive and transmit       #####	
;#####  strings of data over UART   #####


 
 
	serTx	DATA	    30H
	serRx	DATA	    31H

	byte1	DATA	    32h
	byte2	DATA	    33h
	byte3	DATA	    34h
	byte4	DATA	    35h


 			ORG 00h


;#####      Main program      #####



		ACALL SetUART	;Set up UART

		;set up pointers to load UART data string to RAM

loop:		MOV R0,#serRx	;source pointer			  	
		MOV R1,#byte1 	;destination pointer	
		MOV R3,#4 	;counte	
		ACALL Rx_ram	;input UART string to ram  


		;set up pointers to load RAM data to UART and output string 

		MOV R0,#byte1	;source pointer			  	
		MOV R1,#serTx	;destination pointer	
		MOV R3,#4 	;counte
		ACALL ram_Tx	;output string of data from ram over UART

		ACALL loop	   ;keep doing it in a loop

;####################################
;#####      	  RAM Loops        ######
;####################################



		
Rx_ram:		ACALL Rx		;Get data from UART 
		MOV A,@R0 		;get a byte from source
		MOV @R1,A 		;copy it to destination
		INC R1 			;increment destination pointer
		DJNZ R3,Rx_ram 		;keep doing till all bytes are received
		;setb P0.4		;turn off p0.4 LED after all bytes are sent
		RET

ram_Tx:		MOV A,@R0 		;get a byte from source
		MOV @R1,A 		;copy it to destination
		INC R0 			;increment source pointer
		ACALL Tx			;transmit data byte   
		DJNZ R3,ram_Tx 	;keep doing till all bytes are sent 
		RET




 
;####################################
;#####   UART Initialization   ######
;#####		&	   ######
;#####	 transmit and receive  ######
;#################################### 

 
setUART:		MOV	PCON,#0x80	;x2 serial baud rate
		MOV	TH1,#0xF4 	;reload value 250 for 9600bps w/11.059MHz xtal
		MOV	TL1,#0xF4 
		MOV TMOD,#0x20 	;timer 1,mode 2(auto reload)
		MOV	TCON,#0x40	;start timer 1
		MOV	SCON,#0x50 	;8-bit, 1 stop, REN enabled
		RET	
 
TstOK:		MOV serRx,SBUF				
		CLR RI			 ;clear RI flag
		RET

		;timer to keep sync

Rx:		MOV R4,#20	 	;delay time multiplier     
AGAIN:		MOV R5,#20	 	;delay time   
HERE:		JB RI,TstOK		;get byte from SBUF if IR is set 
		NOP
		NOP
		DJNZ R5,HERE
		DJNZ R4,AGAIN
		ACALL st_flt	 ;exit if there is no receive in time period  

		;transmit  UART
Tx:		MOV SBUF,serTx 	;saving incoming byte in A
TxH:		JNB TI,TxH 		;wait for the last bit		
		CLR TI 			;get ready to receive next byte
		RET				;Return to main program

st_flt:		NOP
		;CLR P0.4
		ACALL loop		;start loop again   



		END

its still a little messy and missing some comments but this is what I have so far

if u mean dose it use the Receive interrupt flag then yes. Im still self learning so I may be missing something

copying my code into “wrap code” messed up my formatting big time sorry but the .asm should look ok
 
Last edited:
Should my sync timer be on interrupts? Trying to get it working now but the interrupt only works once

ORG 23H
LJMP ser_IE
ser_IE: MOV serRx,SBUF
CLR RI
AJMP Rx_bite
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top