SEROUT2/SERIN2 Problem


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Jun 2006
    Posts
    12

    Default SEROUT2/SERIN2 Problem

    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

  2. #2


    Did you find this post helpful? Yes | No

    Default T2400 needs a MAX232 RS232 driver

    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

  3. #3


    Did you find this post helpful? Yes | No

    Default I think you have mixed SEROUT and SEROUT2

    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

  4. #4
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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>
    DT

  8. #8
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    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

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by thirsty View Post
    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>
    DT

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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.
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    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

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    WOW!

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

  13. #13
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    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?

Similar Threads

  1. Problem with ASM IRQ using FSR0 on PIC18F252
    By mytekcontrols in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th March 2008, 20:48
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  4. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59
  5. weird 12F629/675 problem
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th October 2004, 01:08

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts