PDA

View Full Version : hserout issues on the 18F26K83



rocket_troy
- 13th May 2024, 14:56
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

rsocor01
- 13th May 2024, 16:16
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.



'####### 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

rocket_troy
- 13th May 2024, 16:41
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.


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:


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

rsocor01
- 13th May 2024, 17:35
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.

rocket_troy
- 13th May 2024, 23:08
Again, if I have it set up as another baud rate, then why is every text string in quotation marks coming through fine?

Troy

rocket_troy
- 14th May 2024, 05:25
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

rsocor01
- 14th May 2024, 17:53
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.

HenrikOlsson
- 16th May 2024, 20:36
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.

rocket_troy
- 17th May 2024, 04:08
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

Ioannis
- 20th May 2024, 20:37
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

tumbleweed
- 21st May 2024, 14:05
...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.

HenrikOlsson
- 22nd May 2024, 15:13
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.

Ioannis
- 24th May 2024, 17:29
Only a tiny bit is enough to do that!

Ioannis

Chris777
- 14th June 2024, 12:34
It seems to work fine with the serout2 software, but there's something off with hserout. It could be due to a difference in how numerical data is handled by these two types of software.
Best regands 😊 (https://mazzani.pl)