PIC to PIC communication and interrupts


Closed Thread
Results 1 to 5 of 5
  1. #1
    lwindridge's Avatar
    lwindridge Guest

    Question PIC to PIC communication and interrupts

    Hi,

    I wonder if anyone else has come across this and could offer a bit of advice?

    I'm trying to get two PIC's talking to each other, which I have managed to do using serout on the master and serin on the slave.

    However on the slave PIC I have an incoming pulse which triggers an asm interrupt to clone the pulse (after small modification of width and timing, based on the data received using the serin command) and output it on another pin.

    What I appear to have a problem with though is the interrupt interferes with the serial input and seems to knock it totally off timing.

    Does anyone have any other suggestions for reading the data from the master PIC which is a little more interrupt friendly (I've tried using shiftin and shiftout but with little success)?

    Just for reference the master PIC is a 16F877@20Mhz and the slave is a 16F84A@20Mhz (but could be another 16F877 if it would suit it better).

    Thanks

    Leigh

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


    Did you find this post helpful? Yes | No

    Default

    Hello Iwindridge,

    IWR>>What I appear to have a problem with though is the interrupt interferes with the serial input and seems to knock it totally off timing.

    Does anyone have any other suggestions for reading the data from the master PIC which is a little more interrupt friendly (I've tried using shiftin and shiftout but with little success)?<<

    Make sure you turn off your interupt when you branch to your routine.. with disable command., or you will interupt again.


    Can you post some barebone code for us to look at?


    Also, I while back, I posted some code for 2 pin and 1 pin communication between two chips. Granted, it is not using PBP SERin or other commands of commuication, it you want me to, I will look up the code for you.

    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
    lwindridge's Avatar
    lwindridge Guest


    Did you find this post helpful? Yes | No

    Default

    Would love to see your two wire solution Dwayne - would possibly make life much easier as I have another two PIC's that are going to have to do a similar job pretty soon using the same master.

    What actually seems to happen is the 16F877 sends out the serial data fine (checked it with PC) but the receiving PIC (the 16F84A) just seems to sit there waiting for the start command to come through. I'm guessing that the interrupt (firing once every 300uS or faster) is stopping it from receiving properly. But I'm still a bit green on these things so I'm not too sure of the best way to get around it.

    I've attached my current code for you to have a look at - let me know if you can see anything glaringly obvious
    The 16F877 send command is...

    serout2 dta1,6,["S",#totalret,#rpmsamph]
    (dta1 is portb.1, totalret and rpmsamph are calculated 16 bit numbers)

    Hope that helps explain a little better anyway.

    Cheers

    Leigh
    Attached Files Attached Files
    Last edited by lwindridge; - 18th June 2004 at 07:46.

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


    Did you find this post helpful? Yes | No

    Default

    It has blinky lights to give you a idea what is happening on the chips...as well as if they are ready to send/Receive.. Thus, the lights can be removed.

    Recieve part.........
    TRISa=%00110000
    TRISb=%00000000
    Counter var byte
    Counter2 var byte
    Result var byte

    Pause 500
    Porta.0=0
    Porta.7=0
    Portb=13 'clear lcd
    Porta.0=1
    Pause 1
    Porta.0=0

    'Flashes LED
    Porta.1=1
    Pause 1000
    Porta.1=0
    Counter=0

    Loop3
    Counter2=0
    Result=0
    Loop2:

    if Porta.4=0 then Loop2
    Result.0=Porta.5
    Result=Result << 1
    kt:
    if porta.4=1 then kt
    Counter2=Counter2+1
    if Counter2 < 4 then Loop2
    Result=Result+48
    Counter2=0

    Porta.7=1
    Portb=Result
    Porta.0=1
    Porta.0=0

    Counter=Counter+1
    if Counter=16 then
    Porta.7=0
    Portb=1 'clear lcd
    Porta.0=1
    Pause 1
    Porta.0=0
    Counter=0
    endif
    Pause 3
    goto Loop3
    end


    Tranmit part...........

    ANSEL=%00111000
    CMCON=%00010111
    TRISIO=%00011100
    ADCON0=%00001100
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50

    counter var byte
    counter2 var byte
    Digloop var byte
    Dignum var byte
    Number var word
    Number=1234

    Loop:
    GPIO.5=1
    Pause 300
    GPIO.5=0
    Pause 300
    if GPIO.2=0 then Loop
    GPIO.0=0

    ADCIN 3, number
    number = number >> 6




    For counter = 3 to 0 step -1
    DigNum=number dig counter


    for counter2= 1 to 4 step 1
    GPIO.1=DigNum.3
    GPIO.0=1
    Pauseus 50
    GPIO.0=0
    Pauseus 500
    DigNum = DigNum << 1
    next counter2
    Pause 10
    Next counter

    Goto Loop

    End
    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...

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


    Did you find this post helpful? Yes | No

    Default

    Hello...

    I took a quick look at your code...Did not do any compilation, but I wonder about a couple of things.

    1. I did not see where you turned off the interupt handler as soon as you entered it.

    2. If I remember correctly, PBP will "finish" its last command before calling a interupt. This also may give you the "out of sequence timing.


    Now...the other stuff <g>. I am note really familiar with PBP ASM code, or PBP. I am learning it myself. I used to program Philip chips in assembly, and that was a few years back. Thus, I can be in error here ok?

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

Similar Threads

  1. Hserin with Instant Interrupts.
    By ronjodu in forum Serial
    Replies: 17
    Last Post: - 30th December 2014, 20:17
  2. Continuous Interrupts when using DT_INTS and an INCLUDE file
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 15th January 2010, 21:42
  3. Wireless serial communication question
    By Ahmadabuomar in forum Serial
    Replies: 3
    Last Post: - 21st December 2009, 03:49
  4. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  5. serial communication pic16f628 - gsm
    By mariani in forum General
    Replies: 0
    Last Post: - 22nd February 2006, 13:31

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