I'm working with a PIC32MX564F128H in MPLABX 2.35 with pickit3. I'm trying to parse a message from UART. The character is received properly, but I'm stalling when I attempt to copy a character to a buffer. This is the part in my main loop:

                unsigned char*buffer="efg"; //dummy string
                GetDataBuffer(buffer, 3);


  UINT32 GetDataBuffer(unsigned char *buffer, UINT32 max_size)
        UINT32 num_char;
        num_char = 0;

        while(num_char < max_size)
            UINT8 character;
            character = UARTGetDataByte(UART1);
            if(character == '\r')
            *buffer = character;  **\\PROGRAM STALLS HERE** 
        return num_char;


In debug mode, after unsigned char pointer declaration: buffer address: 0xA0008010 Value: Invalid Address

After being passed into GetDataBuffer: buffer address: 0xA00071F8 Value: 0x9D005ED8 *buffer=0x65 ("e", at this point not written over.) Continuing, program stalls at point shown above until the debugger halts at an unknown location.


1 Answer 1


You are having this problem because you are attempting to modify buffer which you defined as pointer to char, or rather point to a string literal. You cannot modify this. You should use:

unsigned char buffer[]="efg";

instead. For more information, check out this post: Char array vs Char Pointer in C

  • \$\begingroup\$ So unsigned char*buffer="efg" is actually like a unsigned char const *const buffer="efg" where change in address pointed and value is not allowed?? \$\endgroup\$
    – AlphaGoku
    Apr 18, 2016 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.