- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How about upload your project so people can check ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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