PIC18F2450 Rs-232


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Mar 2008
    Posts
    43

    Default PIC18F2450 Rs-232

    I have a Olimex PIC-28 board. I have a PIC18F2450 and a ST232 installed.

    I have pin 17 on the PIC18F connected to pin 12 on the ST232
    I have pin 18 on the PIC18F connected to pin 10 on the ST232

    I am using this command in PBP:
    SEROUT PORTC.6,T9600,["This is a test"]

    I have a scope attached and the PIC pins 17 and 18 are always high, they never change.

    Is my wiring wrong? or do I have to set some configuration bits to make this work?

    Thanks,
    Bob

  2. #2
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    BTW,
    the SEROUT PORTC.6,T9600,["This is a test"] command is in a loop that updates every 2 seconds.

  3. #3
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    More Information:

    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    TRISB = %00000000 ' Set PortB to outputs
    TRISA = %01111111
    SPBRG = 25 ' Set baud rate to 2400
    RCSTA = %10010000 ' Enable serial port and continuous receive
    TXSTA = %00100000 ' Enable transmit and asynchronous mode
    INTCON2.7 = 0

  4. #4
    Join Date
    Jan 2011
    Location
    Skopje,Macedonia
    Posts
    71


    Did you find this post helpful? Yes | No

    Default

    If you want to control ports.Frist of all change them to "0",with this command PORTB=$00

  5. #5
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    TRISB = %00000000 is the same thing and that is already in my code.
    I don't think Portb has anything to do with my USART operations.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    TRISB = XXX
    PORTB = XXX
    are not the same thing. One sets direction and the other is on/off.

    What happens if you pull the 232 chip?
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Doing further research, it looks like I have to use HSEROUT withe the USART pins on the PIC18F2450. I have tested with HSEROUT and I still don't get any serial out.

    Can I use other Pins and use SEROUT? if so what do I need to specify in my code? I have a 20mhz clock and need 9600,n,8,1

    I disconnected the 232 chip and the result is the same.

  8. #8
    Join Date
    Jan 2011
    Location
    Skopje,Macedonia
    Posts
    71


    Did you find this post helpful? Yes | No

    Default

    Why do you put 9600bauds put 2400
    please post the code!!

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I see what you did now.
    Remove the hardware serial stuff.
    SPBRG = 25 ' Set baud rate to 2400 RCSTA = %10010000 ' Enable serial port and continuous receive TXSTA = %00100000

    Then you can use SEROUT on those pins. You may want to look at SEROUT2, has more options.
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi,
    You shouldn't have to use the USART but I see no apparent reason not to when it is on the same pins as you're trying to use with SEROUT.

    If you're using SEROUT you can use any pin you like as long as it can be made an output but you must make sure that all other peripherals multiplexed to that particular pin is turned off. Start by doing a blink-a-led on the particular pin you want to use, when you have that working you should be able to get data out with the SEROUT or SEROUT2 commands.

    By the way, setting RCSTA, TXSTA etc does not effect SEROUT/SERIN commands, only HSEROUT etc. With HSEROUT you have to use a levelconverter as it can't send the data inverted - as far as I know.

    If you're going to use the USART you can only use the pins to which the USART is connected (PortC.5 and 6 in this case but some chips can switch them around to alternative pins). But again you need to make sure that any other peripheral that may be on the same pin isn't "taking over" so to speak.

    /Henrik.

  11. #11
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    Ok, here is what I have


    DEFINE OSC 20
    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    TRISB = %00010000 ' Set TX (PortB.5) to in, rest outputs
    TRISA = %01111111
    SPBRG = 25 ' Set baud rate to 2400
    RCSTA = %10010000 ' Enable serial port and continuous receive
    TXSTA = %00100000 ' Enable transmit and asynchronous mode
    INTCON2.7 = 0

    pinin VAR PORTB.4 ' Define pinin as PORTB.4
    pinout VAR PORTB.5 ' Define pinout as PORTB.5

    how do I setup the SEROUT command to send "This Is a Test" ?
    how fo I setup the SERIN command to receive "Test Received" ?

  12. #12
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    What configs are you using? If it is the default ones in pbp/18f2450.inc then they are set to:

    Code:
            __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    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
            __CONFIG    _CONFIG3H,_PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
            __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_BB1K_4L & _XINST_OFF_4L
    That should get you 48 mhz instead of 20 mhz.

    And for the hardware, do you have the 3.3 volt jumper on, or off?

    Can you get the chip to blink an LED or something to make sure its running?

    If you decide to go with hardware uart here are some defines for 48 mhz.

    'DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    'DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    'DEFINE HSER_SPBRG 77 ' 9600 Baud @ 48MHz, 0.16%
    'DEFINE HSER_CLROERR 1 ' Clear overflow automatically

  13. #13
    Join Date
    Mar 2008
    Posts
    43


    Did you find this post helpful? Yes | No

    Default

    I have an external 20mhz oscillator. Can you tell me what I need to do to use SEOUT2 and SERIN2 on pins PORTB.5 and PORTB.4?

  14. #14
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PlantBob View Post
    I have an external 20mhz oscillator. Can you tell me what I need to do to use SEOUT2 and SERIN2 on pins PORTB.5 and PORTB.4?
    Hi Bob,

    Are you able to blink an led with the chip? It may sound stupid, but that eliminates a lot of other issues.

    With the 20 mhz external OSC and the default configs, your chip will run at 48 mhz. So if you are using the default configs, you will have to define your OSC. You might also try Darrel's All Digital. It takes care of some of the analog settings that can throw us for a loop. It is located here: http://www.picbasic.co.uk/forum/cont...54-All-Digital
    Im away from my PBP right now, but you should be able to use the PBP serout example from the manual.

    Let us know if you get stuck.

  15. #15
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You definitely do not want to enable the hardware USART if you want to use any bit-banged serial routines like SEROUT/SERIN or SEROUT2/SERIN2 on the hardware RX/TX pins.

    Enabling the hardware USART prevents you from using the TX/RX pins as digital, so bit-banged serial commands can't control these pins.

    And double-check your connections to the ST232. I suspect you have TX and RX backwards.
    Last edited by Bruce; - 3rd February 2011 at 20:57. Reason: ST232 Connections
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  16. #16
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    And double-check your connections to the ST232. I suspect you have TX and RX backwards.
    he is using this board http://www.olimex.com/dev/pic-p28.html so wiring should be correct. (for the hardware serial port that is)

  17. #17
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Pin 17, TX on the PIC, should connect to pin 10 on the 232.
    Pin 18, RX on the PIC, should connect to pin 12 on the 232.

    Not the other way around like he states in his 1st post.
    Last edited by Bruce; - 4th February 2011 at 00:24.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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