floats over serial uart

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I have try to send a float over serial via sprintf and putstring but it does not work? what is the best way to do this?

0 Likes
6 Replies
Anonymous
Not applicable

 How about upload your project so people can check ?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

sprintf places the float string into a RAM buffer, whereas UART_PutString(const char8 string[])

   

wants to fetch the string from FLASH. You will have to use UART_PutChar(uint8 txDataByte) in

   

a loop to transmit the sprintf buffer one character at a time until you hit the null character terminating

   

the string.

   

 

   

Regards, Dana.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

@Dana: You can give a string from sRAM to _PutString(). Its perfectly fine to convert a const char * into a char *, just not the other way round.

   

@EngineerBro: what is it that doesn't work? Code doesn't compile? Nothing received on the PC? Garbage received on the PC?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Hli, so compiler when cast as const to char dupes the string, glad you

   

told me that. Learning C as I float down the stream to the cliff on the lily

   

pad of life, totally oblivious I might add.

   

 

   

Regards, Dana.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

No, the compiler won't copy the string. When a const char * is used in a function parameter, its an assertion (given by the function) that the function won't ever change the string. When used in a variable definition (as in const char * text="hello") its a requirement that no code will try to change this string (so the compiler can place it in flash memory).

   

 

   

Its perfectly fine to give a string which can be mutated to a function which says it won't do that. You just cannot give a non-mutable string to a function which says it might mutate it (as in giving the text variable from above as target to strcpy or so).

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@Dana:

   

The usage of "const" slightly differs from the PSoC1 compilers. The meaning is explained in the C-compiler handbooks. In standard C (GCC) there is nothing like a flash-parameter since the addressing scheme is the same for flash and sram, while in PSoC1 there are different assembly instructions needed. to address them

   

 

   

Bob

0 Likes