SOFTWARE UART - ASM ERRORS

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
LEEDNH
Posts: 25
Joined: Fri Feb 03, 2017 8:44 pm

SOFTWARE UART - ASM ERRORS

Post by LEEDNH » Mon Feb 01, 2021 9:38 pm

I have been running code using the software uart which has worked flawlessly for the past couple of years.
I recompiled and got errors at the asm level. I would very much appreciate any help. Perhaps I could try a copy of SUART V1.4???

After updating to SF VERSION 2.2.3.6 - ICC 1.2.0.7 , the same program
APPEARS TO COMPILE OKAY BUT THE ASM PHASE PUTS UP THE RED FLAG.
GENERATES 3 ERRORS ALL (ASM ERROR):ERROR[113] C:\FILE PATH\name.asm 1067:
Symbol not previously defined (Z) (C) (C)

Device = 18F44k22 'using Vdd = 5.0 v
Clock = 64

' Software UART SET-UP ports tx/rx
SetBaudrate(sbr19200) ' software uart serial data rate is 19200 baud
SetTX(PORTC.4) ' software uart tx port PIN 23
SetRX(PORTC.5) ' software uart rx port PIN 24
SetMode(umInverted) ' software uart serial data is Inverted OR (umTrue)

' ******** READ THE SOFTWARE UART START inverted 19200 8N1 **********
For index = 0 To 115
UART.Read(db)
If index = 16 Then
fix1=db
ElseIf index = 17 Then
fix2=db
ElseIf index > 52 And index < 86 Then
v(index-53) = db
ElseIf index > 109 And index < 114 Then
v(index-106) = db 'v(4) - v(7)
EndIf
Next

LEEDNH
Posts: 25
Joined: Fri Feb 03, 2017 8:44 pm

Re: SOFTWARE UART - ASM ERRORS

Post by LEEDNH » Tue Feb 02, 2021 5:57 am

I think I may have "cried wolf" a bit hastily! I dug out my old computer (on its last legs locks on over-temp) and did not have the error that I mentioned previously. Somehow I must have messed up the installation on the new machine.... I'm a bit embarrassed, one might even say chagrined.....
LEE

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: SOFTWARE UART - ASM ERRORS

Post by Jerry Messina » Tue Feb 02, 2021 10:57 am

I think I may have "cried wolf" a bit hastily!
I don't think you did. Your old PC probably has an older version of the compiler.

The SUART.bas in SF VERSION 2.2.3.6 - ICC 1.2.0.7 will show the error.
I tried to simplify some of the include files and left out some stuff. Sorry!

The attached file should fix it. Unzip and copy SUART.bas to your Library or UserLibrary folder.
NOTE: the file download has been moved to the UserModule Wiki page at https://www.sfcompiler.co.uk/wiki/wiki- ... /SUART.zip

LEEDNH
Posts: 25
Joined: Fri Feb 03, 2017 8:44 pm

Re: SOFTWARE UART - ASM ERRORS

Post by LEEDNH » Tue Feb 02, 2021 10:23 pm

Hi Jerry,
Thank you for your fast response.
The two versions of the compiler that are on the old and new laptops are the latest version - that's what really had me confused...
I loaded up the SUART file and the magic is back!
After my code would no longer compile, I loaded the SUART sample code and it had the same result. Then I thought I would post and inquire.

Back about 3 years, I originally tried to use the standard UART but found the SUART was much easier to implement inside a for-next loop.

Let me just add one final comment... THANK YOU VERY MUCH, JERRY!! (it's one of the most frequent phrases that I see)

LEEDNH
Posts: 25
Joined: Fri Feb 03, 2017 8:44 pm

Re: SOFTWARE UART - ASM ERRORS

Post by LEEDNH » Sat Mar 13, 2021 4:18 am

I am still having problems with the SUART.....THE CODE ASSEMBLES JUST FINE! I USED A COUPLE DIFFERENT SERIAL TERM PGMS REAL TERM SEEMS TO WORK OK, OR AT LEAST BETTER THAN SOME OTHERS GENERALLY.

DUH - THEN I REMEMBERED THAT SF HAS A BUILT IN SERIAL TERM WHICH WORKS BEST.... AS A WAY TO TROUBLE SHOOT THE PROBLEM, i FINALLY LOOPED THE ARRAY BACK TO THE UART WRITE COMMAND AND CAN SUPPLY SOME OF THE I/O AND THE CODE USED.

i INCLUDED THE CONFIG. I THINK I AM RUNNING AT 64MHZ WITH THE 16MHZ RESONATOR X 4...

A LOOK FROM SOMEONE WHO KNOWS WHAT THEY ARE DOING IS APPRECIATED!!!!! i HAVE STARTED TO CLIMB THE WALLS AND MY HEAD IS ACHING FROM COLLISIONS WITH THE CEILING.....

---------------------------------------------------------------------------------------------------------------------------
using SF SERIAL COMMUNICATOR 19200 8N1 USING A USB ADAPTER (LOOPS TO ITSELF FINE)
----------------------------------------------------------------------------------------------------------------------------

test data sent>>>> 1ST TRY: 88 BYTES / 2ND TRY: 176 BYTES (as expected)
LINE #1 TEXT TESTINGLINE #2 abcdefghijklLINE #3 mnopqrstuvwxLINE #4 yz012345678901111111

LINE #1 TEXT TESTINGLINE #2 abcdefghijklLINE #3 mnopqrstuvwxLINE #4 yz012345678901111111

LOOPED THROUGH SUART AS SHOWN BELOW

data received>>>> 1ST TRY:44 BYTES / 2ND TRY 168 BYTES
LN 1TX ETNLN 2acegikLN 3moqsuwLN 4y024680111

LN 1TX ETNLN 2acegikLN 3moqsuwLN 4y024680111LN 1TX ETNLN 2acegikLN 3moqsuwLN 4y02468
!!!LN !DH EDNLN "acegikLN #moacegLN $i
-----------------------------------------------------------------------------------


SOME RELEVANT CODE>>>

Device = 18F14k22 '
Clock = 64 'using 16 MHz x4
Config FOSC = HS 'HS oscillator (high power, >16 MHz)
Config PLLEN = ON

' DIMENSION VARIABLES
'bytes
Dim datrmt(90) As Byte
Dim index As Byte
Dim X As Byte
Dim datval As Byte
Dim db As Byte

'SUART CONFIG ------------------------------------------------------------
SetBaudrate(sbr19200) ' software uart serial data rate is 19200 baud
'SET MODE BEFORE SetTX and SetRX
'SetMode(umInverted) 'software uart serial data is INVERTED at the send end
SetMode(umTrue) 'software uart serial data is TRUE at the send end
SetRX(PORTA.0) ' software uart rx port PIN 19
SetTX(PORTA.1) ' software uart tx port PIN 18



For index = 0 To 87 ' sending 88 bytes

UART.Read(db)
db = db and $7f ' added for trouble shooting
datrmt(index) = db

'If datrmt(0) = datval COMMENTED OUT
'Then GoTo JMPHR1 COMMENTED OUT
'EndIf COMMENTED OUT

UART.Write(db)

Next

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: SOFTWARE UART - ASM ERRORS

Post by Jerry Messina » Sat Mar 13, 2021 12:42 pm

Lee -

Could you post all of the actual code you're using? What you posted doesn't compile as is.

Also, just so you know - in general, software UARTs are usually ok for sending data but have multiple issues reading data.
Since there's no hardware involved, your code must be ready to receive a byte (ie sitting in the UART.ReadByte routine) when the transmitter sends one. Your transmitter has to take this into account and add delays in between sending bytes to allow time for the software UART to process the byte and be ready for the next one.

Doesn't matter too much which terminal program you use (although some are a little more configurable than others). An easy way to test this is to send the string "manually" (ie type it at the keyboard). If it works properly that way but doesn't when you send the entire string then you know you're running into the issue.

This really isn't a PIC or SF issue. You run into the same problem with any chip or language... it's the nature of a software UART.
If you really can't use the hardware USART or live with the limitations, I posted a module on the wiki that's a hybrid of hardware and software Hardware-assisted software uart that works pretty well. It has limits on which pins you can use to receive data since it uses interrupts to detect the RX data START bit.

I haven't tried it on a 14K22, but it should work (famous last words).

LEEDNH
Posts: 25
Joined: Fri Feb 03, 2017 8:44 pm

Re: SOFTWARE UART - ASM ERRORS

Post by LEEDNH » Sun Mar 14, 2021 12:24 am

Hi Jerry
I had a thought about 4 a.m., that I should isolate rx from tx by using a common array but separate FOR-NEXT loops for rx and tx as in half duplex. New code shown below. TNX FOR YOUR SUPPORT!!!!

WORKS GREAT!! I guess it could be called looping data the hard way....

"GET 88 BYTES - NO PIANO INVOLVED ---- SEND 88 BYTES
'-----------------------------------------------------------------------

For index = 0 To 87 ' READ THE 88 CHARACTERS SENT (0-87) FROM RX

UART.Read(db)
lcdrmt(index) = db ' STASH THE 88 BYTES INTO AN ARRAY

Next



For index = 0 To 87 ' 'WRITE TO TX 88 bytes in the array

db = lcdrmt(index)
UART.Write(db) 'send it

Next

LEEDNH
Posts: 25
Joined: Fri Feb 03, 2017 8:44 pm

Re: SOFTWARE UART - ASM ERRORS

Post by LEEDNH » Sun Mar 14, 2021 7:16 am

Jerry
An update on the SUART... After several hours of back and forth at 19200 the version 1.6 SUART works GREAT!!

Downloaded the Hardware-assisted software uart! Placed them in the library - now we do have FULL DUPLEX!

I'll try to use the FDX next weekend...

Best regards
Lee

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: SOFTWARE UART - ASM ERRORS

Post by Jerry Messina » Sun Mar 14, 2021 2:14 pm

Glad you got it figured out.

If you try the FDX module (hwsuart_FD.bas), you'll have to use something other than an 18F14K22.
Full-duplex uses two independent TMRx and CCPx peripherals, one for TX and another for RX, and while the 14K22 has two TMR modules (TMR1/TMR3), it only has a single CCP1 peripheral.

LEEDNH
Posts: 25
Joined: Fri Feb 03, 2017 8:44 pm

Re: SOFTWARE UART - ASM ERRORS

Post by LEEDNH » Sun Mar 14, 2021 10:35 pm

Hi Jerry

I kind of just fell into using the k22 pics (usually the 2xK22) but also the smaller 14K22 when fewer pins are needed.
Thanks very much for the "HEADS UP" as I follow the tried and true engineering maxim regarding the reading of manuals - only after all other options have been exhausted.. Just kidding I saw the 2xK22 test at the start.

Take care
Lee

Post Reply