Simple code but strange result - 877A
Hello, I have written the following code but for some reason it is not working:
Code:
Include "modedefs.bas"
DEFINE OSC 4
@ __Config _XT_OSC & _WRT_256 &_WDT_OFF &_PWRTE_ON &_BODEN_OFF & _LVP_OFF
PAUSE 10
'-----------------------------------------------------
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 6
DEFINE DEBUG_BAUD 4800
DEFINE DEBUG_MODE 0
DEFINE DEBUGIN_REG PORTC
DEFINE DEBUGIN_BIT 7
DEFINE DEBUGIN_MODE 0
@ ERRORLEVEL -306
'------------------------------------------------------
ADCON1=7
CMCON=7
INTCON=128
OPTION_REG.7=0
TRISA=0 : PORTA=0
TRISB=0 : PORTB=0
TRISC=%10000000 : PORTC=0
TRISD=0 : PORTD=0
TRISE=0 : PORTE=0
CCP1CON=0
'-----------------------------------------------------
main:
TOGGLE PORTA.0
DEBUG "AT",13,10
DEBUGIN 500,main,[WAIT("OK")]
PAUSE 500
goto main
When I comment DEBUGIN, PortA.0 starts toggling. Else, my LED at PortA.0 just stays ON on power up.
Can someone point out my mistake if any please?
Re: Simple code but strange result - 877A
financecatalyst , You told it to "WAIT" for an OK to be sent before it is to resume..
DEBUGIN 500,main,[WAIT("OK")]
Dave Purola,
N8NTA
Re: Simple code but strange result - 877A
I have changed the code to use USART, things have progressed, LED at PortA.0 toggles every second, BUT there is constant voltage on the TX PIN. Rx works fine as it is connected to my computer via MAX232. So whenever I send an OK from my computer the toggling of the led is delayed for 3 seconds appx.
I do not see "AT" on my terminal window
Code:
PAUSE 10
'-----------------------------------------------------
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 2400 Baud @ 4MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
@ ERRORLEVEL -306
'------------------------------------------------------
ADCON1=7
CMCON=7
INTCON=128
OPTION_REG.7=0
TRISA=0 : PORTA=0
TRISB=0 : PORTB=0
TRISC=%10000000 : PORTC=0
TRISD=0 : PORTD=0
TRISE=0 : PORTE=0
CCP1CON=0
'-----------------------------------------------------
main:
TOGGLE PORTA.0
HSEROUT ["AT",13,10]
HSERIN 1000,main,[WAIT("OK")]
PAUSE 2000
goto main
877A with Modem. Communication Problem
I have written a small code to send AT commands to the Modem and then get an OK back. I have put my computer's RS232 connections in Parallel to keep an eye on the communication.
But My PIC is not Transmitting anything - I need help to make this work
My code is as follows:
Code:
Include "modedefs.bas"
DEFINE OSC 4
@ __Config _XT_OSC & _WRT_256 &_WDT_OFF &_PWRTE_ON &_BODEN_OFF & _LVP_OFF
PAUSE 10
'-----------------------------------------------------
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 2400 Baud @ 4MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
@ ERRORLEVEL -306
'------------------------------------------------------
ADCON1=7
CMCON=7
INTCON=128
OPTION_REG.7=0
TRISA=0 : PORTA=0
TRISB=0 : PORTB=0
TRISC=%10000000 : PORTC=0
TRISD=0 : PORTD=0
TRISE=0 : PORTE=0
CCP1CON=0
'-----------------------------------------------------
main:
TOGGLE PORTA.0
HSEROUT ["AT",10,13]
HSERIN 1000,main,[WAIT("OK")]
PAUSE 2000
goto main
The receiving end is working fine, as I can send the "OK" from my terminal window and my PIC is getting it. But nothing appears on my Terminal window from the PIC.
I have checked that there is a constant voltage on the TX pin, 4.6V. Is something wrong with my code?
Re: Simple code but strange result - 877A
Do you have a schematic? What's RC.6 connected to?
Re: Simple code but strange result - 877A
Quote:
Originally Posted by
scalerobotics
Do you have a schematic? What's RC.6 connected to?
rc.6 ->Pin11 (MAX232) -> Pin14(MAX232) -> Modem Pin3 (Female RS232)
Re: Simple code but strange result - 877A
Hi,
I have NEVER used the USART to transmit so if I am wrong, . . . well here is my try . . .
TXSTA.5 = 1 'which is transmit enable bit.
Re: Simple code but strange result - 877A
Quote:
Originally Posted by
Joe S.
Hi,
I have NEVER used the USART to transmit so if I am wrong, . . . well here is my try . . .
TXSTA.5 = 1 'which is transmit enable bit.
:( Didn't Work
Re: Simple code but strange result - 877A
this is from the datasheet
Quote:
Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be
set in order to configure pins RC6/TX/CK and RC7/RX/DT
as the Universal Synchronous Asynchronous Receiver
Transmitter.
So maybe you need to set trisc.6=1 also?
Re: Simple code but strange result - 877A
Quote:
Originally Posted by
cncmachineguy
this is from the datasheet
So maybe you need to set trisc.6=1 also?
Thanks for the reply. Tried the above - NO Luck :(
Re: Simple code but strange result - 877A
OK, Just a Doh check for me, but I assume you DO have some kind of osc hooked up? xtal,resonator, something?
Re: Simple code but strange result - 877A
Maybe the extra space between the T and the [ is messing things up?
Code:
HSEROUT ["AT",10,13]
If that is not the problem then double check the speed of your OSC. Receiving works, yes. But receiving is more tolerant than sending.. At least it seems that way. Are you using a crystal with caps or a resonator?
Re: Simple code but strange result - 877A
Unless my glasses are not thick enough, the hserin appears to be missing a variable to store value. Have you tried a single character? Maybe hserout will only send a string from an array ? Just thinking out loud . . .
Re: Simple code but strange result - 877A
Back to basics... do an HSEROUT loop, use a scope see if there's something happening on PIC pin... then on the TX of the MAX232. If so, check on the computer side.