HSerin problems on power up


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Unhappy HSerin problems on power up

    This is a problem I've encountered for years on several different chips and have always just kind of ignored it. I have a problem using the Hserin command on initial power up. Below is a stripped down version of my code. Basically I power up the chip and wait a little while then send a burst of data. that data is basically ignored, I send a second burst and it is processed as is every burst after. if I hit the reset button every burst is processed, but if I turn off the power and wait a few seconds before powering back up the problem comes back for the first burst of data. I've checked the overflow and framing error bits, and see no problem. There are only a few registers I can even think to look at, but nothing is popping out at me. it seems like it would have to be something obvious.

    Code:
    INCLUDE "DT_INTS-18.bas"       ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"    ; Include if using PBP interrupts
    
    Clear
    DEFINE 	OSC		40			' Set Xtal Frequency
    DEFINE HSER_CLROERR 1      'will automatically clear overflow errors
            
    stream		VAR	BYTE[80]	'the last stream in
    view_stream var byte[104]   'outsream converted to patterns                             
    
    a			VAR	BYTE            'loop counter variable
    b			VAR	BYTE
    x			VAR	BYTE            'loop counter variable
    B0			VAR BYTE
    B1			VAR BYTE
    B2			VAR BYTE
    B3			VAR BYTE
    B4			VAR BYTE
    B5          var byte
    
    pattern     var byte
    new_stream  var bit
    
    red_LED	  	VAR	PORTC.4   					'red led
    
    CSALL		CON %00000000			'Chip Select for all chips
    CSOFF		CON	%00001111			'chip select for no chips
    
    CSB0		VAR	PORTB.0
    CSB1		VAR	PORTB.1
    CSB2		VAR	PORTB.2
    CSB3		VAR	PORTB.3
    
    TRISA = %11101100
    TRISB = %11110000			'inputs for upper half switches outputs for lower CS
    TRISC = %11001111			'0-3 for switches, 4-5 for LEDs, 6-7 for serial data
    TRISD = 0
    TRISE = 0
    
    PORTB = CSOFF
    PORTE.0 = 1
    PORTE.1 = 1
    PORTE.2 = 0
    
    ADCON1 = %00001111
    
    ;****************Using Darrel Taylor Interrupts****************************
    ;----[High Priority Interrupts]--------------------------------------------
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler     RX_INT,     _GetData,   PBP,  no
        endm
        INT_CREATE               ;Creates the High Priority interrupt processor
    ENDASM
    
    red_LED    = 0 		    'turn on red LED
    
    Pause 1000
    
    top:
    
        TXSTA = $20   ' Enable transmit, BRGH = 0
        SPBRG = 34    ' 1200 Baud @ 0.0%
        SPBRGH = 8
        BAUDCON.3 = 1 ' Enable 16 bit baudrate generator	
        RCSTA = $90   ' Enable serial port & continuous receive
       	    
    	GoSub send_data
    
    countdown:
    'count from 9 to 0
    
    	For x = 9 TO 0 STEP - 1
    		For a = 0 TO 79
    			stream[a] = x + "0"
    		Next a
    		GoSub send_data
    		Pause 150
    	Next x
    	
    end_countdown:
    'check buttons
    	     
    @   INT_ENABLE  RX_INT     ; enable RX_INT interrupts
    
            RCSTA = $80          'clear CREN
            RCSTA = $90          'Enable receive
     
       
         
    mainloop:
    	
    	
        if new_stream = 1 then
            RCSTA.4 = 0
    	    RCSTA.4 = 1		'clear over run error
            new_stream = 0		
            GoSub send_data
        endif
     
        GoTo mainloop
     
    send_data:
    
        'this sub will send bit patterns via psp (non interrupt driven) to another chip
    	
        Return   
      
    	
    '---[USART RX - interrupt handler]-----------------------[High Priority]---
    GetData:
    
        hserin 1000,No232,[str stream\80\10]  
    
        red_LED = red_LED +1         'heartbeat
        new_stream = 1
        
    No232:
    @ INT_RETURN
    	
    End
    Thanks
    David

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

    Default

    If there's HSERIN/HSEROUT, you should use DEFINEs, unless you just need to write the USART registers.

    Code:
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler     RX_INT,     _GetData,   PBP,  no
    You want to reset flags, unless, your program will loop in the ISR forever.

    I haven't look the whole thing, but those are the really first thing that jump in my face.
    Steve

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

  3. #3
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Default

    Thanks, I'll give the reset flags a try latter. I can't use defines as the baud rate needs to be user configurable in the field.

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

    Default

    Yes you can do it, you define one at the top, then you change it later on the fly by writing SPBRG, RCSTA, TXSTA. Check the datasheet for the recommended sequence.
    Steve

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

  5. #5
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Default

    I finally had a chance to try out your suggestions by putting the defines at the beginning of the program and trying to reset the flag, but I have the same result of garbage in on the first transmission, then clear after that. Any other ideas would be appreciated.

    David

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

    Default

    It may happen if your transmitter use SEROUT/SEROUT2/DEBUG and the pin idle state is not set before sending the first data.

    Post your both code, receiver and transmitter end.
    Steve

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

  7. #7
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Default

    I use a VB program not a pic as the transmitter. I can leave the program running while the pic is powered down. I give the pic a few seconds stabilization time after power up before the next transmission is sent

    David

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

    Default

    Ok then, modify your VB program to send few garbage character, then a Synch String (let's say OK), and in your ISR use WAIT("OK") . See if this solve your problem.
    Steve

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

  9. #9
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86

    Default

    I'm sure this would work, I just figured I would see if anyone knew why I can't get it to work as expected. It isn't critical to the application, just one of those annoyances I figured most people weren't living with

Similar Threads

  1. Power problems
    By menta in forum General
    Replies: 50
    Last Post: - 30th July 2008, 22:55
  2. HSERIN and HSEROUT problems
    By amindzo in forum Serial
    Replies: 1
    Last Post: - 6th September 2006, 21:11
  3. HSERIN and HSEROUT problems
    By amindzo in forum General
    Replies: 2
    Last Post: - 31st August 2006, 06:51
  4. problems on power up of PIC
    By dmairspotter in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th June 2006, 14:11
  5. hserin problems
    By HELDERFERRAZ in forum Serial
    Replies: 0
    Last Post: - 10th February 2006, 23:41

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