bit bashing with SUART module-not reading port - SOLVED

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

bit bashing with SUART module-not reading port - SOLVED

Post by RadioT » Tue Mar 27, 2012 4:37 pm

Hello,

I decided to give using a free port pin a go on my 18F87j11, since the serial ports are used up. I am putting out a GPS signal to port J7 directly, with no RS232 level shifter. I have run the same GPS output for several years on a EUSART port.

I'm running the sample SUART demo program that comes with SF. For whatever reason, I just can't seem to get any data into the port. Set up RX as j.7 and TX as j.6. The signal is 2V from low to high, although I should mention that with this GPS module I have to use a pullup resistor. I have the trace on a scope, though, and the transisions look good.

I don't suppose there have been any updates to this module? On a more complex version that is able to compile in MPLab (the small version can't for whatever reason) I see the "read" function enters the suart module and never is happy it has seen the FTerminator byte.

Anybody run into this problem before?

73's,

de Tom
Last edited by RadioT on Wed Mar 28, 2012 9:04 am, edited 1 time in total.

User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Post by RadioT » Wed Mar 28, 2012 7:24 am

Now SOLVED

Things I have found as I worked through examples:

1. don't forget to set OSCCON to vary speed...."clock = xx" only tells the compiler what speed to use in the rate calculations.

2. transmitting a string works fine.

So far, have code:

Code: Select all

Device = 18F87J11
Clock = 32

Include "SUART.bas"
Include "convert.bas"

// Set speed to internal 8 MHz clock
OSCCON.6 = 1
OSCCON.5 = 1
OSCCON.4 = 1

// Multiply speed x 4 = 32 MHz
OSCTUNE.6 = 1

//Set input and output I/O pins
SetRX(PORTJ.7)
SetTX(PORTE.1)
SetMode(umTrue)

// clear off anything in a pin register, to be sure, as per Microchip datasheet I/O section
Asm
clrf PORTJ
clrf LATJ
End Asm

//Set up a Test Loop for transmit

Whle true

   UART.Write("Bitbanging",13,10)

Wend

So all this gives a nice output waveform.

To see if the Schmidt Trigger input port I'm using is fine, substituted the following in the While loop:

Code: Select all

Whle true

   If PORTJ.7 = 1 then PORTE.0 = 1 
   ElseIf PORTJ.7 = 0 then PORT.0 = 0 
   Endif

Wend
The result is what appears to be a perfect duplicate waveform on the output, as expected. So the Schmidt Trigger is not a problem.

So now the While loop is what it was in the original Sample example:

Code: Select all

Dim Value as string //added the string array for holding the data read

Whle true

   UART.Read(Value)
   UART.Write(Value,13,10)

Wend
What did, in the end, fix the problem was creating a new SUART.BAS library file. SF changed the ASM directives to uppercase in this process. That is the only difference between the old and the new version of SUART.BAS that I made. Perplexing but true. Now the I/O port (in this case, PORTJ.7) reads the GPS strings perfectly.

So I have no idea why case would make a difference in a library file. Maybe it is just a quirk in my system. It is a brand-new Windows 7 box with the latest-and-greatest SF version 2.2.1.4, ICC 1.1.5.7 that I bought to ensure it worked in the shiny new box (time is money - why spend hours tweaking Windows 7 to use an old SF version when the new one installs in 2 minutes??). In this version, the executables are split from the user data and library files, with the executables in C:/Program Files (x86)/Mecanique/Swordfish and the user files in the linked directory Libraries/Documetns/Swordfish, with the actual path being C:/Users/Tom/Documents/Swordfish.

73's,

de Tom

Post Reply