Problem with UART... here is a real challenge


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2007
    Posts
    4

    Question Problem with UART... here is a real challenge

    Hi I am having a really unusual problem, I can recive a string from hiper therminal, and a friend with his microcontroller sends me the same code for deparcing and it continuos working, then a program that runs in windows sends me the same code but it dosen`t work. PIC is working ok with other devices , but when pc sends the same code that hiper therminal sends, pic dosen`t. can the problem be that pc sends the string faster between characters...or a don`t know you tell me what can it be.
    thanks.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    This will help if we see some code and Schematic. In general, the baudrate setting should be the problem... if your target PIC have the usual Bootloader circuit and the VB application don't care about the DTR line, this may be the cause. And then there's also the data format. Text representation or what?

    Unless life should be good.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Any bets that Hyperterminal has a character pacing setting in it that's being used and the VB program doesn't?
    Or maybe an internal oscillator is being used on the PIC?
    Who knows? Can't really tell now can we......again....

  4. #4
    Join Date
    Feb 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Smile thanks

    Tomorrow I will publiesh the code don`t have it with me..

  5. #5
    Join Date
    Feb 2007
    Posts
    4


    Did you find this post helpful? Yes | No

    Default MY code that dosen`t fuction

    Code:
    ' Defines for USART
    
    INCLUDE "bs2defs.bas"			
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h       '24h
    DEFINE HSER_BAUD 9600		'9600 baud
    DEFINE HSER_SPBRG 25        'No estaba 
    
    ' Registros timer
    RCIF	VAR	PIR1.5			' Alias RCIF (USART Receive Interrupt Flag)
    OERR	VAR	RCSTA.1			' Alias OERR (USART Overrun Error Flag)
    CREN	VAR	RCSTA.4			' Alias CREN (USART Continuous Receive Enable)
    T0CS	VAR OPTION_REG.5
    PSA  	VAR OPTION_REG.3
    PS0  	VAR OPTION_REG.0
    PS1  	VAR OPTION_REG.1
    PS2  	VAR OPTION_REG.2
    
    ' Declaracion de variables
    valor1      VAR WORD        ' tiempos Timer
    valor2      VAR WORD
    valor3      VAR WORD
    estado      VAR BYTE        ' variable para disparar timer
    char0       VAR BYTE        ' b0 dato a decodificar
    char1       VAR BYTE        ' b1 dato a decodificar
    char2       VAR BYTE        ' b2 dato a decodificar
    char3       VAR BYTE
    i           VAR BYTE        ' Contador
    string      VAR BYTE[20]    ' Paquete Recepcion    
    TMR0Count   VAR WORD
    c           VAR BYTE
    
    
    
    
    
    
    ' Configuracion de puertos
    TRISB= %00100111
    ' Configuracion inerrupciones
    INTCON = %11111000				' Registro para habilitar las interrupciones
    ON INTERRUPT GoTo serialin      ' AL realizarse interrupcion va ahi
    PIE1.5 = 1                      ' Habilitar interrupcion en USART
    	
    ' Defines
    RBO       VAR PORTB.0
    RX        VAR PORTB.1
    TX        VAR PORTB.2
    interruption  VAR PORTB.3
    led       VAR PORTB.4
    RB5       VAR PORTB.5
    salida1   VAR PORTB.6
    salida2   VAR PORTB.7
    
    ' Inicio del programa
    
    i=0
    c=0
    char0=0
    char1=0
    char2=0
    string[0]=0
    string[1]=0
    string[2]=0
    string[3]=0
    string[4]=0
    string[5]=0
    string[6]=0
    string[7]=0
    string[8]=0
    string[9]=0
    string[10]=0
    string[11]=0
    PORTB=0
    Pause 1
    
    HSerout ["Port has Started Ok!!"]
    High interruption
    'Deparcing
    
    INICIO:
        
        IF i=255 Then
        High salida2
       
        For i = 0 TO 20
        IF string[i]=$52 Then
        char0=string[i]
        i=i+1
        char1=string[i]
        i=i+1
        char2=string[i]
        i=19
        EndIF
        Next i
        EndIF
    IF char0="R" AND char1="1" AND char2="1"   Then         'R11
         	High salida1
            char0=0
            char1=0
            char2=0
            string[0]=0
            string[1]=0
            string[2]=0
            string[3]=0
            string[4]=0
            string[5]=0
            string[6]=0
            string[7]=0
            string[8]=0
            string[9]=0
            string[10]=0
            string[11]=0
            Pause 2000
            i=0
            Low salida1
            Low salida2
            
        EndIF
    
    GoTo INICIO
    
    
    
    
    
    
    
    
         
    Disable	interrupt					' Don't check for interrupts in this section
    
    serialin:		
    		
    		HSerin  [HEX2 b0]
    		 
            
            IF b0 = $7C Then 
            GoTo jump
            EndIF
            
            string[c]=b0
            c=c+1
            RCIF=0        
            Resume
    
    jump:   RCIF=0        
            c=0
            i=255
            Resume
            
    Enable interrupt
    
    End

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    HSerIn doesn't need to be used in an interrupt.
    If you've got going what I think you've got going...
    When your interrupt trips, you've got a character in the receive register. When you get into your interrupt routine, the HSerIn line will wait for the next character, not get the one that's already in the receive register.

    And besides that, you're ON INTERRUPT doesn't get enabled until the end of the program (3rd line from the end of your code), which it will never reach.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    errr... HEX2 wait for two character, RCIF=0 is is a read only. This bit is cleared when you read RCREG untill the USART buffer is empty (HSERIN should take care of it)

    if this program work with Hyperterminal and not on another software, we need to know what's the other software. Could be handy to have a LCD attach to your PIC and display the incoming data.

    And besides that, you're ON INTERRUPT doesn't get enabled until the end of the program (3rd line from the end of your code), which it will never reach.
    mmm... really sure of it???
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    mmm... really sure of it???
    I guess I really never paid attention, but section 9 says they aren't enabled by default...I suppose I could be wrong...

Similar Threads

  1. Problem with ASM IRQ using FSR0 on PIC18F252
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th March 2008, 21:48
  2. Problem using Microloader and Uart Comm at the same time
    By guanerrr in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd August 2007, 10:31
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 09:12
  4. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 23:59
  5. weird 12F629/675 problem
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th October 2004, 02:08

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts