Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

reading a string from uart of cortex-m3

Status
Not open for further replies.

raghavkmr

Junior Member level 2
Joined
Nov 26, 2013
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
194
Hi ,
I am trying to read string from uart into cortex-m3,I can read numbers but how to go with string
below is my code to read number


Code:
int scannumber()
    {
    	uint8_t rxbuff,x[8]={0},i=0;//[8];
    	mss_uart_instance_t * this_uart = &g_mss_uart1;
    	int num;
    	while(i<8)
    	{
    	UART_Polled_Rx( &g_mss_uart1, &rxbuff, sizeof(rxbuff) );

    	if(rxbuff == '\r')
    	    	{
    	    		rxbuff= this_uart->hw_reg->RBR;
    	    		rxbuff= this_uart->hw_reg->RBR;
    	    		break;
    	    	}
    	    	else
    	    		x[i++]=rxbuff;
    	    	}
    	num = atoi(x);
    	return num;
    }
 

Why do you using polling method? First, you should get a string. Then parse it.
When you using old crap microcontrollers like a PIC or AVR, you can use interrupt to receive data from host. But ARM gives you posibility to use FIFO and DMA.
 

Why do you using polling method? First, you should get a string. Then parse it.
When you using old crap microcontrollers like a PIC or AVR, you can use interrupt to receive data from host. But ARM gives you posibility to use FIFO and DMA.

its polling and cortex-m3 uses fifo to do this
 

hello,

sorry, i only now PIC MCU, not CORTEX
but,

Code:
int scannumber()
    {
        uint8_t rxbuff,x[8]={0},i=0;//[8];
        mss_uart_instance_t * this_uart = &g_mss_uart1;
        int num;
        while(i<8)
        {
        UART_Polled_Rx( &g_mss_uart1, &rxbuff, sizeof(rxbuff) );

        if(rxbuff == '\r')
                {
                   [B]x[i]=0;   // add here string terminator [/B]
                       rxbuff= this_uart->hw_reg->RBR;    // i don't now the purpose of this ????
                    rxbuff= this_uart->hw_reg->RBR;    // i don't now the purpose of this ????
                    break;
                }
                else
                    x[i++]=rxbuff;
                }
        num = atoi(x);
        return num;
    }

string length for unsigned integer 16bits is 6 .. not 8 "65536" 5 chars + zero
 
Last edited:

Apart from all detail points what might be coded differently, the function is already reading a string x which is converted to integer number. So what's your exact problem?

To return a string from a function, you would usually supply a pointer to char array that receives the string along with a maximal number of characters. Missing length check is a serious flaw of the shown code, you can easily crash the application by typing many characters without carriage return.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top