UART questions


Closed Thread
Results 1 to 9 of 9

Thread: UART questions

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

    Default UART questions

    I'm using an 18F4550. I have a SPI IC and a UART IC. Most of you who have used a 4550 know that the RX USART pin is shared with the SDO pin (Pin 1). I'm using the MSSP for the SPI communication.

    The best solution that I've found on here is to reconfigure the pin for the function that you need. I'd like to try it to see how much it will slow down the transfer of data but I have some questions.

    1. If I'm running the SPI and want to switch to the UART, would I do something like:
    SSPEN=0
    SPEN=1

    And then do the reverse when I want to use the SPI again?
    2. Can I use other pins for the UART communication? It's not critical data and I only need to check the UART once every 3-4 seconds.

    3. Are there any other options available? I know switching PIC's seems like an easy solution, and in the end I may switch to a 18F46J50, but if I can make this work I'd prefer to stick with it.

    4. The external UART IC runs at 3.3V. I have the 4550 running at 5V. If I want to interface the UART pins, do I put a current limiting resistor in series?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    Hi Christopher,
    1) In theory yes, I believe that's what you need to do, plus swtiching between input and output. In practice I'm not sure it's going to work since the pin, in "SPI mode", is a driven output which then connects to whatever drives the pin when it's in "UART mode". Ie there's a potential short circuit happening there. Perhaps putting a resistor between the pin and the device connected to it "in UART mode" is enough.

    2) No. The on the 4550 the UART pins are RC6 and RC7 and can't be moved. If you can use SEROUT/SERIN you can use (almost) any pin you like.

    3) You already know my view on this ;-)

    4) Hard to say without looking at the datasheet for the UART chip. Some have 5V tolerant I/O some don't.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: UART questions

    Thanks for the reply Henrik.

    In reference to #2, that's what I meant. I know SERIN/OUT is slower, but it won't matter for my application. Is it as simple as just running the UART I/O to the SERIN/OUT and then when I want to send something, I just put "SEROUT pin, mode, blah, blah, blah....." Also, can I or should I use SEROUT2? If I understand it correctly, the only difference is flow control?

    In reference to #4, the external UART IC is only 3.3V. It states that it's an 8mA drive, but nothing on the input. When I'm using SERIN, the 4550 should be floating and only accepting the UART data, so 3.3V should be the max and I can connect the input directly. When I'm using SEROUT, the 4550 is driving the data at 5V and I would need a resistor, perhaps 1k?. I've never done this before, is my understanding correct?

  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'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.

  5. #5
    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

  6. #6
    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.

  7. #7
    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.

  8. #8
    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?

  9. #9
    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