Simple code but strange result - 877A


Closed Thread
Results 1 to 14 of 14
  1. #1

    Default 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?
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default 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

  3. #3


    Did you find this post helpful? Yes | No

    Default 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
    ___________________
    WHY things get boring when they work just fine?

  4. #4


    Did you find this post helpful? Yes | No

    Default 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?
    ___________________
    WHY things get boring when they work just fine?

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: Simple code but strange result - 877A

    Do you have a schematic? What's RC.6 connected to?

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Simple code but strange result - 877A

    Quote Originally Posted by scalerobotics View Post
    Do you have a schematic? What's RC.6 connected to?
    rc.6 ->Pin11 (MAX232) -> Pin14(MAX232) -> Modem Pin3 (Female RS232)
    ___________________
    WHY things get boring when they work just fine?

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default 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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8


    Did you find this post helpful? Yes | No

    Unhappy Re: Simple code but strange result - 877A

    Quote Originally Posted by Joe S. View Post
    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
    ___________________
    WHY things get boring when they work just fine?

  9. #9
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: Simple code but strange result - 877A

    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?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: Simple code but strange result - 877A

    Quote Originally Posted by cncmachineguy View Post
    this is from the datasheet


    So maybe you need to set trisc.6=1 also?
    Thanks for the reply. Tried the above - NO Luck
    ___________________
    WHY things get boring when they work just fine?

  11. #11
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default 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?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default 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?
    Dave
    Always wear safety glasses while programming.

  13. #13
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default 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 . . .
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default 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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts