arunbharathi.arasu
Full Member level 2
- Joined
- Feb 28, 2013
- Messages
- 134
- Helped
- 7
- Reputation
- 14
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Chennai, Tamil Nadu, India
- Activity points
- 2,151
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.
char Table[128];
char *pointer;
int index;
void main()
{
pointer=Table;
index=0;
Table[index]=UartData; // be carrefull, you have to manage the index value 0 to 127
index++;
*(pointer)=UartData;
pointer++;
//check if pointer keep in the range of displacement 0 to 127, else overflow the Table size.
_Interrupt(void){
reqflag = 1;
}
function(){
if(reqflag == 1)
{
ptr++;
reqflag =0;
}
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.
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;
}
Hi friends,
I need to receive a string in UART INTERRUPT using pointer.
Please help me as soon as possible.......
Thanks in advance............
Do you want to say you are expecting strings of infinite length? So you obviously need a processor with infinite RAM. :lol: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.
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; }
So i need to receive and store the whole messages with infinite size.
So i need to receive and store the whole messages with infinite size. How can i do by using this in 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.
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.
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.
reponse is IMPOSSIBLE !
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?