This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Automatic baud rate detection

Hy,
is there any possibilities to determine the actual baudrate with the C167?
We are just developing the second version of our download software from PC to uC which should be downward compatible with the first one. This first one works with a baud rate of 9,6kBaud, the new one eith 56k.

In the infineon bootstrap loader, there is an automatic baud rate detection. How do they do it?

Thanks
HARALD

Parents
  • The following code has worked for me. I believe the '166 does something similar:
    1) Monitor Rx pin for falling edge (start bit)
    2) Start timer (T6)
    3) Monitor Rx pin for rising edge (stop bit)
    4) Read timer
    5) Calculate baud rate

    	Fake_Bootstrap	PROC NEAR
    
    	MOV	CP, #0FA00h			;Init to reset values
    	MOV	STKUN, #0FFFFh			;Leave Ext bus controls alone (for now)
    	MOV	STKOV, #0000h
    	MOV	SP, #0FA40h
    	MOV	STKUN, #0FA40h
    	MOV	STKOV, #0FA0Ch
    	MOV	DPP0, #0000
    	MOV	DPP1, #0001
    	MOV	DPP2, #0002
    	MOV	DPP3, #0003
    
    	MOV	T6CON, #0000			;Init baud rate detector
    	MOV	T6, #0000
    	
    	BCLR	DP3.11				;Rx = Input
    BTSTRP1:					;while ( ! ~Rx_Port )	// Start bit detect
    	JB	P3.11, BTSTRP1			;  continue;
    	
    	BSET	T6R				;Baud timer = Running
    BTSTRP2:					;while ( ~Rx_Port )	// Stop bit detect
    	JNB	P3.11, BTSTRP2			;  continue;
    	
    	BCLR	T6R				;Baud timer = Stopped
    	MOV	R1, #36
    	MOV	MDL, T6				;BRG = ((T6/36)) / 2 - 1
     
    	DIVU	R1
    	MOV	R2, MDL
    	ROR	R2, #1
    	JMPR	cc_C, BTSTRP3			;  round result
    
    	SUB	R2, #0001
    BTSTRP3:
    	MOV	S0BG, R2			;Init serial port
    	BSET	P3.10
    	BSET	DP3.10
    	MOV	S0RIC, #0000
    	MOV	S0CON, #8011h			;Enable
    
    	MOV	S0TBUF, #00C5h			;Transmit Ack code for '167
    	MOV	R0, #0FA40h			;BYTE *p_Byte = bootstrap_Base;
    BTSTRP4:					;do {
    	JNB	S0RIR, BTSTRP4			;  while ( ! rx_Byte )
    						;    continue;
    	MOVB	[R0], S0RBUF			;    *p_Byte++ = rx_Byte;
    	BCLR	S0RIR
    	CMPI1	R0, #0FA60h
    	JMPR	cc_ULT, BTSTRP4			;} while ( p_Byte < bootstrap_Top );
    	
    	JMPA	cc_UC, 0FA40h			;goto( bootstrap_Base );
    
    	Fake_Bootstrap	ENDP
    
    Unfortunately, you can't read the BRG to determine the current baud rate. The only way I know to do that is to read it often in a tight loop and deduce the value by the highest value read.

    Best luck

Reply
  • The following code has worked for me. I believe the '166 does something similar:
    1) Monitor Rx pin for falling edge (start bit)
    2) Start timer (T6)
    3) Monitor Rx pin for rising edge (stop bit)
    4) Read timer
    5) Calculate baud rate

    	Fake_Bootstrap	PROC NEAR
    
    	MOV	CP, #0FA00h			;Init to reset values
    	MOV	STKUN, #0FFFFh			;Leave Ext bus controls alone (for now)
    	MOV	STKOV, #0000h
    	MOV	SP, #0FA40h
    	MOV	STKUN, #0FA40h
    	MOV	STKOV, #0FA0Ch
    	MOV	DPP0, #0000
    	MOV	DPP1, #0001
    	MOV	DPP2, #0002
    	MOV	DPP3, #0003
    
    	MOV	T6CON, #0000			;Init baud rate detector
    	MOV	T6, #0000
    	
    	BCLR	DP3.11				;Rx = Input
    BTSTRP1:					;while ( ! ~Rx_Port )	// Start bit detect
    	JB	P3.11, BTSTRP1			;  continue;
    	
    	BSET	T6R				;Baud timer = Running
    BTSTRP2:					;while ( ~Rx_Port )	// Stop bit detect
    	JNB	P3.11, BTSTRP2			;  continue;
    	
    	BCLR	T6R				;Baud timer = Stopped
    	MOV	R1, #36
    	MOV	MDL, T6				;BRG = ((T6/36)) / 2 - 1
     
    	DIVU	R1
    	MOV	R2, MDL
    	ROR	R2, #1
    	JMPR	cc_C, BTSTRP3			;  round result
    
    	SUB	R2, #0001
    BTSTRP3:
    	MOV	S0BG, R2			;Init serial port
    	BSET	P3.10
    	BSET	DP3.10
    	MOV	S0RIC, #0000
    	MOV	S0CON, #8011h			;Enable
    
    	MOV	S0TBUF, #00C5h			;Transmit Ack code for '167
    	MOV	R0, #0FA40h			;BYTE *p_Byte = bootstrap_Base;
    BTSTRP4:					;do {
    	JNB	S0RIR, BTSTRP4			;  while ( ! rx_Byte )
    						;    continue;
    	MOVB	[R0], S0RBUF			;    *p_Byte++ = rx_Byte;
    	BCLR	S0RIR
    	CMPI1	R0, #0FA60h
    	JMPR	cc_ULT, BTSTRP4			;} while ( p_Byte < bootstrap_Top );
    	
    	JMPA	cc_UC, 0FA40h			;goto( bootstrap_Base );
    
    	Fake_Bootstrap	ENDP
    
    Unfortunately, you can't read the BRG to determine the current baud rate. The only way I know to do that is to read it often in a tight loop and deduce the value by the highest value read.

    Best luck

Children