Integer/Float over UART

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

cross mob
Anonymous
Not applicable

Hi,

   

i think this is a noob question here, but anyway. My application involves interfacing an ADXL345 with the PSOC4 BLE, over SPI, and communicating the data to the computer serially via UART.

   

However, im unale to send the integer data over UART. Here's a short code that im trying to run :

   

the idea is to print "784.4564549" onto my serial monitor.

   
    float myFloat = 784.4564549;     
int bytesWritten;     
char myString[50];     
bytesWritten = sprintf(myString, "%f", myFloat);     
UART_UartPutChar(myString);    
UART_UartPutString("\r\n");   
   

However, all that the serial monitor prints is a dash!

   

Any suggestions on how else to send an integer over UART? thanks 🙂

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

sprintf() needs some settings to work:

   

In "Project -> Build settings -> Linker" you'll have to set "Use newlib nano" and "Use newlib nano float formatting"

   

In .cydwr-view (where you assign the pins) under "System" tab set the heap size to 0x100, better 0x200.

   

 

   

Happy coding

   

Bob

View solution in original post

5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

sprintf() needs some settings to work:

   

In "Project -> Build settings -> Linker" you'll have to set "Use newlib nano" and "Use newlib nano float formatting"

   

In .cydwr-view (where you assign the pins) under "System" tab set the heap size to 0x100, better 0x200.

   

 

   

Happy coding

   

Bob

Anonymous
Not applicable

Hi Bob,thanks for the input.

   

Made the linker chnages.

   

cant seem to edit heap size....its fixed/non editable.

meanwhile, no outputs - not even dashes as i ws getting earlier

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

You can't edit the heap size while debugging.

   

 

   

Bob

moro_1580446
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

hi mr vedant.prusty.could u runing adxl345 with spi?because i cant volved this problem!!!

   

can u give me your project for learning how i can to do?

   

tanks...

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

It would be very nice to stop flooding the forum with your requests which are all the same.

   

Obviously no one here is able (willing) to provide you with a complete project, so you need to learn from the examples or videos that you can access from creator. When you have got a complete project that builds without errors/warnings you may post a workspace bundle together with some description what runs and what does not run. Based on that there will be someone to help you.

   

 

   

Bob

0 Likes