PDA

View Full Version : PIC to PIC communication and interrupts



lwindridge
- 17th June 2004, 08:18
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

Dwayne
- 17th June 2004, 14:40
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

lwindridge
- 17th June 2004, 23:26
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

Dwayne
- 18th June 2004, 15:30
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

Dwayne
- 22nd June 2004, 05:59
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