PDA

View Full Version : Hserin & Hserout - Trying to blink an LED



Megahertz
- 24th May 2010, 05:22
Hi, I am using 16F877A along with DT_INT, I have started this new thread as previous thread was not relevant to this problem anymore. I am trying to understand USART and blink an LED first.
My hardware setup has a TX module connected to PIN25 (TX) & RX module at PIN26 (RX).
LEDs are connected to PIN40,39,38
I am not using any special kind of modules, just normal types sold on ebay.

My Rx code is :


DEFINE OSC 4
Include "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

@ __Config _XT_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_ALL & _CPD_ON

Pause 50
'-------variables declared-------------------------------------

code1 var byte
code2 var byte

;-----------HSERIN & OUT------------------
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 12 ' 4800 Baud @ 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 12 ' 4800 Baud @ 0.17%

'-------------------------FUSES SET----------------------------
PAUSE 50
ADCON1=7
CMCON=7
CCP1CON=0
OPTION_REG=%10000000
TRISA=0 : PORTA=0
TRISE=0 : PORTE=0
TRISB=0 : PORTB=0
TRISC=%10000000 : PORTC=0
TRISD=0 : PORTD=0
@ ERRORLEVEL -306


'------INTERRUPT DECLARED--------------------------------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleFast, PBP, yes
INT_Handler RX_INT, _RX, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON=%00110001

@ INT_ENABLE TMR1_INT
@ INT_ENABLE RX_INT

;------MAIN PROGRAM START-----------
start:
HIGH PORTB.7
PAUSE 50
LOW PORTB.7
PAUSE 100
Goto start


'---[INT - interrupt handler]---------------------------------
ToggleFast:
Toggle PortB.6
@ INT_RETURN


RX:
TOGGLE PortB.5
HSERIN 100,close,[WAIT("MT3"),code1,code2]
close:

@ INT_RETURN

'---------end--------------------

Currently I just want to see first if both interrupts are working fine.
This is what happens:
LEDs are connected to PortB.7,6 & 5. When power is applied, PortB.7 blinks, PortB.6 blinks but when PortB.5 blinks, normally PIC hangs for few seconds and then normal erratic behaviour happens because of the interrupts, then again PIC hangs for few seconds or permanently.
Even if/when I comment out the HSERIN statement in the RX ISR, PIC still hangs, BUT only TMR1 led keeps blinking.
Is this overall behaviour normal, I am using this feature for the first time, am I doing it right?

Help please.

Jumper
- 24th May 2010, 05:48
Hi,

A good idea is to remove the radio modules and just put a short cable with 3 lines.. GND RX and TX and see what happens.

Remove as much as possible from the circuit and simplify ...

AND

TURN OFF the Watch Dog.. it seems as you have it turned on in the config bits but you are not clearing it anywhere in the code so it will come out and bite you. The WDT is constantly resetting your PIC and that will account for at least some of the erratic behaviour (or alot).

Megahertz
- 24th May 2010, 06:37
Hi,

A good idea is to remove the radio modules and just put a short cable with 3 lines.. GND RX and TX and see what happens.


May be I didn't made myself clear, I am just using one IC only Both modules are connected to one IC.



TURN OFF the Watch Dog.. it seems as you have it turned on in the config bits but you are not clearing it anywhere in the code so it will come out and bite you. The WDT is constantly resetting your PIC and that will account for at least some of the erratic behaviour (or alot).

I have turned off the watchdog timer
....& WDT_OFF....
Behaviour is still the same. As soon as RX ISR led glows, the main loop LED hangs, only timer LED is blinking.
(HSERIN IS COMMENTED CURRENTLY IN RX ISR)

mackrackit
- 24th May 2010, 08:36
May be I didn't made myself clear, I am just using one IC only Both modules are connected to one IC. Many RF modules will not work when close together. Having them both in the same chip is almost certainly not going to work.

You also need a syncing method and a way to train the data slicer on the receiver.

Like Jumper said, get it working with cables then go for the RF.

Megahertz
- 24th May 2010, 09:06
OK, I have disconnected the TX module. Now only RX module is connected. When I power up the IC, the receiver module catches codes in the air.
NORMAL BEHAVIOUR:Main led should keep blinking, TMR1 led should keep blinking, and when ever PIC enters RX ISR, PortB.5 LED should toggle (HSERIN IS COMMENTED HERE, SO NO WAITING OR CHECKING FOR THE DATA CURRENTLY).

But is it still not happening, I will jump onto wired communication between two ICs when this will start working normally. Currently, as soon as LED in RX ISR toggles, it hangs and so IS the led in the main loop. Only TMR1 LED keeps blinking. Looks like code is getting stuck somewhere when it enters RX ISR.

I am not communicating with any ICs currently. Just trying to blink LED's in interrupts so I know that interrupts are happening, code is entering there and getting out of there.

Jumper
- 24th May 2010, 09:38
Hi,

Maybe your RX module picks up so much noice that it is constantly receiving "data" and therefore you are more or less stuck interupting all the time...

Pull out the RX module too and connect the RX pin to GND.. that would leave you with a LED in the main loop and the TMR1 LED toggle.

when you have done that.. take a new pic and send data from new pic TX pin to OLD pic RX pin using a cable..

Or put a scope on the RX pin you have today and see what is actually happening....

vaporized
- 24th May 2010, 12:25
Hello.
If you commented out HSERIN in the ISR then you're not clearing interrupt flag, therefore constantly looping between main routine and the ISR. Also, I would advise to read RCREG first then toggle portb.5. But it would be much better to pick up a complete package and deal with it in the main routine.

Out of curiosity:


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

RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 12 ' 4800 Baud @ 0.17%

Why doing same thing twice?