Hi,
You code does what I would expect, when I run it on an MSP430. The code
doesn't actually do what you said, though. It just adds 4 to the first
element of the array that is passed.
Alan007 wrote:
Dear All,
I'm trying to recompile some c code that was initially with IAR in gcc. My
function that doesn't work, is supposed to write characters to a serial
port.
The prototype of my function to write to a serial port, is:
void put_message( unsigned char *s);
I then call this function like so:
put_message( "TEST");
If I put a breakpoint inside the put_message function and examine the value
of *s, I get 0. I've examined the "memory map" around s in gcc, and the
memory locations after s are also set to 0.
Does gcc not like unsigned char pointers?
Here's a small snippet of code where the problem occurs:
#include <msp430x42x.h>
void put_message(unsigned char *msg){
msg[0]++;
msg[0]++;
msg[0]++;
msg[0]++;
}
The first byte of msg is incremented 4 times. Interestingly, it doesn't
get optimised down to a single increment by 4. I wonder why.
int main(void){
int i = 0;
unsigned char message[10];
message[0]=1;
message[1]=2;
message[2]=3;
message[3]=4;
P1SEL = 0;
P1DIR = P1DIR | 0x8;
while (1){
P1OUT = P1OUT | 0x8;
for (i=0;i<1000;i++){}
P1OUT = P1OUT & 0xf7;
for (i=0;i<1000;i++){}
If I use an optimisation level greater than the base level, the two
above loops are optimised away, and P1.3 shows a very narrow pulse.
put_message(message); //neither of these function calls produce the
correct value in put_message
message is now 0x05, 0x02, 0x03, 0x04
put_message("test");
message is now 0x68, 0x65, 0x73, 0x74
}
}
Do you have any suggestions? Thanks in advance for your help,
What were you expecting to be different from this?
Steve