PDA

View Full Version : DT_Interupts with 18F2525



Mike2545
- 11th January 2016, 03:03
Been trying to get RX_INT to work with 18F2525, I can get it with 18F1320 but I seem to be missing something. Any help would be great...
Here is what I have



INCLUDE "modedefs.bas"
Include "ALLDIGITAL.pbp"
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
OSCCON =$60 'clock speed
DEFINE OSC 4

DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 24h 'Hser transmit status init
DEFINE HSER_BAUD 9600 'Hser baud rate
Define HSER_SPBRG 25
Define HSER_CLROERR 1
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _read_serial, PBP, yes


endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE RX_INT ; enable external (RX) interrupts



The Fuses are set as:
__CONFIG _CONFIG1H, _OSC_INTIO67_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & 0bfh ;_XINST_OFF_4L


Thanks in advance

HenrikOlsson
- 11th January 2016, 06:16
Hi,

Have you verified that the PIC is running at the desired (4MHz) speed? OSCCON=$60 doesn't look quite right to me.
Have you checked that the serial connection works and that you can recieve data in a non interrupt driven way, ie by using HSERIN for example?

Not sure if it's related or nor but generaly you don't want DT-Ints to reset the interrupt flag because it gets reset automatically by the hardware when the RCREG is read.

/Henrik.

Mike2545
- 11th January 2016, 13:42
Hi Henrik,

The Pic is running at 4 MHz with internal xtal. I can receive serial with SERIN2, will try HSERIN.
The ASM interrupt will not trip and go to label Read_serial:
At work at the moment; Will confirm that I have TX and RX on the right pins when I get home and keep you updated :)

HenrikOlsson
- 11th January 2016, 14:10
The Pic is running at 4 MHz with internal xtal.
Have you actually verified that? The fact that SERIN2 works indicates that you have and it is but I must ask again because as far as I can see (looking at this datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf) setting OSCCON=$60 selects 1MHz and you don't have the PLL enabled (which only works when 4 or 8MHz is selected anyway) - if I read the datasheet correct of course.

Then you say that the ASM interrupt won't trip, but you have the type set to PBP (and you don't show the handler).

Anyway, make sure you can recieve using HSERIN, when that works properly go back to the interrupt driven stuff.

EDIT: By the way, setting the baudrate and other settings using DEFINEs doesn't seem to actually do anything until you include a HSEROUT/HSERIN statement in the code. Instead of doing the DEFINE method try setting the registers directly and see if that makes any difference.

/Henrik.

Charlie
- 11th January 2016, 14:43
The problem might also be in your interrupt handler, or several other places. You should post all the code.

amgen
- 11th January 2016, 19:29
could also check the serial data polarity coming to pic..... may need inverted

Mike2545
- 12th January 2016, 01:19
Well...it was swapped pins on the x-bee module header. It was my mistake for grabbing one already soldered up and not checking the pin-out.
Thanks for all the suggestions, here is the code


'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : Mike Mummert *
'* Notice : Copyright (c) 2016 All Rights Reserved *
'* : All Rights Reserved *
'* Date : 1/9/2016 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
INCLUDE "modedefs.bas"
include "ALLDIGITAL.pbp"
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
OSCCON =$60 'clock speed
DEFINE OSC 4
Define PULSIN_MAX 1000
DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 24h 'Hser transmit status init
DEFINE HSER_BAUD 9600 'Hser baud rate
define HSER_SPBRG 25
Define HSER_CLROERR 1
INTCON = %11000000
TRISC = %10000000
ADCON1 = %00001111

' DEFINE DEBUG_REG PORTB
'DEFINE DEBUG_BIT 3

' DEFINE DEBUG_BAUD 9600
'DEFINE DEBUG_MODE 1
DQ VAR PortA.1 ' 1-Wire buss pin
tX var PortC.6
rX var PortC.7
Baud CON 84 ' 9600 baud, non-inverted
RdROM CON $33 ' read serial number
MatchROM CON $55 ' match SN -- for multiple devices
SkipROM CON $CC ' ignore SN -- use for one device
CvrtTmp CON $44 ' start temperature conversion
RdSP CON $BE ' read DS1822 scratch pad
tempIn VAR Word ' raw temperature
sign VAR tempIn.BIT11 ' 1 = negative temperature
tLo VAR tempIn.BYTE0
tHi VAR tempIn.BYTE1
tSign VAR Bit ' saved sign bit
tempC VAR Word ' final Celsius temp
tempF VAR Word ' final Fahrenheit temp
Panel VAR Word
Tank VAR Word
Nb_var21 var byte
Nb_var22 var byte
Nb_varH23 var byte
Nb_varM23 var byte
Nb_var24 var byte
Nb_varH27 var byte
Nb_varM27 var byte
Nb_var28 var byte
Nb_varH59 var byte
Nb_varM59 var byte
Nb_var60 var byte
Nb_var31 var byte
Nb_var32 var byte
Nb_varH33 var byte
Nb_varM33 var byte
Nb_var34 var byte
Nb_varH37 var byte
Nb_varM37 var byte
Nb_var38 var byte
Nb_varH63 var byte
Nb_varM63 var byte
Nb_var64 var byte
Nb_var41 var byte
Nb_var42 var byte
Nb_varH43 var byte
Nb_varM43 var byte
Nb_var44 var byte
Nb_varH47 var byte
Nb_varM47 var byte
Nb_var48 var byte
Nb_varH67 var byte
Nb_varM67 var byte
Nb_var68 var byte
hour var byte
Minute var byte
day var byte


ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _read_serial, PBP, yes

endm
INT_CREATE ; Creates the interrupt processor

ENDASM
T0CON = %10010010
@ INT_ENABLE RX_INT ; enable external (RX) interrupts


Main:

serout2 PortB.4,16468,[1,"DS1822 ", CR,"------", CR,SDEC Panel, " Panel ", CR,SDEC Tank, " Tank ",cr, dec Nb_var21, " DR temp "] ' display



Get_Temperature:


OWOUT DQ, 1, [ MatchRom,$28,$D4,$04,$60,$07,$00,$00,$F3] 'Match serial number to your device
OWOUT DQ, 0, [ CvrtTmp] ' send convert temperature command
DO ' wait on conversion
PAUSE 25 ' small loop pad
OWIN DQ, 4, [tempIn] ' check status (bit transfer)
LOOP UNTIL (tempIn)
OWOUT DQ, 1, [ MatchRom,$28,$D4,$04,$60,$07,$00,$00,$F3]

OWOUT DQ, 0, [ RdSP] ' read DS1822 scratch pad
OWIN DQ, 2, [tLo, tHi] ' get raw temp data
tSign = sign ' save sign bit
tempC = tempIn >> 4 ' round to whole degrees
tempC.BYTE1 = $FF * tSign ' correct twos complement bits
tempF = (ABS tempC) * 9 / 5 ' start F conversion
IF (tSign) THEN ' finish F conversion
tempF = 32 - tempF ' C was negative
ELSE
tempF = tempF + 32 ' C was positive
ENDIF
Panel = tempF

OWOUT DQ, 1, [ MatchRom,$28,$34,$AF,$5F,$07,$00,$00,$4B]
OWOUT DQ, 0, [ CvrtTmp] ' send convert temperature command
DO ' wait on conversion
PAUSE 25 ' small loop pad
OWIN DQ, 4, [tempIn] ' check status (bit transfer)
LOOP UNTIL (tempIn)
OWOUT DQ, 1, [ MatchRom,$28,$34,$AF,$5F,$07,$00,$00,$4B]

OWOUT DQ, 0, [ RdSP] ' read DS1822 scratch pad
OWIN DQ, 2, [tLo, tHi] ' get raw temp data
tSign = sign ' save sign bit
tempC = tempIn >> 4 ' round to whole degrees
tempC.BYTE1 = $FF * tSign ' correct twos complement bits
tempF = (ABS tempC) * 9 / 5 ' start F conversion
IF (tSign) THEN ' finish F conversion
tempF = 32 - tempF ' C was negative
ELSE
tempF = tempF + 32 ' C was positive
ENDIF
tank = tempF


goto main

read_serial:

hserin 1000,timeout,[WAIT (":"),Nb_var22,Nb_var21,Nb_varH23,Nb_varM23,Nb_var24,N b_varH27,Nb_varM27,Nb_var28,Nb_varH59,Nb_varM59,Nb _var60]
hserin 1000,timeout,[WAIT (":"),Nb_var31,Nb_var32,Nb_varH33,Nb_varM33,Nb_var34,N b_varH37,Nb_varM37,Nb_var38,Nb_varH63,Nb_varM63,Nb _var64]
hserin 1000,timeout,[WAIT (":"),Nb_var41, Nb_var42,Nb_varH43,Nb_varM43,Nb_var44,Nb_varH47,Nb _varM47,Nb_var48,Nb_varH67,Nb_varM67,Nb_var68, hour, minute,Day ] 'get temp setting from Master
Send_serial:
hserout [dec tank, dec panel]'send info to Master
serout2 PortB.4,16468,[1,"got data"]
pause 2000

@ INT_RETURN


timeout:
RCSTA.4=0
RCSTA.4=1
serout2 PortB.4,16468,[1,"error "]

pause 2000
@ INT_RETURN