View Full Version : Simple code but strange result - 877A
financecatalyst
- 6th May 2011, 11:46
Hello, I have written the following code but for some reason it is not working:
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?
Dave
- 6th May 2011, 12:08
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
financecatalyst
- 6th May 2011, 14:37
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
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
financecatalyst
- 6th May 2011, 16:30
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:
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?
ScaleRobotics
- 6th May 2011, 16:54
Do you have a schematic? What's RC.6 connected to?
financecatalyst
- 6th May 2011, 19:48
Do you have a schematic? What's RC.6 connected to?
rc.6 ->Pin11 (MAX232) -> Pin14(MAX232) -> Modem Pin3 (Female RS232)
Archangel
- 6th May 2011, 20:49
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.
financecatalyst
- 6th May 2011, 21:21
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
cncmachineguy
- 6th May 2011, 23:48
this is from the datasheet
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?
financecatalyst
- 7th May 2011, 01:00
this is from the datasheet
So maybe you need to set trisc.6=1 also?
Thanks for the reply. Tried the above - NO Luck :(
cncmachineguy
- 7th May 2011, 02:30
OK, Just a Doh check for me, but I assume you DO have some kind of osc hooked up? xtal,resonator, something?
mackrackit
- 7th May 2011, 02:40
Maybe the extra space between the T and the [ is messing things up?
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?
Archangel
- 7th May 2011, 11:11
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 . . .
mister_e
- 8th May 2011, 19:14
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.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.