USART problems


Closed Thread
Results 1 to 40 of 48

Thread: USART problems

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    What's the purpose of two HSERIN's?
    Regards,

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

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Question

    I have a variable length file. The first SERIN2 processes a RECORDTYPE, the second processes VARIABLEDATA.

    That way I can have record A: 33 characters, and record B: 24 characters. My file consists of 6 different record layouts at the moment, and I'd like to process all the records in one batch. I'd like to avoid having to use 6 different PICs to load them onto EEPROM.

    I can't find any reference to where the flow pin is connected on the DB-9 connector. I checked here:

    http://www.klm-tech.com/technicothic...2.html#pinouts

    And my best guess would be pin 8, but it's not working, neither is 7. Actually, I tried all the empty pins without success. Maybe I need a resistor like on the RX and TX pins?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Unhappy

    I found this Assembler program that uses CTS and RTS:

    http://www.ecomorder.com/techref/mic...tinttst-rh.htm

    I kinda follow the code, sorta. At least I understand his note about how RTS and CTS have to be opposite since MAX232 will invert their value; so you set 0 to get 1 and vice versa.

    I figure the same routine could be written in BASIC Pro, I'm just not sure on some of the variables and sizes (like for the input/output buffers, stuff like that).

    So now I gotta tear at my MAX232 circuit, I had only used one line, leaving the other unused. I put it on a small board for the sake of convenience when moving it about my projects. Well, having no working room on it isn't proving convenient any more.

    At least it's a start as to how to use USART with RTS and CTS. I can't find any references for the 'flow pin' used in SERIN2 so my options are getting slimmer.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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


    Did you find this post helpful? Yes | No

    Default

    With hardware handshaking, the PC transmits data when CTS is asserted, but you'll also need to setup your PC & terminal software to use hardware handshaking.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    How about something like this?
    Code:
    ' ** // PIC16F877, 20MHz crystal, MCS+ loader
    ' ** // Interrupt driven serial receive
    
    ' ** // Buffers up to 80 characters using the hardware
    ' ** // USART. Buffering ends when the EOM "~" character
    ' ** // is received.
    
    ' ** // Includes auto over-run reset + RCIF bit polling
    ' ** // for new serial characters
    
    define  LOADER_USED 1
    define  OSC 20
    define  HSER_BAUD 19200 ' Set data rate
    DEFINE  HSER_CLROERR 1  ' Automatically clear over-run errors
    DEFINE  HSER_RCSTA 90h  ' Enable USART receive
    DEFINE  HSER_TXSTA 24h	' TXSTA=%00100100. TX enable, BRGH=1 for high-speed
                            ' TXSTA=%00100000. TX enable, BRGH=0 for low-speed
    
    GP      VAR BYTE        ' GP variable
    BytesIn var byte[80]    ' Up to 80 bytes
    ByteCnt var byte        ' Indicates number of bytes in buffer
    X       VAR BYTE        ' GP var
    EOM     CON "~"         ' "End Of Message" marker
    OERR    VAR RCSTA.1     ' Alias USART over-run bit
    CREN    VAR RCSTA.4     ' Alias USART continuous receive enable bit
    RCIF    VAR PIR1.5      ' Alias USART received character interrupr flag bit
    
    ' ** // Zero vars & A/D off
    ByteCnt = 0             ' Zero counter
    ADCON1 = 7              ' A/D off, all digital
    
    ' ** // Setup serial interrupts
    INTCON = %11000000		' Enable interrupts
    PIE1.5 = 1				' Enable interrupt on USART
    
        On Interrupt Goto Main
        GOTO Doodle
        
        Disable    
    Main:
        WHILE RCIF              ' If RCIF=1 there's a new character in RCREG
         BytesIn[ByteCnt]=RCREG ' Yes. Then store it in array
         If BytesIn[ByteCnt]=EOM then OutMsg ' Display on receipt of terminating char 
        ByteCnt=ByteCnt+1      ' Increment array index pointer
        WEND                    ' Exit only when RCREG is clear
        RESUME                  ' Return to normal operation prior to interrupt
        ENABLE
    
    OutMsg:   ' Note: Interrupts are still disabled here
        HSEROUT [13,10,dec ByteCnt," Bytes Rcvd",13,10]
        HSEROUT [str BytesIn\ByteCnt,13,10]
        FOR GP=0 to ByteCnt   ' Clear array bytes 0 to ByteCnt
         BytesIn[GP]=0        '
        NEXT                 '
        ByteCnt=0             ' Reset index pointer back to first element
        WHILE RCIF            ' Trash any left over characters in RCREG buffer
         GP=RCREG             ' after EOM has been received
        WEND
        GOTO Main             ' RCIF is clear, so return
        
    Doodle:  ' Waste time here waiting for serial interrupt
        HIGH PORTB.0
        FOR X = 0 TO 250
            PAUSEUS 20        ' Do not use long pauses. It slows down interrupt
        NEXT X                ' processing, and requires a slower data rate to work
        LOW PORTB.0           ' with on interrupt
        FOR X = 0 TO 250
            PAUSEUS 20
        NEXT X
        GOTO Doodle
    
        end
    If you have a terminator on the end of your data packets, this makes the whole process pretty simple.

    If you just need to PIC to tell the PC to stop sending data, connect the PIC flow control pin to the PC CTS pin.
    Regards,

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

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Thumbs up

    That's perfect Bruce! Thanks!

    I read a tutorial on controlling the DB9 pins directly, modem style, and I was going nowhere fast. Your technique is much better, I had read about it earlier but I didn't know how to tie it all together. And best of all, it uses USART instead of SERIN2.

    Yup, I had an asterisk as end of record marker, but I like tilde even better. There's no chance at all that it will appear in the text so it makes a better choice.

    I don't really care about telling the PC to stop sending, but I'll keep your solution in mind. My main goal was just to download a file onto EEPROM, once complete, I didn't really care about cleaning up. This will be used for one-shots, once the data is on the EEPROM, I don't alter the data.

    Welp, I'm off to try this. If I got it right; MAIN is the USART I/O routine, DOODLE is waiting for input and OUTMSG is an end of record summary.

    Robert


    Stupidlesser as each day goes on...
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default

    Bruce,

    Can you PM or email me your last name please?

    roberthedan AT hotmail DOT com

    I'd like to give credit where credit is due in the comments.

    And you've also made yourself a new customer at Rentron.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Question

    On Interrupt Goto Main
    GOTO Doodle

    Disable
    Main:
    WHILE RCIF ' If RCIF=1 there's a new character in RCREG
    BytesIn[ByteCnt]=RCREG ' Yes. Then store it in array
    If BytesIn[ByteCnt]=EOM then OutMsg ' Display on receipt of terminating char
    ByteCnt=ByteCnt+1 ' Increment array index pointer
    WEND ' Exit only when RCREG is clear
    RESUME ' Return to normal operation prior to interrupt
    ENABLE

    ---------------------------------------------------

    Isn't DISABLE an unexecutable statement? Shouldn't it be the 1st statement of Main?

    Then at the bottom of OutMsg, we could GOTO the WHILE statement as it is doing now; label Main1 on Disable, and Main2 on While?

    Or am I missing something?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. My USART problems..
    By Glenn in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 31st July 2009, 01:00
  2. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  3. USART TXREG Problems
    By BigH in forum Serial
    Replies: 2
    Last Post: - 11th January 2006, 00:30
  4. Replies: 5
    Last Post: - 1st December 2004, 12:49
  5. Synchronous USART problems... HELP!!!
    By moni in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th November 2003, 19:00

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