PDA

View Full Version : SEROUT on a 16F1947



Rayneobid
- 3rd February 2016, 19:07
Hello,
I hope someone can help me with a basic problem.
Using a 16F1947 and trying to get SEROUT to work.

This started as a product board upgrade from a 16F77 to a 16F1947
All else works, but I dont get any serial data out on the new chip.


So, I stripped down the code to simplify the problem.
Here is my code:

Include "modedefs.bas"
ANSELF = 0
Pattern var byte
Pattern = 0

SO var PortF.2

Start:
High SO
Pause 10
Low SO
Pause 10

Pattern = Pattern + 1
Serout SO,4,[Pattern]
Goto Start

It toggles the pin on for 10 mS then off for about 14mS.
There is no data output ever (using a o-scope, not a pc to look at it)
If I comment out the Serout line, I get 10 mS on and 10 mS off so the serout command is doing something for 4 ms.
I dont need the High or Low commands, but put them in to see if the pin was working ok.
If I comment out the High and Low commands I get no output at all.

I've tried using PortF.2 in place of SO, same result.
Tried using different pins, but no data out.
Tried not using a variable, like SEROUT PortF.2,4,["Data"] same result.
Tried different data rates, same result.
Tried SEROUT2, same results.

Using a 4.00 MHz resonator

I would think the A/D and such are set to digital ok because the High and Low work correctly.

Does a 16F1947 not work with SEROUT commands?

Thanks for looking!

Archangel
- 4th February 2016, 04:40
I would think the A/D and such are set to digital ok because the High and Low work correctly.

High & Low do all the analog vs Digital manipulation for you, I suspect you are
having an analog (default state) issue.
Take sure any comparators are off on that port pin . . . I have never seen serout used the way you are trying to use it, try sending some text.

richard
- 4th February 2016, 05:08
I would start here

http://support.melabs.com/content/562-PBP-2.60-and-later-PBP-commands-on-PORTF-and-PORTG-of-16F1946-1947

Published on 12-04-2013 10:03 AM

With PBP 2.60 and later (up to 3.0.7.x), PBP commands that automatically set the TRIS bits will not work properly on PORTF or PORTG of the 16F1946/1947.

An issue with bank selection for the TRIS register has been identified.

Hopefully, this will be corrected by version 3.0.8.x
2.60(A,B,C) will continue to have this issue.

There are no workarounds.

Rayneobid
- 4th February 2016, 13:47
Thanks for looking at it!
I've tried a few more things, ending with:

Include "modedefs.bas"

ANSELF = 0 'Set PortF to digital
TRISF = 0 'PortF = outputs
ADCON0 = 0 'Turn off A/D

Low PortF.1

Start:
Toggle PortF.1
Pause 10
Serout PortF.2,4,["data"]
Goto Start

There is no serial data coming out of PortF.2, but PortF.1 toggles about every 26mS.

When it says there is no work around, does that mean I cant set them manually and there is no way to make it work?

Or, am I still missing a setup for the A/D or something?

Thanks!

Rayneobid
- 4th February 2016, 15:23
Ok, I have it working.
Thank you for pointing me in the right direction about the compiler not working well with the 1947 chip yet.

Here is what I did to make it work:
(I only need to send one byte at a time at 2400 baud, so it works ok for now)

Include "modedefs.bas"

ANSELF = 0
TrisF = 0

SO var PortF.2
Pattern var byte

Start:

Pause 200
Pattern = Pattern + 1
Gosub SendSerial ' Serout PortF.2,4,[Pattern]
Goto Start

SendSerial:
High SO
PauseUs 416

If Pattern.0 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

If Pattern.1 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

If Pattern.2 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

If Pattern.3 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

If Pattern.4 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

If Pattern.5 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

If Pattern.6 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

If Pattern.7 = 1 then
High SO
PauseUS 410
Else
Low SO
PauseUS 410
Endif

Low SO
PauseUS 416

Return