Dual EUSART in 18F25K22


+ Reply to Thread
Page 1 of 5 123 ... LastLast
Results 1 to 15 of 70

Thread: Dual EUSART in 18F25K222313 days old

  1. #1
    Member Peter Truman's Avatar
    Join Date
    Dec 2003
    Posts
    312
    Thumbs Up
    Received: 8
    Given: 7
    Total Downloaded
    406.61 MB

    1 Not allowed!

    Thumbs up Dual EUSART in 18F25K22

    Hi

    I'm looking at using a PIC 18F25K22 in an upcoming project. I'd just like to be sure of my facts before I get a board made.

    Can anyone confirm that I can use a different BAUD rate with each EUSART at the same time, and also that I can use LES's serial buffer with at least one of them.

    Any suggestions as to which Xtal I should use? I'm receiving at 9600 and sending at 115200 (I' thinking of using 22.11840MHz so I get the best chance with 115200 and I can't really see there being a problem with 9600 on the other port at that speed?)

    My reading of the data sheet suggests that this should not be a problem?

    I have to handle serial data coming in to one of the ports at one rate while simultaneously buffering and re-sending at a different rate from the other port! The second port with be half duplex while the first is receive only.

    I'd appreciate any help / advice

    Thanks
    Peter
    Peter Truman

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,396
    Thumbs Up
    Received: 48
    Given: 39
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: Duel EUSART in 18F25K22

    Hi Peter

    I am using a 18F46K22 with both EUSARTs. I run one at 115200 (driving an mp3 decoder) and the other at 9600 baud (driving a radio module). I haven't used Les's buffer though, I did my own. I use the internal clock with the PLL at 64 megs. I found a baud rate that was pretty near 115200, if you haven't got another answer by this afternoon, I'll get the details for you.

    Charlie

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,396
    Thumbs Up
    Received: 48
    Given: 39
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: Duel EUSART in 18F25K22

    Peter

    Here are the two set-ups for my two USARTS:

    ; TX1 on C6 pin 25 RX1 on C7 pin 26 TXSTA1.1 is 1 if buffer empty, 0 if busy HRSOUT xxx
    ; This USART, number 1, is connected to the OGG-VORBIS player (transmit, pin 25 goes to player RX pin) TXREG1 is buffer


    TXSTA1=%10100100 ;clk internal, 8 bit tx, tx enabled, async mode, syn done, BRGH=1, x, x
    RCSTA1=%10110000 ;serial port enabled, 16 bit, enable single rcv, enable rcvr, no addr detect, x, x, x
    BAUDCON1=%00001000 ;x, x, x, o/p idles high, BRG16 is 1, x, x, x
    SPBRG1=138 ;115200 see p.276 of datasheet
    SPBRGH1=0

    ; TX2 on D6 pin 29 RX2 on D7 pin 30 TXSTA2.1 is 1 if buffer empty, 0 if busy HRSOUT2 xxx
    ; This is USART, number 2, connected to XFR radio module
    TXSTA2=%10100000 ;clk internal, 8 bit tx, tx enabled, async mode, syn done, BRGH=0, x, x
    RCSTA2=%10100000 ;serial port enabled, 8 bit, enable single rcv, not-enabled rcvr, no addr detect, x, x, x
    BAUDCON2=%00000000 ;x, x, x, o/p idles high, BRG16 is clr, x, x, x
    SPBRG2=103 ;9600

    If the percents disappear, it's obvious where they should be. This setup works perfectly for me.

    Charlie

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Member Peter Truman's Avatar
    Join Date
    Dec 2003
    Posts
    312
    Thumbs Up
    Received: 8
    Given: 7
    Total Downloaded
    406.61 MB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Thank you Charlie - just what I need. Do you mind if I ask how deep your serial buffer is? Les's is 255 bytes maximum and, while that is enough for this project is is a potential limitation for other things.

    Thanks again
    Peter
    Peter Truman

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,396
    Thumbs Up
    Received: 48
    Given: 39
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Mine was originally 256 circular. I had a byte index that automatically "wrapped" when it reached 255 (254, 255, 0, 1 etc). I don't see any reason why you shouldn't have a bigger buffer than 256 but with one important proviso: you will need a WORD to do the indexing, and there can be problems if a character arrives and causes an interrupt at the same time your non-interrupt code is changing the word pointer. I'm sure you know what I mean, it's not difficult to do as long as you know about it. (Don't ask how I found out!)

    Because my receive routine was receiving packets of data, which had a rigid structure, I dispensed with the buffer and used SELECT CASE to decode the packets directly within the interrupt routine. It was one of those bits of coding that you sit back and admire for its elegance.

    Hope this helps
    Charlie

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,392
    Thumbs Up
    Received: 79
    Given: 46
    Total Downloaded
    1.40 GB

    1 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Quote Originally Posted by charliecoultas View Post
    ...there can be problems if a character arrives and causes an interrupt at the same time your non-interrupt code is changing the word pointer...Charlie
    Couldn't you use separate pointers, a write point in the interrupt and a read point in the non interrupt code?

    Norm

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,396
    Thumbs Up
    Received: 48
    Given: 39
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Hi Norm

    I think that's the way Les does it. But at some time you will have to compare the two pointers to see if any new data has arrived and I think the same problem will occur. Or you could maintain a count of characters in the buffer: increased by the int code when a char arrives, and decreased by the "user" code when a character is taken. This would be more than a byte long and the same would happen.

    I think a possible solution is to disable interrupts for the very short time that the pointer(s) are manipulated outside interrupts.

    Charlie

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,392
    Thumbs Up
    Received: 79
    Given: 46
    Total Downloaded
    1.40 GB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Something like:

    dim writept as byte
    dim readpt as byte
    dim data_array[256] as word

    interrupt:
    data_array[writept + 1] = newdata
    inc writept 'inc after loaded


    main:
    While readpt <> writept
    inc readpt
    ...process... data_array[readpt]
    wend
    goto main

    Norm

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,396
    Thumbs Up
    Received: 48
    Given: 39
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Norm,

    I don't think this would work as you expect. Although your buffer is 512 bytes long, you would be storing each received data byte in half of each buffer word. So there is really only a 256 byte buffer. If I can modify your code:
    • dim writept as word
      dim readpt as word
      dim datachr as byte
      dim gotdata as bit
      dim data_array[1024] as byte ;may have to assign this some other way

      interrupt:
      data_array[writept] = newdata
      inc writept ;writept runs from 0 to 1023
      if writept = 1024 then writept = 0 ;reset write ptr at end of buffer
      gotdata = 1 ;signal new data (may be more than 1)


      main:
      if gotdata = 1 then ;is there at least 1 new byte?
      datachr = data_array[readpt] ;get first new byte
      inc readpt
      if readpt = 1024 then readpt = 0 ;step ptr and reset if end of buffer
      GIE = 0 ;stop ints
      if readptr = writeptr then gotdata = 0 ;clear flag if no more data in buffer
      GIE = 1
      endif ;allow ints again

      ...process your new data

      goto main

      Charlie
    Last edited by charliecoultas; 7th December 2013 at 10:11.

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Member Peter Truman's Avatar
    Join Date
    Dec 2003
    Posts
    312
    Thumbs Up
    Received: 8
    Given: 7
    Total Downloaded
    406.61 MB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Just to finish off - can I confirm that it's perfectly acceptable to change the Baud rate on the fly? I have to keep this compatible with an old legacy project but I can also use ot for other work. I would add a 'hook' in nay new software that the logger could pick up. If it sees the hook it would switch to a much higher baud rate - if not it will stay at 9600.

    Seem reasonable to me - but I could be wrong :-)

    Cheers
    Peter
    Peter Truman

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,396
    Thumbs Up
    Received: 48
    Given: 39
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    I'm sure it's ok Peter. If the switch happened in mid-stream then some characters would be messed up but otherwise I can't see why not. Did you get the main points of the bigger buffer routine that Norm and I devised?

    Something tells me you should disable ints before you change the baud rate, then re-enable them. Otherwise you might get false triggers.

    Charlie

  22. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,858
    Thumbs Up
    Received: 90
    Given: 34
    Total Downloaded
    4.60 GB

    1 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Hi Peter
    I change baud rate on the fly in one of my projects using an 18f4685.
    GPS at 4800 to start then 9600 after. Input switched with a 4066B.
    Not able to access my code at present but will post if you want it. I think it was just the SFR.
    Works like a train
    John

  24. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  25. #13
    Member Peter Truman's Avatar
    Join Date
    Dec 2003
    Posts
    312
    Thumbs Up
    Received: 8
    Given: 7
    Total Downloaded
    406.61 MB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Excellent news - I would have been very surprised if I couldn't but it's always worth asking. Charlie, I did grasp the issues associated with a bigger buffer - reading the posts makes it seem quite simple, but looking at Les's interrupt code, it looks like things are much more complex. I do get the basics though!

    Hey John - I can always count on you to have a code snippet to help me along. I always appreciate any help I can get, so thanks, yes it would be great - only if its no trouble.

    I'm using the Alfat OEM board to write to the USB drive - I've tried with I2C mode - so I receive my data from the legacy device via serial - then control the Alfat board with I2C - it's a bloody nightmare! Sort of works, but does unpredictable things in different circumstances.

    So, I'm ditching the I2C approach and moving to a PIC with 2 USARTS - should have done that in the first place! - So there is no rush with all this, I've just been laying out my new board and it will be after christmas before I get it back from the board house.

    Thanks for the help

    Cheers
    Peter
    Peter Truman

  26. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  27. #14
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,858
    Thumbs Up
    Received: 90
    Given: 34
    Total Downloaded
    4.60 GB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Will do, it will be a few days though.
    John

  28. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  29. #15
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,396
    Thumbs Up
    Received: 48
    Given: 39
    Total Downloaded
    3.45 GB

    0 Not allowed!

    Default Re: Dual EUSART in 18F25K22

    Peter

    Don't be discouraged by the apparent simplicity of our code over Les's. Les has to deal with timeouts if nothing arrives within a certain time. It has to deal with buffer overrun where the user hasn't been quick enough and the put-in pointer has caught up with the take-out pointer. Also, it has to disable the compilers internal HRSIN command and replace it. Plus a few more things no doubt. I didn't include the code to clear the pending interrupt. If you like, I could add the finishing touches to the routine we devised? I can put a finished version of the big buffer routine on the Wiki? John D, is this a good idea?

    Charlie

    Charlie

  30. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. 2 EUSART's interfering with each other
    By [email protected] in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 21st September 2013, 19:18
  2. Using second EUSART
    By Dick Barton in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 26th February 2013, 08:47
  3. 18F25K22 and Pickit2
    By RGV250 in forum The Lounge
    Replies: 2
    Last Post: 30th July 2011, 23:11
  4. dual eusart support?
    By jvjen in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 1st February 2009, 09:25
  5. Eusart #2 Buffered_hserin
    By all77 in forum Proton Plus Compiler v3
    Replies: 2
    Last Post: 22nd December 2008, 00:38

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