[SOLVED] How to receive string in UART using POINTER

Status
Not open for further replies.
I need to get a character using pointer form UART.

We can get single character using pointer in C Language by using memory allocation.

But in our (EMBEDDED)compiler we cannot use memory allocation.

Without using memory allocation how can i get a character using pointer.
 



If I understand your description of the issue correctly, the simple answer is you CANNOT store any form of data using a pointer without some method of memory allocation.

A pointer is just that, only a pointer, it must point to viable memory address or sequence of viable memory address before the pointer can be utilized to storage data within those memory locations.

Memory allocation can occur either by defining an auto variable, i.e. standard variable definition, or through dynamic allocation, i.e. malloc(), calloc(), etc.


Perhaps if you elaborate on the specifics of your project, we maybe able to suggest possible options.

Posting your code might also more clearly convey what you are attempting.


BigDog
 

hello,




Tell us what is the maximum size of data you will get..
What type of MCU , maximum RAM size
sometime with PIC family, you must rearange the RAM bank by modify the linker file.
ex: if table size is more than 256 bytes (1 bank =256 bytes)

you can declare a table and a pointer on this table
ex:
Code:
char Table[128];
char *pointer;
int index;

and initialize it somewhere before to use it

Code:
void main()
{

pointer=Table;
index=0;
after you can store the data from UART
directly inside the table
Code:
Table[index]=UartData;  // be carrefull, you have to manage the index value 0 to 127
index++;


or use the pointer
Code:
*(pointer)=UartData;
pointer++;
//check if pointer keep in the range of displacement 0 to 127, else overflow the Table size.
 
Last edited by a moderator:

Thanks for your replies,

I already tried what you given in the above post Mr.paulfjujo.

Actually i am using ARM 2129 and keil compiler.

The problem is,how to receive and store single character in pointer.Which is receiving from UART.

Without using malloc and calloc function,because we cannot allocate memory using malloc and calloc in EMBEDDED C.
 

use a flag high in the interrupt, write separate function based on the flag, make your storage accordingly by incrementing pointer every time the flag goes high !

Code:
_Interrupt(void){
  reqflag = 1;
}

function(){
if(reqflag == 1)
{
   ptr++;
   reqflag =0;
}
 
Last edited:

Fine Raady,

How can we receive a single character in pointer?

we cannot receive single character in pointer without allocating memory,But in Embedded C memory allocating is not possible(Like malloc and calloc in C).

Can you know any other way to allocating memory in EMBEDDED C.
 


I didn't get your application, if known I can help you out !

Here I go with an simple example I scan Keypad and store the password
KP_Data is the scan of the keypad in ascii.

Here are my decelarations
Code:
unsigned char* pEnteredPW;
unsigned char EnteredPW[5], SavedPW[5]="0000";

....
pEnteredPW = EnteredPW;              			// Pointing to the first character of Entering Password	
....


if( KP_Data > 47 && KP_Data < 58 )       		// Checking if any numerical values are pressed
    {
	CursorPos++;				          		// Counting the number of characters
	if(CursorPos > 0 && CursorPos < 5) 			// Only first 4 characters are taken as password
	{
		XLCDPut('*');					  		// Masking the key by '*'
		*pEnteredPW++ = KP_Data;
		*pEnteredPW   ='\0';	
	}
	if(CursorPos == 4)
		XLCD_BLINKCURSOROFF();
		KP_Data =0;
    }
Now I have that array filled with the keys that I have entered. Now if I wish to save I will write in EEPROM,or else make some comparisions or so as I required.

In my case KP_Data is the keypad scanned variable, in your case the letter that is received from UART( KP_Scan = UXRG).
Here I havent allocated memory using calloc or malloc for this ! Try out your self for any circuit in proteus.
 

It's not clear why you keep on about allocating memory. Related to your original question it's sufficient to know that you can set a pointer to any already allocated memory entity, e.g. an external or automatic variable, as explained by paulfjujo in post #5.

It's not generally true that embedded C doesn't allow malloc(), but it's correct to say that malloc() isn't of much practical use in embedded applications. The details are implementation dependant, I don't know particularly about Keil C for ARM.
 

Hi friends,
I need to receive a string in UART INTERRUPT using pointer.
Please help me as soon as possible.......

Thanks in advance............

Maybe you are asking the wrong question?

I think the question should be "How to receive string in UART using BUFFERS?"
 

Thanks for your replies,

Friends,we can get string in pointer,

But from UART i can get string character by character,

i can get a character by using ARRAY.But using array i have to allocate the maximum size.

I don't know the size of the string,which i get from UART.

So using ARRAY is not possible in this case.So only i am going for pointer instead of array.

In pointer i can get a single character by using malloc and calloc,generally in C.

But in EMBEDDED C i cannot use this malloc and calloc keyword directly.

Now,How to get a character from uart in pointer.

please help me.......
 

I don't know the size of the string,which i get from UART.

So using ARRAY is not possible in this case.So only i am going for pointer instead of array.
Do you want to say you are expecting strings of infinite length? So you obviously need a processor with infinite RAM. :lol:

Thinking seriously about the problem, you'll arrive at a certain string length that your application should process regularly. If for some reason (e.g. hardware failure) longer strings are presented to the UART, it should provide some kind of robust error handling. The problem is basically the same in embedded or general computing, malloc won't be a resonable solution for it in any case.

Most practical UART designs are receiving data to a circular buffer on the first (usually interrupt controlled) level, using NextIn and NextOut pointers. Then reading it asynchronously from the buffer. In some cases, the data can be simply processed continuously without copying it to another string. But you didn't yet talk about an actual application.
 

HELLO MR. TRY THIS,


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void transmit(unsigned char a)
{
SBUF=a;
while(TI==0);
TI=0;
}
 
unsigned char receive()
{
unsigned char d;
d=SBUF;
while(RI==0);
RI=0;
return d;
}



- - - Updated - - -

THIS IS ENOUGH, NO NEED TO DECLARE ARRAY AND ALL
 
Last edited by a moderator:

Thanks mr.fvm

My problem is not in hardware,And in my application i need to receive a string(MESSAGE) from GSM 900 via UART.
i need to process a whole messages by segmenting it.

So i need to receive and store the whole messages with infinite size. How can i do by using this in pointer.

Thank Mr.Thirunavukkarasu.

But my problem is, i have to store the string what i get from UART.
 

hello


So i need to receive and store the whole messages with infinite size.

reponse is IMPOSSIBLE ! if the data flow is contigus and RS232 speed to high..

The MCU need some time to treat each caractere ...
The UART has a buffer of 1 car (minimum)
at 9600bds, 960 car per seconde , it's take near 1 Milliseconde to have a Full UART buffer
You will get an UART interrupt every 1MS.

so it depends what do you have to do in your main program
How long time it needs to do other operations..
if all other task take more than 1 milliseconde => Impossible ..

Or try to find out a MCU with a big buffer inside the UART.. 16 cars buffer
and some RAM to store data.
 

So i need to receive and store the whole messages with infinite size. How can i do by using this in pointer.

Repeatedly asking the same question will unfortunately not change the answer to your question.

I would strongly advise you to study a section of a text on the C language pertaining to the use of pointers in C.

It is quite obvious at this point in the discussion you have not bothered to read the following previous replies:





reponse is IMPOSSIBLE !



BigDog
 

Actually i don't know whether it is possible or not.

so only asked.I studied lot of things,But the result is impossible.

I just ask here,Because of any possibilities.

And Mr.fvm ask the original application, so only i continued.

now i came to know which is not posible.

Thanks for your replies.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…