- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a strange problem with the psoc 4 uart when sending and receiving raw hex data. from i2C.
from one psoc to another ....for processing
on just one psoc i have no problems with getting the i2c sensor data and converting it to floating point then using the
sprintf function and UART_uartutString(msg) to display it on the screen.
all works fine and I am able to send sensor data to a pc via uart no problems.
Now if i try to send the sensor values as raw hex straight over uart using the UART_Uart PutChar(byte)
There's no problem sending the bytes or receiving them as hex as expected. I can test a variable and display the hex values as
interpreted by the uart on the screen or use a logic analyzer to see the raw values.
When i try to convert the raw hex values to floating point at the receiving end. And then as before using the sprint function for to display the floating point values all i see is 00.000 displayed on the screen for example the variables that have been initiated are not zero they contain hex but when i try to convert the values to floating point are not displayed.
This worked at the sending side doing all the processing locally at that end. Can someone explain help.
if you want to limit the bandwidth by just ending raw hex then doing the processing at the receiving side such as wanting to store the results in an array for processing.
and doing the conversion from int to float at the receiving end instead of the sending end. It seems strange why i am unable to do this. yet it works at the transmitting end.
can someone explain? or offer a solution to this problem?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Reading the post, I wondered what the size of a float is?
So I wrote the following test program, and found that a float is 4 byte variable.
#include "project.h"
#include <stdio.h>
#define print(s) UART_UartPutString(str) ;
char str[128] ; /* print buffer */
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
}
int main(void)
{
float f_value ;
size_t var_size ;
unsigned long l_value ;
init_hardware() ;
sprintf(str, "Converting Float to Hex test (%s %s)\n\r", __DATE__, __TIME__) ;
UART_UartPutString(str) ;
var_size = sizeof(f_value) ;
sprintf(str, "Size of float is %d\n\r", var_size) ;
print(str) ;
f_value = 1.2345 ; // 1.2345 = 0x3F9E0419
sprintf(str, "float value: %.4f is 0x%08X\n\r", f_value, *((unsigned long *)&f_value)) ;
print(str) ;
l_value = 0x3F9E0419 ;
sprintf(str, "unsigned long 0x%08X is %.4f if converted as float\n\r",
l_value, *((float *)&l_value)) ;
print(str) ;
while(1) { }
}
Tera Term log
So I think that you need to send/receive 4 bytes for each float value.
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @smev_4172901 ,
Please confirm for me the raw data (without converting it into a floating point) received from the sensor you are transferring one PSoC (Master) to another PSoC (Slave) using UART_UartPutChar().
and also you are referring transmitting end as one PSoC 4(Master) which is receiving Sensor data and receiving end as another PSoC 4 (Slave) which is getting sensor data from Master PSoC right?
Can you check whether you are writing UART_UartPutString() function after sprint function to view the data on the Serial Terminal in the Receiving end code?
Also please share the code written for the transmitting end and receiving end.
Thanks and regards,
Sidramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sidra,
I have two 8 bit arrays which contain the sensor Data in hex at the transmitting side.
sequential transmission of the two bytes e.g
UART_Uart_PutChar(Start_sequence);
UART_Uart_PutChar(Byte(0)) ; sensor lower hex value
UART_Uart_PutChar(Byte(1)) ; sensor upper hex value
all processing at the receiver.
interrupt routine outline
look for the start of the sequence using UART_Uart_PutChar(Start_sequence);
main program
using UART_UartGetChar(Incoming_byte);
store in an array at index i
For some reason i get a warning when using arrays with an interrupt:
So the variables are not able to be used and i get zeros in the sprintf function as explained above
error message variable set but not used. I tried many ways to fix this error and i have not succeeded.
i am obviously doing something wrong
I hope this makes things more clearer.
Could you explain how to take the incoming hex values and store them in an array. and to display them using the psoc code example? is much appreciated.
Thank you for your reply.
smev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @smev_4172901 ,
Please find the attachment of the project where I have taken the CE224406 – PSoC 4 UART_Interrupt code example.
In the main program, I changed the code to store 5 characters in an array and I am displaying all values within an array once it is full.
Hope it was useful.
Thanks and regards,
Sidramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Reading the post, I wondered what the size of a float is?
So I wrote the following test program, and found that a float is 4 byte variable.
#include "project.h"
#include <stdio.h>
#define print(s) UART_UartPutString(str) ;
char str[128] ; /* print buffer */
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
}
int main(void)
{
float f_value ;
size_t var_size ;
unsigned long l_value ;
init_hardware() ;
sprintf(str, "Converting Float to Hex test (%s %s)\n\r", __DATE__, __TIME__) ;
UART_UartPutString(str) ;
var_size = sizeof(f_value) ;
sprintf(str, "Size of float is %d\n\r", var_size) ;
print(str) ;
f_value = 1.2345 ; // 1.2345 = 0x3F9E0419
sprintf(str, "float value: %.4f is 0x%08X\n\r", f_value, *((unsigned long *)&f_value)) ;
print(str) ;
l_value = 0x3F9E0419 ;
sprintf(str, "unsigned long 0x%08X is %.4f if converted as float\n\r",
l_value, *((float *)&l_value)) ;
print(str) ;
while(1) { }
}
Tera Term log
So I think that you need to send/receive 4 bytes for each float value.
moto