Dual USART, Second USART sends but not receives, PIC18F24K22


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2017
    Posts
    17

    Default Dual USART, Second USART sends but not receives, PIC18F24K22

    My application is utilizing both USARTs for this chip. The primary USART is working fine. The second USART will transmit but will not receive. I sususpect I have an issue with the configuration. I did see this note for the RX2 pin in the documentation with Note 2 below for the RX2 pin. I do not know what this information means.


    2: Alternate pin assignment for P2B, T3CKI, CCP3 and CCP2 when Configuration bits PB2MX, T3CMX, CCP3MX and
    CCP2MX are clear.

    Thanks
    George

    My configuration and code is:
    'Configuration
    DEFINE FOSC INTIO67
    OSCCON = 110010 ' Set internal 8Mhz OSC




    Define OSC 16


    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    define HSER_BAUD 9600
    DEFINE HSER_CLROERR 1


    DEFINE HSER2_RCSTA 90h
    DEFINE HSER2_TXSTA 24h
    define HSER2_BAUD 9600
    DEFINE HSER2_CLROERR 1






    ANSELA = 000000
    ANSELB = 000000
    ANSELC = 000000 ' Turn Off A2d


    ADCON2 = 101101
    ADCON1 = 001000
    ADCON0 = 011000




    TRISA = 111111 ' Setup TRIS
    TRISB = 110000
    TRISC = 111111


    PORTA = 100000 ' Setup ports
    PORTB = 000000
    PORTC = 000000




    Init_9800
    Flag = 0
    low led1
    pause 100
    'Initialization Process
    'Send 0 then check hserin2 for a 13
    'Increament x with each 13 received, once 13 is received 3x then OEC = 1
    'Then wait for $43 for Report Transfer On
    'Then wait for $42 for Touch report on
    'At this point, OEC = 2 and is considered initialized
    hserout2 [hex $0]
    hserin2 100, main, [hex char2]
    hserout2 ["input was", hex char2]
    if char2 = $13 then
    OEC = 1
    x = X + 1
    if X > 2 then
    OEC = 2
    X = 0
    high led4
    endif
    endif
    goto main
    return

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185

    Default Re: Dual USART, Second USART sends but not receives, PIC18F24K22

    TRISB.7 = 1
    TRISC.7 = 1


    RX1 and RX2 Pins = input pins.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default Re: Dual USART, Second USART sends but not receives, PIC18F24K22

    I only see 6 of the 8 TRIS bits being set for each port.
    Dave Purola,
    N8NTA
    EN82fn

  4. #4
    Join Date
    Sep 2017
    Posts
    17

    Default Re: Dual USART, Second USART sends but not receives, PIC18F24K22

    Something happened in the cut and paste, all 8 TRIS bits are set.
    I did change the bits to inputs and it didn't resolve the issue:
    TRISA = %11111111 ' Setup TRIS
    TRISB = %11110000
    TRISC = %11111111

    Any other suggestions on why hserin2 may not be working?

    Thanks
    George

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,485

    Default Re: Dual USART, Second USART sends but not receives, PIC18F24K22

    no 1
    http://www.picbasic.co.uk/forum/showthread.php?t=19594
    no 2
    OSCCON = 110010 ' Set internal 8Mhz OSC




    Define OSC 16
    what is it 8 or 16 ?

    no 3
    'Configuration
    DEFINE FOSC INTIO67
    that's not a configuration , it does nothing


    no 4
    hserin2 100, main, [hex char2]
    main does not exist in the snippet , who knows what goes on there

    no 5

    given that hserin2 does infact work correctly when used correctly , the fault probably lies in the code not shown
    Warning I'm not a teacher

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,485

    Default Re: Dual USART, Second USART sends but not receives, PIC18F24K22

    also, char2 we cant see how it was declared but if its a byte then it can only receive a single hex digit
    it may never be $13 it may only be 0 to F
    $13 sent as serial hex is ascii 0x31,0x33 ie two chrs

    you need to be sure what you actually sending

    I'd try this if hex is whats sent
    hserin2 100, main, [hex2 char2]
    hserout2 ["input was", hex char2]
    if char2 = $13 then
    Last edited by richard; - 12th January 2018 at 13:13.
    Warning I'm not a teacher

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185

    Default Re: Dual USART, Second USART sends but not receives, PIC18F24K22

    Quote Originally Posted by svjohngalt View Post

    Define OSC 16


    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    define HSER_BAUD 9600
    DEFINE HSER_CLROERR 1


    DEFINE HSER2_RCSTA 90h
    DEFINE HSER2_TXSTA 24h
    define HSER2_BAUD 9600
    DEFINE HSER2_CLROERR 1

    return

    Sinde you say that UART1 is working fine with your config settings, then UART2 should also be working fine with the same config settings.
    Change your lines to

    Code:
    DEFINE OSC 16
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 160 ' 9600 Baud @ 16MHz, -0,08%
    SPBRGH = 1
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER2_SPBRG 160 ' 9600 Baud @ 16MHz, -0,08%
    SPBRGH2 = 1
    BAUDCON2.3 = 1         ' Enable 16 bit baudrate generator
    Last edited by sayzer; - 12th January 2018 at 15:32.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    Join Date
    Sep 2017
    Posts
    17

    Default Re: Dual USART, Second USART sends but not receives, PIC18F24K22

    It is now working. It was the issue of sending bytes and data mismatch. I had HSERIN2 100, main, [HEX char2] with char2 defined as a byte. When I dropped the HEX modifier, it worked properly and that is my last issue to resolve. My project is not complete and thank you everyone for your input.

    Thanks
    George

Similar Threads

  1. My USART problems..
    By Glenn in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 31st July 2009, 01:00
  2. USART to PC
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th October 2008, 00:09
  3. Usart
    By lew247 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd June 2008, 23:41
  4. PIC16F877 sends/receives data to/from a PC
    By ovidiu in forum Serial
    Replies: 1
    Last Post: - 2nd December 2006, 14:09
  5. dual- usart- receive- problem
    By Tomasm in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st June 2004, 17:33

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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