USART problems


Closed Thread
Results 1 to 40 of 48

Thread: USART problems

Hybrid View

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

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

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

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Hi Robert,

    NOP, see PBP manual. Interrupt handler must be write like this. I agree that it looks weird but compiler handle it for you.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Talking

    The compiler is wrong, and I am right...

    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!

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


    Did you find this post helpful? Yes | No

    Question

    Bruce, your code works perfectly when I process a single record. But I'm trying to add a paragraph at the bottom to read multiple records and failing miserably. I'm sure I'm screwing up the INTERUPT controls. As it stands, RESUME returns into the Doodle paragraph and stays there until my hair falls out (which will be soon).

    I tried to add ON INTERUPT immediately before the Doodle, followed by an INTCON=$80, but I must be messing something up doing that. I want the interupts to happen ONLY during the Doodle logic. I don't want it to fire up while I'm in the middle of extracting the bytes from BytesIn and writing them onto the EEPROM.

    Also, when you 'Trash any left over characters in RCREG buffer, I will be losing characters from the next record. I have to save that in a temporary array and load it back at the start of BytesIn somehow.

    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!

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


    Did you find this post helpful? Yes | No

    Question

    Ok,

    I started again from your code, and modified one thing at a time. I've removed the comments to make it easier to read here (I figure you don't need your own comments).

    1. I saved the data from the 1st record by copying it into BytesGP[ByteGPN]. I need that data so I can write it to the EEPROM.

    2. I was able to get just Doodle under Interupt control.

    3. I was able to save the data from RCREG. There was indeed the 1st character from the next record in there. The data is stored in BytesBK[ByteBKN].

    ?. But I can't figure out what I'm doing wrong to get the rest of the 2nd record. I must be losing some kind of flag or something to tell USART not to hyperspace the rest of the 2nd record.

    ====================================
    define LOADER_USED 1
    ASM
    LIST
    INCLUDE 'M16F87X.INC' ; PM header
    DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
    XALL
    NOLIST
    ENDASM
    define OSC 20
    define HSER_BAUD 19200
    DEFINE HSER_CLROERR 1
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h

    GP VAR BYTE
    BytesIn var byte[80]
    ByteCnt var byte
    BytesGP VAR BYTE[80]
    ByteGPN VAR BYTE
    BytesBK VAR BYTE[80]
    ByteBKN VAR BYTE
    X VAR BYTE
    EOM CON "~"
    OERR VAR RCSTA.1
    CREN VAR RCSTA.4
    RCIF VAR PIR1.5
    ByteCnt = 0
    ADCON1 = 7
    INTCON = %11000000
    PIE1.5 = 1
    ' -------------------------------------------------------------
    GOTO Start
    ' -------------------------------------------------------------
    Main:
    WHILE RCIF
    BytesIn[ByteCnt]=RCREG
    If BytesIn[ByteCnt]=EOM then OutMsg
    ByteCnt=ByteCnt+1
    WEND
    RESUME
    ' -------------------------------------------------------------
    OutMsg:
    HSEROUT [13,10,dec ByteCnt," Bytes Rcvd:",STR BytesIn\ByteCnt]
    FOR GP=0 to ByteCnt
    BytesGP[GP]=BytesIn[GP]
    BytesIn[GP]=0
    NEXT
    ByteGPN=ByteCnt-1
    ByteCnt=0
    ByteBKN=0
    WHILE RCIF
    BytesBK[ByteBKN]=RCREG
    ByteBKN=ByteBKN+1
    WEND
    GOTO Main
    ' -------------------------------------------------------------
    On Interrupt Goto Main
    Doodle:
    FOR X = 0 TO 250 : PAUSEUS 20 : NEXT X
    FOR X = 0 TO 250 : PAUSEUS 20 : NEXT X
    RETURN
    INTCON=$80
    ' -------------------------------------------------------------
    Start:
    ByteGPN=0
    WHILE ByteGPN=0 : GOsub Doodle : Wend
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
    ' BytesGP[ByteGPN] Data from BytesIn is saved here for EEPROM
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
    ' Place contents trashed from RCREG back in beginning of BytesIn
    ByteCnt=ByteBKN-1
    For X=0 TO ByteCnt
    BytesIn[X]=BytesBK[X]
    NEXT X

    HSEROUT [13,10,dec ByteCnt," Bytes Saved:",STR BytesIn\ByteCnt]
    GOTO Start
    ' -------------------------------------------------------------
    end
    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