PDA

View Full Version : SEROUT2/SERIN2 Problem



thirsty
- 10th September 2007, 05:48
Hi All,

I'm hoping someone can shed some light on a problem I'm having.

I have 2 projects (one PIC18F4525 based and one PIC16F913 based). I have connected the two projects together via port b.3 on the 16F and port e.2 on the 18F. I have a 10K pullup res on this line. I've disabled the AD on the 18F and made porte digital IO.

Here is the serial out code on the 16F:

serout2 so, T2400,["INIT", "1111", "2222", "333", "444"]

and here is the serial in code on the 18F:

Serin2 Si,T2400,[WAIT ("INIT"), str RHET \4, str LHET \4, str RHspd \3, str LHspd \3]

The variables are defined as byte arrays with dimensions of 4,4,3 and 3 respectively.

Now the problem is the code will not go past the "wait" in the serin2 line on the 18F. I've measured the input to the 18F's e.2 pin and there is activity on that pin as expected.

I assume I've not set a config bit somewhere but I've read through the datasheet many times and I can't see what I'm missing.

Any ideas?

The 18F is working as it displays data on some LED's so I know everything is OK there.

I'd appreciate it if anyone can shed some light,

Thanks

Thirsty

BrianT
- 10th September 2007, 05:54
I think you will find T2400 only works/receives if you have a MAX-232 chip.

Try N2400 and at the start of the sending, condition the line with

HIGH SO
pause 5
serout2 ............

HTH
Brian

BrianT
- 10th September 2007, 06:00
Disregard the post above - it is right for SEROUT however.

I think you have mixed up the command syntax for your SEROUT2. I think your command line should be something like...

serout2 So, 396,["INIT", "1111", "2222", "333", "444"]

HTH
Brian

thirsty
- 10th September 2007, 06:51
Thanks Brian,

The T2400 is a constant from modedefs.bas that I've included in my program (though I have tried using 396 and various other modes as well).

I've had easy success using this type of comms before between a pair of 16F's (a serial LCD module for example) but the 18F doesn't seem to like it so I guess I've done something wrong in my code.

Is there anything tricky about using porte for serial comms?

The only other thing that might have an effect is I'm running the projects at different speeds but I've used defines in both to tell PBP the clock speed.

Regards

Thirsty

Bruce
- 10th September 2007, 17:17
Brian is spot-on about using 396 VS T2400 with SERIN2/SEROUT2. The constant serial mode
definitions in MODEDEFS.BAS like T2400 are for use with SERIN/SEROUT only.

PORTE on this PIC has A/D. Have you disabled A/D so these pins can be used for digital I/O?

thirsty
- 10th September 2007, 23:11
Thanks Bruce.

I tried 396 (and a bunch of other modes) but no joy.

I have disabled the A/D and set porte to all digital IO.

I've read on this site that using an internal osc is a bad idea for asynch comms and I am using an internal osc on the 18F so I guess that could be the problem.

I guess I'll have to give this idea a miss and try synch comms using shiftin/out and write my own slave routine for the 18F.

Thanks for the replies anyway,

Regards

Thirsty

Darrel Taylor
- 11th September 2007, 00:25
If you can't get SERIN2 to work, I'd skip the idea of writing your own Synchronous Slave routine.

You keep saying that you've set all ports to digital.
How did you do that? What statements did you use?
The method of turning off analog ports varies from PIC to PIC.
Are you sure you got the right ones?

Did you set TRISE.
If so what did you set it to?
I've seen people go TRISE=%11111111, thinking that they are setting PORTE to all input, but what it really does is turn on the PSP module, which along with other problems, disables PORTE.2 for general I/O.

Don't dismissed 396 as being correct, simply because you've tried it and it didn't work. 396 is the correct mode number, not T2400.
<br>

thirsty
- 11th September 2007, 00:35
Darrel, point taken.

Here is how I've set the configs (18F4525):

DEFINE OSC 8


OSCCON = %01110010
CMCON = %00000111
ADCON0 = %00000000 'Turn off A/D
ADCON1 = %00001111 'Make All ports Digital IO
TRISA = %00000000 'PortA is all outputs
TRISB = %00000000 'PortB is all outputs
TRISC = %00000000 'PortC is all outputs
TRISD = %00000000 'PortD is all outputs
TRISE = %00000110 'PortE.0 is output, 1 and 2 are inputs

As I've said though it seems lots of experienced guys on this forum advise not to use asynch comms when relying on an internal clock that's why I made my last comment.

Any further observations would be appreciated though,

Thirsty

Darrel Taylor
- 11th September 2007, 01:55
As I've said though it seems lots of experienced guys on this forum advise not to use asynch comms when relying on an internal clock that's why I made my last comment.

On a lot of the older chips with internal oscillators that is a valid statement. And I guess you could say that even on the new ones, when you consider the full temperature range, it's still a valid statement.

But, when you're sitting in a room at somewhere close to 25°C, the internal oscillator of the 18F4525 will be within +/- 1%, which should be fine for asynchronous comms. So it doesn't really account for you're problem.

Your register settings look good.

Are you using any @ __CONFIG lines? Or just the defaults for PBP with a 4525?
<br>

mackrackit
- 11th September 2007, 02:03
Try re-writing with out the str , something like
from the manual


SERIN2 1,16780,[WAIT(“A”),B0]

Or better yet just send/receive a simple 5 and blink an LED to test the connection,

I think the problem is in the way you are trying to receive the data. Take another look at SERIN2 in the manual, WAITSTR might be the answer.

thirsty
- 11th September 2007, 03:09
Thanks guys.

Darrel: I hadn't used any other config directives.

The problem is that this setup will be used in an environment other than my office so it has to be reliable. I've decided to go the synch route and have gotten it working reasonably now.

I've definately learned a lesson here though so it wasn't all a waste.

I appreciate your help

Regards

Thirsty

Darrel Taylor
- 11th September 2007, 03:13
WOW!

You've written Synchronous Slave routines in 4 hrs (or less).
I'm impressed, although skeptical.
<br>

thirsty
- 11th September 2007, 05:56
I didn't say I wrote it - I said I had it working. I found some sample code and used that as a basis.

Sarcasm really is the lowest form of wit don't you think?