EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / usart transmission problem

usart transmission problem

|

Microcontroller › PIC › usart transmission problem

  • This topic has 1 reply, 2 voices, and was last updated 12 years, 7 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • March 31, 2013 at 10:22 pm #2221
    kingshuk basu
    Participant

    i am facing a problem with data transmission while using the usart module of 16f877a.

    the data is being sent continuously even though the program is for sending data once only…………………..

    plzzzzzzzzzz help.its urgent.this my program:

     


    main


    #include <htc.h>
    #include “usart.h”
     
    void gsm_cmd(unsigned char *);
    void Delay_ms(unsigned char);
     
    unsigned char value=0;
    int i=0,j,k;
    unsigned char *sms_format=”AT+CMGF=1″;
    unsigned char *sms_write=”AT+CMGS=”9038940850″”;  // 10-Digit Mobile Number
    unsigned char *sms=”Hello”;
    unsigned char *sms_report=”SMS Sent…”;
    unsigned char sms_terminate=0x1A;
    unsigned char enter=0x0D;
    unsigned char *data;
     
    void main()
    {
    INTCON=0; // purpose of disabling the interrupts.
     
    init_comms(); // set up the USART – settings defined in usart.h
     
    gsm_cmd(sms_format);
     
    Delay_ms(1000);
     
    gsm_cmd(sms_write);
     
    Delay_ms(1000);
     
    gsm_cmd(sms);
    Delay_ms(1000);
    putch(0x1A);
    Delay_ms(1000);
    while(1);
    }
     
    void Delay_ms(unsigned char d)
    {
    while(d–);
    }
     
    void gsm_cmd(unsigned char *string)
    {
    int i=0;j=0;
    while(string!=’’)
    {
     
    if(string==0x5C) // Not to send ” cahracter
    i++;
    putch(string); // Send by serial communication
    i++;
     
    }
     
    putch(enter); // Send ASCII code for ‘Enter’ key
     

    }

     

     

     

     

     

     

    #include <htc.h>
    #include <stdio.h>
    #include “usart.h”
     
    void putch(unsigned char byte) 
    {
    /* output one byte */
    TXREG = byte;
      while(!TXIF); /* set when register is empty */
     
     
    }
     
    unsigned char getch()
    {
    /* retrieve one byte */
    while(!RCIF) /* set when register is not empty */
    continue;
    return RCREG;
    }
     
     
    unsigned char
    getche(void)
    {
    unsigned char c;
    putch(c = getch());
    return c;
    }
    April 1, 2013 at 5:45 pm #9405
    AJISH ALFRED
    Participant

    Hi Kingshuk,

    You haven’t written anything inside an infinite loop, but you can see the data being sent again and again.

    Most probably your controller is getting restarted again and again after sending some data, that’s why you feel that the controller is continuosly sending data.

    The reason for such an issue is always related with memory shortage. You might be either trying to allocate memory which is not avilable at the moment or trying to access memory which has not been allocated (using pointers).

    This is basically run time error. Suggest you to thoroughly analyse your pointer usage.

     
    For example in the following function;
     
    void gsm_cmd(unsigned char *string)
    {
    int i=0;j=0;
    while(string!=”)
    {
     
    if(string==0x5C) // Not to send ” cahracter
       i++;
    else                          //#### TRY PUT AN ELSE HERE ####
       putch(string); // Send by serial communication
    i++;
     
    }
     
    Try this also; change to ‘const char’
    const char *sms_format=”AT+CMGF=1″;
    const char *sms_write=”AT+CMGS=”9038940850″”;  // 10-Digit Mobile Number
    const char *sms=”Hello”;
    const char *sms_report=”SMS Sent…”;
    Change to this type in function defenitions and wherever required.
     
     
  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • WTB: "The Theory Of Servicing AM, FM, And FM Receivers" by Clarence R. Green and Robert M. Bourque November 10, 2025
  • Anyone In The US Ordered From AliExpress Recently? November 10, 2025
  • Calculation of A Class amplifier November 10, 2025
  • strange laptop problem November 10, 2025
  • restarting this Christmas project November 10, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise