Whats going on? serial comm


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Question Whats going on? serial comm

    Hi,

    I am having trouble with communication between 2 pics. All I am trying to do is send one word from one pic to another I have a cs and data line and the following code.

    Transmitter:

    high cs
    pause 50
    serout serialpin, T1200, [value]
    low cs

    Receiver:

    datain:
    serin serialpin, T1200, [value]
    return

    start:
    IF cs = 1 then gosub datain
    IF weld = 0 then start

    I just cant get it to work. I have tried [#value], serout2 with [dec value], well have tried everything I can think of, but no luck. Help please. I have read all the posts I can find on serial comms, but I still cant see what im doing wrong.

    Regards

    Bob...

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Bob,

    Clink on this link:
    http://www.picbasic.co.uk/forum/showthread.php?t=579


    before you do anything, you must break down your project in very simple steps... Your program shows nothing on using TRISIO switchings, making the chip pins I/O's Let alone turning off comparators and A/D's.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    must be few things...
    1. Wich PIC are you using?
    2. wich PIC pin are you using?
    3. are they multiplexed with analog stufff???
    4. if so did you disable them prior to use them?
    5. Is your datain is before of after the main loop?
    6. If before did you place a Jumpstart Goto to jump over your SERIN?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    darkman's Avatar
    darkman Guest


    Did you find this post helpful? Yes | No

    Default

    this my working serial com project : ( I'm test it )

    transmitter :

    @ device XT_osc
    INCLUDE "modedefs.bas"
    baslangicdatasi var byte
    TRISB=%01000000
    PORTB=0
    baslangicdatasi=65

    gonder:
    PAUSE 1000
    SEROUT PORTB.7,N2400,["protocol",baslangicdatasi] ' SEND BEFORE "protocol" AFTER SEND baslangicdatasi

    son:
    END


    receiver :

    INCLUDE "modedefs.bas"

    TRISA=%00000000
    TRISB=%00000011
    B0 var byte
    B1 var byte
    B3 var byte
    B0=0
    PORTA=0
    B3=2
    LOW PORTB.3
    LOW PORTA.2
    HIGH PORTA.0
    start:
    B0=0
    ' IF PORTB.0=0 THEN bekle
    ' GOTO start

    bekle:
    SERIN PORTB.1, N2400, ["protocol"],B0 ' wait "protocol" after write receive baslangicdatasi and insert in B0

    IF B0=65 then kontrol
    GOTO bekle

    kontrol:
    IF B3=2 then ac
    IF B3=1 then kapat
    GOTO kontrol

  5. #5
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Angry

    Well thanks for the replies, but still no luck. This should be the easiest bit of the project. Isnt it always the way.

    I have included the code. Display is the transmitter, and fback3 is the receiver. The programs control a welder, display is supposed to tell the feedback chip the desired welding current. I can see the serial input to the pic on the scope but still no output mirrored on the test pin. I have also tested the pins as digital in and out, so i know there is no damage to the chips. I have also written code just to test the comms part with but no difference

    By the way in the display file is a routine to drive a 4 digit 7 seg led display, with blanking of leading zeros. Quite proud of that little routine.

    Thanks again for the help. Hope we can sort it out soon, the boss is back on tuesday :-( lol...

    Regards
    Bob
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Bob,

    Instead of wading through the code, can you write *just* the code to send the data?

    When you do so, make sure the sending pin is a I/O pin.
    Make sure you assign it with the TRIS register as a Output
    Make sure you You turn off all ADC's and Comparators.

    If you cannot scope the output on this pin of any data (like the decimal number 1), you are wasting your time with all the other stuff.

    When you get a scoped decimal one, then work on the reciever side.

    When the above is finished, insert it in your code where it belongs.

    MisterE made some EXTREMELY good points... Do not ignore them!


    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  7. #7
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    I have scoped the output of the transmitter, no problem with that. To test the circuit I have a PIC16F877A transmitting:

    pause 500 'make sure receiver has time to boot
    let value = 1
    loop:
    serout portb.7, 1, [value]
    pause 100
    goto loop

    and a PIC 16F870 receiver:

    loop:
    serin portb.7, 1, [value] 'get input
    high led
    serout portb.0, 1, [value] 'send to pin to compare waves
    low led
    goto loop

    The led never flashes so its just sat waiting for input which it never sees, though the scope sees a nice clean signal on the input pin.

    I have noted all the points Mr E mentioned. I have tried it on lots of pic types, and various pins, I have included "modedefs.bas", I have a 10k resistor from TX pin to gnd, no comparators to worry about.

    I am going to try disabling the A/D before receiving data, but cant see this making a difference, since I'm using port B

    regards

    Bob...

  8. #8
    darkman's Avatar
    darkman Guest


    Did you find this post helpful? Yes | No

    Default

    and a PIC 16F870 receiver:

    loop:
    serin portb.7, 1, [value] 'get input
    high led
    serout portb.0, 1, [value] 'send to pin to compare waves
    'add here PAUSE
    low led
    'add here PAUSE
    goto loop


    and try this software for rs 232 commination capture with pc :

    http://www.rs232pro.com
    Last edited by darkman; - 27th May 2005 at 17:15.

  9. #9
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Bob,


    Bob>>loop:
    serin portb.7, 1, [value] 'get input
    high led
    serout portb.0, 1, [value] 'send to pin to compare waves
    low led
    goto loop

    The led never flashes so its just sat waiting for input which it never sees, though the scope sees a nice clean signal on the input pin.
    <<

    Ok, One thing I see, is that it will only take a very SMALL amount of time to send the data to the output, Thus your LED may be flashing, but too fast.

    Can you scope the POrtb.0? and see the data being transmitted? Do not rely on just 1 LED flashing. (which seems you are doing here). It will flash way too fast, and probably look as if it is not flashing at all.

    Since you have scoped the transmitter, and have verified it, then the reciever should be almost the same...Try scoping the PORTB.0, and making sure you have data coming out. If not, it is in your receiver... Then I would suggest slowing down your baud rate to 300.

    Dwayne

    Bob>>I am going to try disabling the A/D before receiving data, but cant see this making a difference, since I'm using port B <<

    Will not make any difference if they are not present on POrtb. PortA ususally has all the AD and comparators...

    Make sure your TRISB has the proper pins as I/O... according to your example

    your input is PORTB.7 and output is PORTB.0

    Thus I would (for safety sake)
    Portb=%10000000

    This assigns POrtb.7 as a input, and all others as outputs.

    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  10. #10
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Smile

    First of all thanks to everyone who replied to my posts. I have now cured the problem

    serout serpin, 0, ["A",#VALUE,"AA"]
    and
    serin serpin, 0, ["A"],#VALUE
    worked just fine.

    Kind regards

    Bob Edge...

Similar Threads

  1. Serial comm between two PICs
    By ALFRED in forum Serial
    Replies: 24
    Last Post: - 13th March 2014, 23:22
  2. Idea of master/slave serial comm.
    By sirvo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th December 2007, 08:36
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 02:21
  4. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 10:36
  5. serial comm from Pic to STAMP
    By d1camero in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th April 2004, 23:58

Members who have read this thread : 0

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