Coding and general discussion relating to the compiler
Moderators: David Barker, Jerry Messina
-
TonyR
- Posts: 75
- Joined: Fri Jan 14, 2011 11:49 pm
- Location: Sydney
-
Contact:
Post
by TonyR » Tue Sep 15, 2015 10:59 pm
I've been using USART2.write for years with many 18F and it always works fine but not this time. Im using 18F87K22 for the first time.
If I use USART2.write to transmit 1 char it works fine. On my scope its the correct bit width and on Teraterm I can see the char no problem.
But if I increase the string to more than two chars there's silence. (USART.write has no problem).
This works
Code: Select all
Device = 18F87K22
Clock = 12
Config FOSC = HS1
Include "usart2.bas"
USART2.SetBaudrate(br9600)
DelayMS(100)
While true
USART2.Write ("H")
DelayMS(200)
Wend
This doesnt work
Code: Select all
Device = 18F87K22
Clock = 12
Config FOSC = HS1
Include "usart2.bas"
USART2.SetBaudrate(br9600)
DelayMS(100)
While true
USART2.Write ("Hi")
DelayMS(200)
Wend
Is it a bug in SF setting up the USART2 maybe?
-
TonyR
- Posts: 75
- Joined: Fri Jan 14, 2011 11:49 pm
- Location: Sydney
-
Contact:
Post
by TonyR » Wed Sep 16, 2015 12:08 am
I have a work around which is below, in case anyone else has this problem.
But I would be interested to know if I have done something not right....(Jerry, David...)
Code: Select all
Device = 18F87K22
Clock = 12
Config FOSC = HS1
Include "usart2.bas"
Dim Txstring As String(20)
dim n as byte
Dim b As Byte
USART2.SetBaudrate(br9600)
Txstring = "Swordfish"
while true
for n = 0 to 8
b = Txstring(n)
usart2.write(b)
next
usart2.write(13,10)
DelayMS(200)
wend
-
Jerry Messina
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Post
by Jerry Messina » Wed Sep 16, 2015 1:19 pm
The routine 'Sub WriteItem(pText As String)' in the USART/USART2 libraries uses some inline asm that doesn't always work (it's missing some bank select code).
Also, the 'SetBaudrate()' routine has issues with some chips if you use the 16-bit BRG.
EDIT: I moved the zip file with the fixed library files to the "Updated Swordfish Modules" section of the User Module wiki page at
http://www.sfcompiler.co.uk/wiki/pmwiki ... er.Modules
-
TonyR
- Posts: 75
- Joined: Fri Jan 14, 2011 11:49 pm
- Location: Sydney
-
Contact:
Post
by TonyR » Wed Sep 16, 2015 8:17 pm
Thanks Jerry, l will try them today. Usart2.read is silent too on 18f87k22.
-
Jerry Messina
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Post
by Jerry Messina » Wed Sep 16, 2015 9:12 pm
I use the 87K22 all the time, so I think those should work but if not drop a note and I'll get them fixed (mine are a bit different).
Make sure you're setting the pins to digital mode since RX2 is an analog pin (see
SetDigitalIO)
-
TonyR
- Posts: 75
- Joined: Fri Jan 14, 2011 11:49 pm
- Location: Sydney
-
Contact:
Post
by TonyR » Wed Sep 16, 2015 9:39 pm
Thanks greatly Jerry, usart2.write worked as soon as I swapped in the fixed library.
usart2.readbyte worked as soon as I put in setalldigital.