Sci reception

Discussion in 'Embedded Systems and Microcontrollers' started by geoffers, Jul 19, 2011.

  1. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Hi all,
    I wonder if anyone can point me in the right direction, I'm trying to read to scio pin of a tms3705, the protocal is one start bit high, one stop bit low and no parity. Im using a pic 16f818 with 4mhz internal osc, tmr1 with a 1/2 prescale. Firstly does anyone know if the internal osc is accurate enough for what Im trying to do, has anyone used the tms3705?
    The transponder I'm trying to read is iso 11784/11785 compliant and should send a start byte of 01111110 followed by the data bytes.
    Here is my bit of code, any comments/help would be welcome;


    ISR BCF PORTB,3 ;TURN OFF U2270B
    BCF PORTB,2 ;wake up tms3705
    MOVLW 37H ;LOAD FSR
    MOVWF FSR
    CALL TXCT ;4MS DELAY
    BSF PORTB,2
    CLRF STFLAG

    CLRF D1

    CLRF TMR0
    RUF CLRF DATA1
    MOVLW .25
    SUBWF TMR0,W
    BTFSC STATUS,C
    GOTO BACK
    BTFSS PORTB,1 ;WAIT FOR START BIT
    GOTO RUF

    CLRF TMR1L
    CLRF TMR1H
    RUG MOVLW .13 ;32 PUTS CHECK IN MIDDLE OF BIT
    SUBWF TMR1L,W
    BTFSS STATUS,C
    GOTO RUG
    CLRF TMR1L ;START TIMER AGAIN
    BTFSS PORTB,1 ;SHOULD STILL BE SET
    GOTO BACK ;IF NOT BE ERROR


    RUH MOVLW .28 ;BIT LENGH 64uS
    SUBWF TMR1L,W
    BTFSS STATUS,C
    GOTO RUH
    CLRF TMR1L
    BCF STATUS,C
    BTFSS PORTB,1 ;IS BIT SET OR CLEAR?
    BSF DATA1,7 ;SET MSB
    RRF DATA1 ;ROTATE DATA
    INCF D1

    MOVLW .8
    SUBWF D1,W ;HAVE 8 BITS BEEN RECIVED?
    BTFSS STATUS,2
    GOTO RUH
    BTFSS STFLAG,0 ;HAVE STARTBITS BEEN RECIVED
    GOTO CHECKS

    MOVF DATA1,W
    MOVWF INDF
    INCF FSR
    CLRF DATA1
    CLRF D1
    MOVF FSR,W
    SUBLW 41H ;HAS ALL BEEN READ?
    BTFSS STATUS,2
    GOTO RUF ;NO CYCLE AGAIN

    CALL HOME
    CALL DFILE
    CALL DISPLAY
    CALL DISP

    BACK BSF PORTB,3

    BCF INTCON,2
    BCF INTCON,1

    RETFIE
    CHECKS MOVLW B'01111110'
    SUBWF DATA1,W
    BTFSS STATUS,2
    GOTO BACK
    BSF STFLAG,0
    GOTO RUF
     
  2. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Well I got it working! Had alot of things wrong, which I've now sorted out. The interal osc seems to work at room temp, but I think its wise to use a crystall.
    I know its frustrating to find a unresolved post so here is my code, any comments welcome;

    ISR BCF PORTB,3 ;TURN OFF U2270B
    BCF PORTB,2 ;txct line on tms3750
    BANKSEL T1CON
    MOVLW B'00000001'
    MOVWF T1CON ;CHANGE TMR1 PRESCALE
    BANKSEL 0
    MOVLW 37H ;LOAD FSR
    MOVWF FSR0L

    CALL TXCT ;4MS DELAY
    BSF PORTB,2
    CLRF STFLAG

    CLRF D1

    BOB CLRF TMR0L
    RUF CLRF DATA1
    MOVF TMR0L,W
    SUBLW .50
    BTFSC STATUS,2
    GOTO BACK
    BTFSS PORTB,1 ;WAIT FOR START BIT
    GOTO RUF

    CLRF TMR1L
    CLRF TMR1H

    RUG MOVLW .21 ;32 PUTS CHECK IN MIDDLE OF BIT
    NOP
    NOP
    SUBWF TMR1L,W
    BTFSS STATUS,C
    GOTO RUG
    CLRF TMR1L ;START TIMER AGAIN
    BTFSS PORTB,1
    GOTO BACK ;IF NOT BE ERROR


    RUH MOVLW .57 ;BIT LENGH 64uS
    NOP
    SUBWF TMR1L,W
    BTFSS STATUS,C
    GOTO RUH
    CLRF TMR1L
    BCF STATUS,C
    RRCF DATA1 ;ROTATE DATA
    BTFSS PORTB,1 ;IS BIT SET OR CLEAR?
    BSF DATA1,7 ;SET MSB

    INCF D1


    MOVLW .8
    SUBWF D1,W ;HAVE 8 BITS BEEN RECIVED?
    BTFSS STATUS,2
    GOTO RUH
    CLRF D1
    BTFSS STFLAG,0 ;HAVE STARTBITS BEEN RECIVED
    GOTO CHECKS



    MOVF DATA1,W
    MOVWF INDF0
    INCF FSR0L
    CLRF DATA1
    MOVF FSR0L,W
    SUBLW 47H ;HAS ALL BEEN READ?
    BTFSS STATUS,2
    GOTO BOC ;NO CYCLE AGAIN
    BSF DON,0 ;TAG HAS BEEN READ SO SET DONE BIT & RETURN FROM INTERRUPT

    BACK BSF PORTB,3
    BANKSEL T1CON
    MOVLW B'00010001'
    MOVWF T1CON
    BANKSEL 0
    CLRF TMR0L

    BCF INTCON,2
    BCF INTCON,1

    RETFIE
    CHECKS MOVLW B'01111110'
    SUBWF DATA1,W
    BTFSS STATUS,2
    GOTO BOC
    BSF STFLAG,0
    BOC MOVLW .60 ;CHECK FOR STOP BIT LOW
    SUBWF TMR1L,W
    BTFSS STATUS,C
    GOTO BOC
    BTFSC PORTB,1
    GOTO BACK ;IF HIGH BE ERROR
    GOTO BOB ;RETURN & WAIT FOR START BIT

    ;*******************************************************************************
    TXCT CLRF TMR0L ;PRESCALER IS SET TO /256 BEFORE
    BUCK MOVF TMR0L,W ;INTERUPT IS ENABLED, SO 15 GIVE
    SUBLW .200 ;4MS DELAY (ISH)
    BTFSS STATUS,2
    GOTO BUCK
    RETLW 0
     
  3. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    Yes, you have to use a XTAL for reliable operation.
     
Loading...