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.

EUSART1_Read() function to receive string

Status
Not open for further replies.

engr_joni_ee

Advanced Member level 3
Advanced Member level 3
Joined
Nov 3, 2018
Messages
822
Helped
2
Reputation
4
Reaction score
7
Trophy points
18
Activity points
6,874
I am using PIC18F. I am wondering if anyone has tried to get string using this function which is generated in the MCC in MPLAB.


Code:
uint8_t EUSART1_Read(void)
{
    while(!PIR1bits.RC1IF)
    {
    }

    eusart1RxLastError.status = 0;
  
    if(1 == RCSTA1bits.OERR)
    {
        // EUSART1 error - restart

        RCSTA1bits.CREN = 0;
        RCSTA1bits.CREN = 1;
    }

    return RCREG1;
}

I have made the following function outside the main() that calls the MCC generated function "EUSART1_Read()". I need to get a string basically through the following function but this has some issues that involves return types and assignments. Can someone please have a look and help me to resolve the issue in receiving the string using the MCC generated function.

Code:
char EUSART_Read(void)
{
int i = 0;

char rx = 'a';
char rx_string[10];

while (rx != 0x0d)
{
rx = EUSART1_Read(); // Return type of this function is uint8_t
rx_string[i] = rx; // store the data in string
i++;
}
return rx_string;
}

I need to call this function in the main() function but it says that rx_string is not assignable.

Code:
 rx_string = EUSART_Read();
Even if I define rx_string as uint8_t, the problem is the same. Somewhere I am not using the correct data type and return type.
 
Last edited:

Hi,

I´m no C specialist, but if I´m not mistaken you can´t return strings.
Try to define the string outside and pass it as pointer.

Klaus
 

I guess John doesn't appreciate the help he is getting at
and
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top