Serial port receive Buffer help

This is a discussion on Serial port receive Buffer help within the C Programming forums, part of the General Programming Boards category; This is My First post to this Forum.... suggest me which is the best way to receive string from serial ...

  1. #1
    Registered User Daffodils's Avatar
    Join Date
    Jul 2009
    Posts
    2

    Unhappy Serial port receive Buffer help

    This is My First post to this Forum....

    suggest me which is the best way to receive string from serial port by using own functions with out using standard library.....

    Fixed Char array or by using pointers??

    Please Help me to receive strings from serial port of a microcontroller using C..


    I Established the communication with controller and the function getchar() can receive one charector at a time from serial port succesfully..

    Code:
    /******************************************************************************/
    /* SERIAL.C                                        */
    /******************************************************************************/
    #include <controllerxx.H>            
    #define NULL     '/0'
    
     
      
    /* implementation of getchar */
    
    int getchar (void)  {                     /* Read character from Serial Port   */
    
      while (!(U1LSR & 0x01));	   //Don't care about this this is controller registors 
    
      return (U1RBR);
    }
    
    
    //Here 	is my code start....	getchar() function can read one charector at time  from serial port
    
    All I need to do is store this to a variable and whenever iam calling from main function it should display the string...
    
    //Function  defenitions
    
    unsigned char string_receive(void)
    {
    static char uart_data[200];
    static char count=0;
    while(uart_data[count]!=NULL)
        {
         uart_data[count]=getchar();
         count++;
        } 
    return uart_data[200];	 
    } 							 
    
    
    
    
    int main (void)
     {
     char abc[200];
     init_serial ();              /* Initialized Serial Interface   ..its OK I can receive Char..    */
     
    
     abc[200]=string_receive();
    
     display(abc);
    
     }
    Last edited by Daffodils; 07-23-2009 at 06:18 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    First practice passing and returning arrays (or more accurately, pointers).

    > #define NULL '/0'
    1. NULL (the pointer) is not the same thing as nul (the zero character).
    2. It should be written as '\0' anyway.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM
  2. Serial Port - Receive Packet
    By samuelmoneill in forum C Programming
    Replies: 21
    Last Post: 04-22-2009, 02:07 AM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Send and receive through serial Port
    By overspray in forum C++ Programming
    Replies: 1
    Last Post: 07-21-2004, 04:15 PM
  5. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 03:59 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21