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

yet another serial question

why does my get stuck at
jnb TI, $

List:
; enable external clock 11.0592Mhz for
; standard baud rate generation
; external pin T2 stimulated from
; function generator.

		mov SCON, #01010000B
		mov  T2CON, #00110010B
		mov  TL2, #0EEh
		mov  TH2, #0FFh
		setb TR2
		clr  TI
		mov  SBUF, #'A'
		jnb  TI, $
Looking at SBUF, 'A' never seems to get moved there. What am I doing wrong?

Parents
  • ok I corrected my code. I have an 11.0592MHz clock on pin T2. I use this as my base for a baud rate of 19200. I step through the program but the letter A is never moved to SBUF. So then TI is never set, and it gets stuck in that circle. What is wrong?

    mov SCON, #01110000B
    mov  T2CON, #00110010B
    mov  TH2,  #0FFh
    mov  TL2,  #0EEh
    mov  RCAP2L, #0EEh
    mov  RCAP2H, #0FFh
    setb TR2
    clr  TI
    mov  SBUF, #'A'
    jnb  TI, $
    

Reply
  • ok I corrected my code. I have an 11.0592MHz clock on pin T2. I use this as my base for a baud rate of 19200. I step through the program but the letter A is never moved to SBUF. So then TI is never set, and it gets stuck in that circle. What is wrong?

    mov SCON, #01110000B
    mov  T2CON, #00110010B
    mov  TH2,  #0FFh
    mov  TL2,  #0EEh
    mov  RCAP2L, #0EEh
    mov  RCAP2H, #0FFh
    setb TR2
    clr  TI
    mov  SBUF, #'A'
    jnb  TI, $
    

Children
  • I have an 11.0592MHz clock on pin T2.

    Well, I can't be sure without knowing a lot more about your hardware design, but I don't think you can have an external clock source that runs that fast. Of course, this probably depends on the speed of the actual clock for the MCU and which MCU you are using.

    Typically, the T2 input pin is sampled at a particular clock state. It's probably getting sampled when your clock output is high. That's why nothing is getting transmitted.

    Do the T2L and T2H registers change while waiting in the jnb TI, $ loop?

    Jon

  • Yes I see T2 changing values. Now I used config.exe to configure everything. I am merely using a proto board with a Silicon Labs C8051F226 MCU. Here is the updated code. The same thing happens. I guess I'll try to install a real 11.059MHz crystal.



    
    
    
    $INCLUDE(C8051F200.INC)	; Register definition file.
    
          org 00h
          LJMP Config
    ; Place jump to reset handler and interrupt service routines here.
    
          org 0B3h      ; End of Interrupt Vector space.
    Config:
    
    	mov WDTCN, #007h	; Watchdog Timer Control Register
        mov WDTCN, #0DEh    ; Disable WDT
        mov WDTCN, #0ADh
    
    ; Configure the PRTnMX Registers
    
    	mov PRT0MX, #041h ; PRT0MX:	Initial Reset Value
    	mov PRT1MX, #000h ; PRT1MX: Initial Reset Value
    	mov PRT2MX, #080h ; PRT2MX: Initial Reset Value
    
    ; Select Pin I/0
    
    ; NOTE: Some peripheral I/O pins can function as either inputs or
    ; outputs, depending on the configuration of the peripheral. By default,
    ; the configuration utility will configure outputs as push-pull.
    
    ; Port configuration (1 = Push Pull Output)
    
    	mov PRT0CF, #001h ; Output configuration for P0
    	mov PRT1CF, #040h ; Output configuration for P1
    	mov PRT2CF, #000h ; Output configuration for P2
    	mov PRT3CF, #000h ; Output configuration for P3
    
    
    
    	mov P0MODE, #0FFh ; Input Configuration for P0
    	mov P1MODE, #0FFh ; Input Configuration for P1
    	mov P2MODE, #0FFh ; Input Configuration for P2
    	mov P3MODE, #0FFh ; Input Configuration for P3
    
    	mov CPT0CN, #000h	; Comparator 0 Control Register
    
    
    
    
    
    	mov CPT1CN, #000h	; Comparator 1 Control Register
    
    
    
    
    	;Comp1 marker
    
    ;----------------------------------------------------------------
    ; Oscillator Configuration
    ;----------------------------------------------------------------
    
    	mov OSCXCN, #010h	; External Oscillator Control Register
    
    	mov OSCICN, #087h	; Internal Oscillator Control Register
    
    
    ;----------------------------------------------------------------
    ; Reference Control Register Configuration
    ;----------------------------------------------------------------
    
    	mov REF0CN, #003h	; Reference Control Register
    
    ;----------------------------------------------------------------
    ; SPI Configuration
    ;----------------------------------------------------------------
    
    	mov SPI0CN, #000h	; SPI Control Register
    	mov SPI0CFG, #000h	; SPI Configuration Register
    	mov SPI0CKR, #000h	; SPI Clock Rate Register
    
    ;----------------------------------------------------------------
    ; UART Configuration
    ;----------------------------------------------------------------
    
    	mov SCON, #050h		; Serial Port Control Register
        anl SCON, #0FCh    ; clear interrupt pending flags
    
    
    
    
    	mov PCON, #000h		; Power Control Register
    
    ;----------------------------------------------------------------
    ; ADC Configuration
    ;----------------------------------------------------------------
    
    	mov AMX0SL, #000h	; AMUX Channel Select Register
    	mov ADC0CF, #000h	; ADC Configuration Register
    	mov ADC0CN, #000h	; ADC Control Register
    
    	mov ADC0LTH, #000h	; ADC Less-Than High Byte Register
    	mov ADC0GTH, #0FFh	; ADC Greater-Than High Byte Register
    
    ;----------------------------------------------------------------
    ; Timer Configuration
    ;----------------------------------------------------------------
    
    	mov CKCON, #000h	; Clock Control Register
    	mov TH0, #000h		; Timer 0 High Byte
    	mov TL0, #000h		; Timer 0 Low Byte
    	mov TH1, #000h		; Timer 1 High Byte
    	mov TL1, #000h		; Timer 1 Low Byte
    	mov TMOD, #000h		; Timer Mode Register
    	mov TCON, #040h		; Timer Control Register
    
    	mov RCAP2H, #0FFh	; Timer 2 Capture Register High Byte
    	mov RCAP2L, #0EEh	; Timer 2 Capture Register Low Byte
    	mov TH2, #0FFh		; Timer 2 High Byte
    	mov TL2, #0EEh		; Timer 2 Low Byte
    	mov T2CON, #036h	; Timer 2 Control Register
    
    ;---------------------------------------------------------------
    ; Reset Source Configuration
    ;
    ; Bit 7  | Bit 6  | Bit 5  | Bit 4  | Bit 3 | Bit 2 | Bit 1 | Bit 0
    ;------------------------------------------------------------------
    ;        |   R    |  R/W   |  R/W   |   R   |   R   |  R/W  |  R
    ;------------------------------------------------------------------
    ;Reserved|NOT     | Comp.0 | S/W    | WDT   | Miss. | POR   | HW
    ;        |USED    | Reset/ | Reset  | Reset | Clock | Force | Pin
    ;        |        | Enable | Force  | Flag  | Detect| &     | Reset
    ;        |        | Flag   | &      |       | Flag  | Flag  | Flag
    ;        |        |        | Flag   |       |       |
    ;------------------------------------------------------------------
    ;
    ; NOTE! : Comparator 0 must be enabled before it is enabled as a
    ; reset source.
    ;------------------------------------------------------------------
    
    	mov RSTSRC, #000h	; Reset Source Register
    
    
    ;----------------------------------------------------------------
    ; Interrupt Configuration
    ;----------------------------------------------------------------
    
    	mov IE, #010h		;Interrupt Enable
    	mov IP, #000h		;Interrupt Priority
    	mov EIE1, #000h		;Extended Interrupt Enable 1
    	mov EIE2, #000h		;Extended Interrupt Enable 2
    	mov EIP1, #000h		;Extended Interrupt Priority 1
    	mov EIP2, #000h		;Extended Interrupt Priority 2
    
    
    
    ; other initialization code here...
    
    
    
    ;-----------------------------------------------------------------
    ; MAIN PROGRAM CODE
    ;-----------------------------------------------------------------
    
    Main:
    
    	; main code routines here...
    	setb  TR2
    	clr	TI
    	mov	SBUF, #'A'
    	jnb	TI, $
    
    
    END
    

  • Yes I see T2 changing values
    what does that prove? If you are running T2IN too fast, it will still pick up sometimes.

    1) Why are you trying to run the UART with an external clock?
    2) what happens if you try to communicate using the CPU clock?

    Erik

  • Well I changed my code to use the internal clock @ 16MHz. I put a scope on P0.0 and saw the character was being transmitted repetitivley, but TI is never set. Why is this?

    $INCLUDE(C8051F200.INC)	; Register definition file.
    
          org 00h
          LJMP Config
    ; Place jump to reset handler and interrupt service routines here.
    
          org 0B3h      ; End of Interrupt Vector space.
    Config:
    
    	mov WDTCN, #007h	; Watchdog Timer Control Register
        mov WDTCN, #0DEh    ; Disable WDT
        mov WDTCN, #0ADh
    
    ; Configure the PRTnMX Registers
    
    	mov PRT0MX, #001h ; PRT0MX:	Initial Reset Value
    	mov PRT1MX, #000h ; PRT1MX: Initial Reset Value
    	mov PRT2MX, #080h ; PRT2MX: Initial Reset Value
    
    ; Select Pin I/0
    
    ; NOTE: Some peripheral I/O pins can function as either inputs or
    ; outputs, depending on the configuration of the peripheral. By default,
    ; the configuration utility will configure outputs as push-pull.
    
    ; Port configuration (1 = Push Pull Output)
    
    	mov PRT0CF, #001h ; Output configuration for P0
    	mov PRT1CF, #000h ; Output configuration for P1
    	mov PRT2CF, #000h ; Output configuration for P2
    	mov PRT3CF, #000h ; Output configuration for P3
    
    
    
    	mov P0MODE, #0FFh ; Input Configuration for P0
    	mov P1MODE, #0FFh ; Input Configuration for P1
    	mov P2MODE, #0FFh ; Input Configuration for P2
    	mov P3MODE, #0FFh ; Input Configuration for P3
    
    	mov CPT0CN, #000h	; Comparator 0 Control Register
    
    	mov CPT1CN, #000h	; Comparator 1 Control Register
    
    	;Comp1 marker
    
    ;----------------------------------------------------------------
    ; Oscillator Configuration
    ;----------------------------------------------------------------
    
    	mov OSCXCN, #010h	; External Oscillator Control Register
    
    	mov OSCICN, #007h	; Internal Oscillator Control Register
    
    
    ;----------------------------------------------------------------
    ; Reference Control Register Configuration
    ;----------------------------------------------------------------
    
    	mov REF0CN, #003h	; Reference Control Register
    
    ;----------------------------------------------------------------
    ; SPI Configuration
    ;----------------------------------------------------------------
    
    	mov SPI0CN, #000h	; SPI Control Register
    	mov SPI0CFG, #000h	; SPI Configuration Register
    	mov SPI0CKR, #000h	; SPI Clock Rate Register
    
    ;----------------------------------------------------------------
    ; UART Configuration
    ;----------------------------------------------------------------
    
    	mov SCON, #050h		; Serial Port Control Register
    
    
    
    
    
    
    
    
    	mov PCON, #000h		; Power Control Register
    
    ;----------------------------------------------------------------
    ; ADC Configuration
    ;----------------------------------------------------------------
    
    	mov AMX0SL, #000h	; AMUX Channel Select Register
    	mov ADC0CF, #000h	; ADC Configuration Register
    	mov ADC0CN, #000h	; ADC Control Register
    
    	mov ADC0LTH, #000h	; ADC Less-Than High Byte Register
    	mov ADC0GTH, #0FFh	; ADC Greater-Than High Byte Register
    
    ;----------------------------------------------------------------
    ; Timer Configuration
    ;----------------------------------------------------------------
    
    	mov CKCON, #020h	; Clock Control Register
    	mov TH0, #000h		; Timer 0 High Byte
    	mov TL0, #000h		; Timer 0 Low Byte
    	mov TH1, #000h		; Timer 1 High Byte
    	mov TL1, #000h		; Timer 1 Low Byte
    	mov TMOD, #000h		; Timer Mode Register
    	mov TCON, #040h		; Timer Control Register
    
    	mov RCAP2H, #0FFh	; Timer 2 Capture Register High Byte
    	mov RCAP2L, #0EFh	; Timer 2 Capture Register Low Byte
    	mov TH2, #0FFh		; Timer 2 High Byte
    	mov TL2, #0EFh		; Timer 2 Low Byte
    	mov T2CON, #034h	; Timer 2 Control Register
    
    	mov RSTSRC, #000h	; Reset Source Register
    
    
    ;----------------------------------------------------------------
    ; Interrupt Configuration
    ;----------------------------------------------------------------
    
    	mov IE, #000h		;Interrupt Enable
    	mov IP, #000h		;Interrupt Priority
    	mov EIE1, #000h		;Extended Interrupt Enable 1
    	mov EIE2, #000h		;Extended Interrupt Enable 2
    	mov EIP1, #000h		;Extended Interrupt Priority 1
    	mov EIP2, #000h		;Extended Interrupt Priority 2
    
    
    
    ; other initialization code here...
    
    
    
    ;-----------------------------------------------------------------
    ; MAIN PROGRAM CODE
    ;-----------------------------------------------------------------
    
    Main:
    
    	; main code routines here...
    	setb	TR2
    	clr	TI
    	mov	SBUF, #'A'
    	jnb	TI, $
    
    END
    

  • jnb TI, $

    END

    Once TI get set, your program goes to uncharted territory.

    Erik

  • jnb TI, $

    END

    Once TI get set, your program goes to uncharted territory.

    Erik

  • Once TI get set, your program still goes to uncharted territory.

    Erik