hserout issues on the 18F26K83


+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    137

    Default hserout issues on the 18F26K83

    Hi all,
    Having issues transmitting numeric data out from the 18F26K83 using hserout. No problems with the software serout2, but for some reason all my numerical data is corrupted for hserout ie. any numeric variable sent with a dec or dec2 or dec6 etc is corrupted. Anything sent between quotation marks "" sends fine. Any ideas?

    This is what I should be seeing in my output (transmitted with serout2):

    Start Report
    Base_Pressure =102338
    Elapsed time (s),Z_Gs,Baro_Temp,Baro_mBar,Ch1_Out,Ch1_Active,Ch 1_Firec,Ch2_Out,Ch2_Active,Ch2_Fired,Timer_ON,Time r_Active,Timer_Time,Inhibit_Time,Min Press
    0.000000,2.558,20.21,1023.27, , , , , , ,, ,15000000,0,1023.27
    0.024605,1.698,20.21,1023.27, , , , , , ,, ,15000000,0,1023.27
    0.061340,0.447,20.21,1023.27, , , , , , ,, ,15000000,0,1023.27
    0.098057,-1.4294966557,20.21,1023.28, , , , , , ,, ,15000000,0,1023.27
    0.136882,0.610,20.21,1023.28, , , , , , ,, ,15000000,0,1023.27
    0.183435,2.3,20.21,1023.29, , , , , , ,, ,15000000,0,1023.27
    0.219704,2.952,20.21,1023.30, , , , , , ,, ,15000000,0,1023.27
    0.256500,1.135,20.21,1023.30, , , , , , ,, ,15000000,0,1023.27


    And this is what I'm getting with hserout:

    Start Report
    •}A••= LŠŠj
    Elapsed time (s),Z_Gs,Baro_Temp,Baro_mBar,Ch1_Out,Ch1_Active,Ch 1_Firec,Ch2_Out,Ch2_Active,Ch2_Fired,Timer_ON,Time r_Active,Timer_Time,Inhibit_Time,Min Press
    r‚‚‚‚‚b& b&r’bLŠrb, , , , , , , , S bLŠrj
    rŠ‚ŠššbL MS &r’bLŠrLb, , , , , , , , S bLŠrj
    r’’’bL ªb&r’bLŠrLb, , , , , , , , S bLŠrj
    r‚brŠŠb&r’bLŠrLb, , , , , , , , S bLŠrj
    rLºbršb&r’bLŠrLL , , , , , , , , S bLŠrj
    rL’brb&r’bLŠrL& , , , , , , , , S bLŠrj
    rLSbrŠb&r’bLŠrL& , , , , , , , , S bLŠrj
    r&š’brb&r’bLŠrL& , , , , , , , , S bLŠrj
    r&S‚brʲb&r’bLŠrL& , , , , , , , , S bLŠrj
    r&š¢brN& &r’bLŠrL& , , , , , , , , S bLŠrj
    r&‚‚brN“ &r’bLŠrL& , , , , , , , , S bLŠrj
    r&bL ‚Šb&r’bLŠrL& , , , , , , , , S bLŠrj


    Same code, same everything other than serial transmission method.

    Thanks for any assistance,

    Troy
    Last edited by rocket_troy; - 13th May 2024 at 15:19.

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    654


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    You might want to double check that you are setting the hardware communication correctly. I have used the code below to set the HSEROUT/HSERIN for the 18F4550. You might want to check the correct settings for the 18F26K83. I have never used that chip before. The Mr. E calculator was helpful to me.

    Code:
    '####### MR. E CALCULATOR SETTINGS #########	
    DEFINE HSER_RCSTA 90h       'ENABLES SERIAL PORT		
    DEFINE HSER_TXSTA 20h       'ENABLES TRANSMIT
    		
    DEFINE HSER_CLROERR 1       'Hser clear overflow automatically 		
    
    SPBRG = 25
    SPBRGH = 0
    		
    'DEFINE HSER_SPBRG 25        '115200 BAUD
    		
    BAUDCON.3 = 1               'ENABLE 16 BIT BAUDRATE GENERATOR
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    137


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    I've set the hardware config totally manually from the datasheet and via PBP defines (suggested in the supplementary document PIC18FxxK42_notes) and many hybrids of the 2 methods.

    Code:
    OSCFRQ = %1000 '64Mhz
    Define OSC 64
    
    '******************************************************************************
    'Configure UART Control Register 0
    U1CON0.7 = 1 'BRGS = 1 (high speed baud generator)
    U1CON0.6 = 0 'ABDEN = 0 Auto-baud Detect Disabled 
    U1CON0.5 = 1 'TXEN: Transmit Enabled
    U1CON0.4 = 0 'RXEN: Receive Disabled
    U1CON0.3 = 0 '0000 = Asynchronous 8-bit UART mode
    U1CON0.2 = 0 '0000 = Asynchronous 8-bit UART mode
    U1CON0.1 = 0 '0000 = Asynchronous 8-bit UART mode
    U1CON0.0 = 0 '0000 = Asynchronous 8-bit UART mode
    
    U1CON1.7 = 0 'Turn Serial port 1 off for baud setting
     
    U1BRGL = 138  'Baud Divisor low byte
    U1BRGH = 1    'Baud Divisor high byte
    U1RXPPS = %1011 'Assign UART RX pin to RB3
    RB0PPS = %010011  'Assign UART1 TX pin to RB0
    U1CON1.7 = 1 'Turn Serial port 1 on
    and the more straightforward method:

    Code:
    Define OSC 64
    DEFINE HSER_RXREG PORTB
    DEFINE HSER_RXBIT 3
    DEFINE HSER_TXREG PORTB
    DEFINE HSER_TXBIT 0
    DEFINE HSER_BAUD 115200
    If that was the issue, then why does everything in the quote marks come through okay?

    Regards,

    Troy
    Last edited by rocket_troy; - 13th May 2024 at 16:46.

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    654


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    Use a logical analyzer to see what's coming out of the chip. Compare the output of the SEROUT2 to the output of the HSEROUT2 using the logical analyzer. You might think that your output is 115200, but it is not. I suspect that you have it set up for another baud rate. Also, check if you have the data configured as 8N1.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  5. #5
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    137


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    Again, if I have it set up as another baud rate, then why is every text string in quotation marks coming through fine?

    Troy

  6. #6
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    137


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    Okay, I think I might have solved this one. I didn't have the TRIS of the transmit pin configured as an output. I was under the erroneous impression the UART controller trumped control of any port setting while active. I misinterpreted page 463 of the datasheet:
    "When TXEN is set and the transmitter is not idle, the TX pin is automatically configured as an output. When the transmitter is idle, the TX pin drive is relinquished to the port TRIS control"

    Damn these serial issues have been throwing some curveballs at me recently. Just transmitting enough correct data to totally throw me off the scent... damn it...

    Troy

  7. #7
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    654


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    If you connect a logical analyzer to the serial lines, you know for sure if data is being transmitted or not. That would have saved you a lot of time. I always put in my PCB designs a testing point for all the serial data lines.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    I've been having some issues lately, not with that device specifically but with MCS Serial Communicator (or so it seems). I'm communicating with my board using simple ASCII commands at 57600 baud. Single letter/digits commands (like '?' works most of the time, multi letter/digit commands (like 'P100' works sometimes but most often not.

    Thing is, if I use TeraTerm instead everything works perfectly, same computer, same USB cable, same FTDI adapter, same board. Disconnect Serial Communicator and connect TeraTerm to the same virtual COM port and it just works. I have no idea what's going on, before trying TeraTerm I even changed the PIC chip on the board cause I figured I've damaged the UART pins somehow but needless to say the new chip behaved exactly the same.

    Anyone else seen anything like this when using Serial Communicator built into MicroCode Studio?

    I'm going to put the scope and/or logic analyzer on it and see if I can see anything different.

    /Henrik.

  9. #9
    Join Date
    Dec 2010
    Location
    Melbourne Australia
    Posts
    137


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    I didn't even realize that MCS & MCSX had a Serial Communicator [blush]. Been using them for... dunno... 20+ years and never noticed. The only defence I have is I'm only an occasional user/coder.

    Troy

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,825


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    Well, I did knew that but something in my mind was telling me not to use it...

    I also am using TeraTerm and from time to time Br@y Terminal that has some nice automations.

    Ioannis

  11. #11
    Join Date
    Aug 2011
    Posts
    415


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    Quote Originally Posted by HenrikOlsson View Post
    ...Single letter/digits commands (like '?' works most of the time, multi letter/digit commands (like 'P100' works sometimes but most often not.
    This could be due to your code and how the two terminals work. MCS will send the data when you click 'send', or when you hit 'Enter' if you have the transmit window setting 'Transmit on carriage return' checked.

    For TeraTerm, this is configurable (char vs line mode), but typically it's set to transmit as the individual chars are entered.

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    Yep, I figured it probably have something to do with that.
    Strange thing is that the code has been working fine with MCS for over 10 years but now it doesn't. So I've messed something up.

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,825


    Did you find this post helpful? Yes | No

    Default Re: hserout issues on the 18F26K83

    Only a tiny bit is enough to do that!

    Ioannis

Similar Threads

  1. Loop issues
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th September 2021, 01:42
  2. A/D compiler issues
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th March 2014, 13:24
  3. A/D, and compiler issues.
    By BobEdge in forum PBP3
    Replies: 4
    Last Post: - 27th March 2014, 13:20
  4. button press AND hserout issues?!
    By Giulio in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 31st July 2011, 01:22

Members who have read this thread : 11

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