PDA

View Full Version : Problem with multiple interrupts



aratti
- 31st May 2009, 11:51
Dear friends, I am trying to make two pic16F88 to serially communicate between them.

Pic_A Pic_B

portB.6 (Tx) >-------------------------> portB.7 (Rx)

portB.7(Rx) <-------------------------< portB.6(Tx)


To be sure to have a reliable communication, I am using DT int on portB.0 to activate serial transmission as per the code below.


INCLUDE "Modedefs.bas"
INCLUDE "DT_INTS-14_3.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

ANSEL = 0
CMCON = 7
OPTION_REG.6 = 1

TrisA = %00010000
TrisB = %10000101
PortA = 0

DEFINE OSC 8

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 12 ' 9600 Baud @ 8MHz, 0,16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically


SCall var PortB.3

PwrL var PortA.0
PwrM var PortA.1

Led var PortA.2
Buz var PortA.3

STx var PortB.6
SRx var PortB.7

ZCrox var PortA.4
X10Tx var PortB.1
TxEnable var PortB.4

low TxEnable
low SCall
input SRx
high STx

A0 var Byte
DataFlag var byte
House var byte
Unit var Byte
Job var Byte

Rdata var Byte[30]

Flag0 var dataflag.0
Flag1 var DataFlag.1 ' Hserin interrupt channel
Flag2 var dataFlag.2 ' PortB.0 interrupt channel
Flag3 var DataFlag.3
Flag7 var dataFlag.7


'-------------------- Rx & PB0 DT interrupt definition -----------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _Getbytes, PBP, yes
INT_Handler INT_INT, _DataReady, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RX_INT ; enable RX_INT interrupts

'----------------------------------------------------------------------

gosub Buzzer
low led
A0=0
DataFlag=0

pause 500
hserout ["System Ready",10,13]

Main:

pause 1

IF Rdata[0] = 36 and Flag0 = 1 then

High led

If Rdata[1] = 49 then
House = ((Rdata[4]-48)*10) + (Rdata[5]-49) ' X10 house value
Unit = ((Rdata[6]-48)*10) + (Rdata[7]-49) ' X10 Unit value

Flag7 = 0
If Rdata[8] = 49 then Job = 18 : Flag7 = 1
If Rdata[8] = 50 then Job = 26 : Flag7 = 1
If Rdata[8] = 98 then Job = 20: Flag7 = 1
If Rdata[8] = 99 then Job = 28: Flag7 = 1
if Flag7 = 0 Then Skip00

High TxEnable ' enable X10 transmission
pause 1 ' delay before X10 Tx
Xout X10Tx,Zcrox,[House\Unit,House\Job] ' X10 transmission
low TxEnable ' disable X10 Transmission

goto Skip00
Endif

If Rdata[1] = 52 then ' intra system comand

If Rdata[8] = 250 then gosub Power01
If Rdata[8] = 240 then gosub Power02
If Rdata[8] = 230 then gosub Modem01
If Rdata[8] = 220 then gosub Modem02

goto Skip00
endif

If Rdata[1] = 51 then ' intra system communication
High Scall
Pause 10
serout2 STx,84,5,[str Rdata\30]
Low Scall

goto Skip00
endif

IF Rdata[1] = 57 and Flag2 = 1 then ' send out via wifi string recived
hserout [str Rdata\30]
endif

Skip00: ' reset main pointers & flag

Rdata[0] = 0
Rdata[1] = 0
Rdata[2] = 0
Rdata[8] = 0
Flag0 = 0
Flag1 = 0
Flag2 = 0
A0=0

gosub buzzer
Low led
endif

goto Main


Getbytes: ' Rx interrupt data from Xbee module
hserin 100, Nodata, [Str Rdata\9]
Flag0 = 1
@ INT_RETURN

Nodata:
Flag0 = 0
Flag1 = 1
@ INT_RETURN

DataReady: ' Intracom interrupt data from chip
hserout ["PB0 Interrupt"] ' this message never show up
Flag0 = 0
Flag1 = 0
Flag2 = 0
serin2 STx,84,500,JumpOut,[str Rdata\30]
Flag2 = 1
Flag0 = 1
Loop:
if PortB.0 = 1 then Loop
@ INT_RETURN

JumpOut:
Flag0 = 0
Flag1 = 0
Flag2 = 0
Flag3 = 1
@ INT_RETURN

Power01:
hserout ["PowerLine Off",10,13]
pause 1
low PwrL
return

Power02:
hserout ["PowerLine On",10,13]
pause 1
high PwrL
return

Modem01:
hserout ["Modem Off",10,13]
pause 1
low PwrM
return

Modem02:
hserout ["Modem On",10,13]
pause 1
high PwrM
return

Buzzer:
high buz
pause 20
low buz
return



The Rx interrupt works fine, while the portB.0 interrupt doesn't work at all, so I am anable to get data transfer between the two pics.

There must be something wrong but I am anable to find it! Any help will be greatly appreciated.

Al.

Darrel Taylor
- 31st May 2009, 15:18
Probably just need to ...
@ INT_ENABLE INT_INT

aratti
- 31st May 2009, 18:40
Yes Darell that was the missing part! Thank you very much indeed for the help.

Al.

Ioannis
- 1st June 2009, 17:53
Sniff sniff,I smell something interesting here.

If I may ask, what are you cooking? Wifi was the trigger to be curious!

Ioannis

aratti
- 1st June 2009, 18:40
Ioannis , The project is called "Home Automation to the maximum possible extent" naturally I am doing it in my house, and as you can imagine from the title, the project is in continuos evolution.

At present, I have almost all the appliances; lamps and blinders controlled via X10, plus 16 digital inputs to control various sensors, and 16 digital outputs to control non X10 devices.

So far, I can control and monitor my house in several ways (PC; SMS; Timers and local keypads), I am working to be able to do it also via web.

Al.

Ioannis
- 2nd June 2009, 07:15
Nice Al.

Most control are trivial I believe although some care is needed in the design. Web is the most impressive one.

Good luck in the project.

I am also doing something similar with Zigbee devices for local communication and am looking for the web thing later (now our 3rd kid is coming, so...)

Ioannis

aratti
- 2nd June 2009, 08:02
(now our 3rd kid is coming, so...)

These are really great projects! congratulation Ioannis

Al.

Ioannis
- 2nd June 2009, 08:18
Oh, thanks. Yes they are indeed!

Well, I am leaving now fr the deliver!

Ioannis