PDA

View Full Version : Pic to pic interrupt ans serial comm



ronjodu
- 10th May 2008, 14:33
I have two pics I'd like to send a few bytes between at varying times. Pic1 (18f2525 @ 20 mhz) and Pic2 (16f876 @ 4 mhz). Darrel Taylor's instant interrupts in use! Thanks again Darrel.

My thought is to send a pulse to RB0 INT/INT of the receiving pic to let it know something is coming and after a short pause, ISR will receive the bytes on RB0, 6 bytes max always in the same order, and go back to what it was doing. Both pics would be set up the same way. Poor planning and lack of forward thinking finds RC6 and RC7 on both pics used up already.

Question #1. can I change the operation of RB0 on the fly within the ISR to receive the bytes and then change back and return from the interrupt?

Question #2. How should I be generating the pulse for the interrupt trigger? Pulseout or toggle the pin with a pauseus?

I've read many threads about Pic to Pic comm but my brain keeps circling around this option.

Question #3. Is this feasible or should I go back and reread those other threads?


As always thanks for any suggestions.

Darrel Taylor
- 10th May 2008, 20:03
No problem.

Just use DEBUG, SERIN or SERIN2 inside the (PBP type) INT_INT handler.
You don't have to "change the operation of RB0" because once it's in the handler it can no longer cause another interrupt.

The interrupt trigger is very fast (1 instruction cycle minimum) at 4mhz that's 1 us. But it will take about 50 instruction cycles to get to a PBP type handler, more if using PBPL.

TX side:
HIGH OutPin
@ nop ; add nop's if sending pic is 20mhz
@ nop
@ nop
@ nop
LOW OutPin
PAUSEUS 60 ; 60 if receiving PIC is 4mhz, 15 if 20mhz
SEROUT2 ...

tenaja
- 10th May 2008, 20:38
... Poor planning and lack of forward thinking finds RC6 and RC7 on both pics used up already....
As always thanks for any suggestions.
Depending on how many boards you have in hand, it might be faster to just cut the two traces going to C6-7, and run some jumpers. That will allow you to use the h/w usart, giving you a "received" interrupt, rather than a "begin receive" interrupt... this will be most useful if you are working with time sensitive stuff. Then, for your next board run (if it that is a possibility), you won't have to edit the code. The importance of that is even greater when you are updating firmware in old boards--you won't have to have two versions.

ronjodu
- 10th May 2008, 22:43
Thanks for the replies. Will certainly try this out tonight.

If I ever do another board for this I would combine everything into one pic and this wouldn't be a problem. For now though it's my web enabled relay board and my PGA2320 volume control board I'm Ruth Goldburg'n together for use in my amp. Most functions work well already just need both pics to be on the same page with a few variables.

It seems I've done more prototyping with this relay board than my Easypic4 and LabX2 combined.

More questions to follow I'm sure. Thanks again.