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.

Problem Sending Pointer to String to Function

Status
Not open for further replies.

ste2006

Advanced Member level 4
Joined
May 1, 2012
Messages
118
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
2,226
I am writing some code in C and i have written some code to send a pointer to a string to a function but its not working. I am trying to keep the code down a little and i thought what i have written would work but it wont, it compiles fine but the array does not seem to contain anything.

Here is the code calling the function:

Function Prototype:
Code:
unsigned char SendCommand (unsigned char *str);

Code:
ModemStatusFlag=SendCommand("AT+WS46=12");

Here is the start of the function

Code:
unsigned char SendCommand (unsigned char *str)
{
    unsigned char ModemStatus = 0x00;
    unsigned char i = 0x00;
    unsigned char RxData[9] = {0};
    char CReturn = 0x0D;

    // Start 1 Second Timer in case USART Locks Up
    if (RCSTA2bits.OERR2 = 1)           // Check for Overflow Error
         {
             RCSTA2bits.CREN2 = 0;
             RCSTA2bits.CREN2 = 1;
         }


    while(*str != '\0')
        Send2Byte(*str++);

    Send2Byte(CReturn);

    for (i=0;i < 2; i++)

I have ran through it with the debugger and it seems to get to the function fine but as the pointer to str seems to contain nothing useful,

Anyone any thoughts??

Thanks
 

still having issues but have modified the function and a few bits to make life easier but i am more confused than ever now,

New function part:

Code:
while(*str != '\0')
    {
        temp1 = *str;
        str++;
        temp2 = *str;
        str++;
        temp3 = *str;
        Send2Byte(*str);
    }


values of registers from ICD3 after i run these few lines,

temp1 = 0x44
temp2 = 0x68
temp3 = 0x00

str value after these commands = 0x14F6

MemDump:

Address 00 02 04 06 08 0A 0C 0E
014F0 FFF4 0012 5441 572B 3453 3D36 3231 FF00 ....AT+W S46=12..

01500 50C2 0B02 E001 0E01 0012 0012 FFFF FFFF .P...... ........

01510 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ........ ........

Any ideas whats going on here???

It seems like it is not reading the pointer values from memory at all and just making up its own
 

Hi,
Try add a local pointer inside your function

Code:
unsigned char myfunction (unsigned char *mystr)
{
    unsigned char* str=mystr;      

......
......

    while(*str != '\0')
    {
        temp1 = *str;
        str++;
        temp2 = *str;
        str++;
        temp3 = *str;
        Send2Byte(*str);
    }

.....
.....

If you do not have any result, please specify how compiler you use.
 

Spent the whole day at it yesterday but got it sorted in the end by scouring the memory, Amazed no one here spotted it,

The string was being stored in ROM while the pointer was to a location in RAM, I forced the pointer to be in ROM and now its all fine again,

A tricky one to debug though,

Thanks Alex for your suggestion
 

Your example was using SendCommand("AT+WS46=12"); so the string was in RAM, am I wrong?

Depending on the architecture a pointer to ROM may need special handling (like in AVR) or be exactly the same like ARM based MCU, you didn't provide info on the mcu you were using.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top