UART questions


Closed Thread
Results 1 to 9 of 9

Thread: UART questions

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    Hello Christopher,

    I'd be very interested to know which UART chip you are using.

    A different approach could be to utilize the UART for the serial communications and use the software SPI commands (SHIFTIN and SHIFTOUT). I would be lost without the PIC's two-byte buffer and interrupt...8v)

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  2. #2
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    It's the RN-171. I'm using this code and I can see the data coming out of the RN-171 and into the 4550 but the 4550 isn't doing anything. Am I at least in the ballpark?

    Code:
    DEFINE OSC 48
    
    @ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    @ __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_OFF_2L & _BORV_3_2L & _VREGEN_ON_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_32768_2H 
    @ __CONFIG _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    @ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_ON_4L & _XINST_OFF_4L
    
     CMCON = 7 
     PORTD.1=0 'diagnostic LED
     PORTD.0=0 'diagnostic LED
    
    
    DEFINE HSER_BAUD 9600
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_CLROERR 1
    
    in1 var byte
    
    HIGH PORTD.0
    HIGH PORTD.1
    
    
    mainloop:
    
    IF RCSTA.1 = 1 THEN    'if USART overrun error flag OERR is set...
       RCSTA.4 = 0          'clear and then set CREN bit to recover
       RCSTA.4 = 1
       in1 = RCREG          'read data to clear out RCREG
       IF PIR1.5 = 1 THEN in1 = RCREG   'clear possible 2nd byte in RCREG
    ENDIF
    
    
    WHILE PIR1.5 = 0   'stay here until USART receives data
    
      
    WEND
    LOW portD.0       'data in RCREG; turn on diagnostic LED   <----my code won't go past this point even though I can see data being sent with an oscope.
    
    goto mainloop

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    Nevermind. Apparently I either need glasses or sleep.

  4. #4
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    Hello Christopher,

    I see a couple of things. To make the USART work on the '4550 the manual says that both the RX and TX pins need to be configured as inputs, so add
    Code:
    TRISC.7 = 1
    TRISC.6 = 1
    If you're having trouble, try remming out the first six lines under mainloop, from the if to the endif, just to confirm that the port is working asynchronously.

    For synchronous operations, TRISC.7 needs to be set to 0.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    I have everything working for the most part. It's a little buggy but hopefully I can sort that out over time. I have a question about sorting the data. The data comes to me in this form:

    *DATA* 84 324 2343 211 2345 234 DONE
    ID: 24
    I want to take the six numbers on the first line and assign variables to them and then do stuff with them. How can I do that? Also, if I was to push out 100 variables in one shot, would that work or is it considered normal practice?

  6. #6
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    One other question. When I'm using SPI, my settings are as follows:
    Code:
    SSPSTAT = %01100100      
     SSPCON1 = %00100001 
     BAUDCON = %00001111
    When I switch to UART, I do the following:
    Code:
    SELECT case TIMER
            CASE 255
                SSPSTAT = 0     
                SSPCON1 = 0
                BAUDCON = 0
                PAUSE 1000
                for x=1 to 10
                HSEROUT ["FAN: ",DEC FAN]
                pause 10
                next x
                SSPSTAT = %01100100      
                SSPCON1 = %00100001 
                BAUDCON = %00001111
                pause 100
        END SELECT
    Using one or the other (initial programming), it works correctly. When I use the code above, the data goes out but it's garbled. Instead of the fan information, I get stuff like "* "

    Any ideas?

Similar Threads

  1. PK2 UART tool
    By cncmachineguy in forum Serial
    Replies: 13
    Last Post: - 24th May 2011, 08:00
  2. using Quad UART
    By harryweb in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 30th April 2011, 00:13
  3. UART-not consistant
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st August 2008, 03:14
  4. How to set up UART??
    By jkbpower in forum Serial
    Replies: 8
    Last Post: - 25th April 2007, 07:09
  5. External UART IC
    By Terry in forum General
    Replies: 4
    Last Post: - 22nd December 2005, 18:01

Members who have read this thread : 0

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