01-18-2016 01:26 PM
01-19-2016 09:18 AM
Many thanks @muzaffer! Now it is working!
I was not aware that the pointers always point to bytes, and depending on the type of its definition, they jump every 1, 2, 4, or 8 bytes according to its definition as char, short, int, or long respectively.
I was trying is to send an stack of double precision floating-point data (64bits or 8 bytes) to Matlab's Simulink. I was first having problems in sending the data from the Zynq and then figuring out how to configure the Serial Receive block to get all the data from the Zynq. So now it is working.
I post here all the info needed to get this working.
On Simulink, the Serial Configuration block has to be:
Baud rate: 115200
Data bits: 8
Parity: none
Stop bits: 1
Byte order: LittleEndian
Flow control: none
Timeout: 10
And then the Serial Receive block:
Header: [empty]
Terminator: none
Data size: 1
Data type: double
And the code to be programmed on the Zynq can be this:
double stack[] = {1.0, 1.1, -1.1, 100000000}; char *chptr, x; chptr = (char*)&stack; for(x=0;x<8*sizeof(f);x++) XUartPs_SendByte(STDOUT_BASEADDRESS, *chptr++);
Many thanks for your help!
Cerilet
01-18-2016 02:50 PM - edited 01-18-2016 02:52 PM
yes it has to be sent byte per byte.
double precision represents data on 64bit, my guess is you could do something like
double f = 0.5; uint64_t *temp, bytes_sent; char *_to_send; temp = (uint64_t*)&temp; // binary value for 0.5 _to_send = temp; for( k=0; k < 64/8; k++ ) _bytes_sent = send_uart( _to_send, sizeof( char )); // send one byte _to_send += _bytes_sent; // one byte offset
you can do that with an array too, because your are always incrementing by one byte(8 bit) over 64
01-18-2016 07:20 PM
01-19-2016 01:53 AM
First of all, thanks for your quick reply.
To @guillaumebres: I do not understand what send_uart return to then make the assignation _to_send += _bytes_sent.
Apart from that, there is a mistake in here:
temp = (uint64_t*)&f;
To @muzaffer: When I said it does not work as expected is that I cannot reconstruct the data on the receiver's end.
Actually, I do not know how that instruction works (*chptr++). I was making some tests trying to figure out how the data is send and how an 8bit pointer increments if the system is 32bit but I could not.
If the memory on the Zynq is 32bit long, the pointer should point to a 32bit-length address, therefore, how can I point to one byte at a time? Moreover, how to send the data in the proper format to be recognized on the receiver's end: %c, %x, %d...?
Here the code I posted before, but now formatted and modified according to @muzaffer's suggestions:
double data = -1.234; unsigned char *chptr, x; chptr = (unsigned char *) &data; for(x=0;x<8;x++) { xil_printf("%c",*chptr++); }
Many thanks to both.
Cerilet
01-19-2016 02:07 AM
01-19-2016 09:18 AM
Many thanks @muzaffer! Now it is working!
I was not aware that the pointers always point to bytes, and depending on the type of its definition, they jump every 1, 2, 4, or 8 bytes according to its definition as char, short, int, or long respectively.
I was trying is to send an stack of double precision floating-point data (64bits or 8 bytes) to Matlab's Simulink. I was first having problems in sending the data from the Zynq and then figuring out how to configure the Serial Receive block to get all the data from the Zynq. So now it is working.
I post here all the info needed to get this working.
On Simulink, the Serial Configuration block has to be:
Baud rate: 115200
Data bits: 8
Parity: none
Stop bits: 1
Byte order: LittleEndian
Flow control: none
Timeout: 10
And then the Serial Receive block:
Header: [empty]
Terminator: none
Data size: 1
Data type: double
And the code to be programmed on the Zynq can be this:
double stack[] = {1.0, 1.1, -1.1, 100000000}; char *chptr, x; chptr = (char*)&stack; for(x=0;x<8*sizeof(f);x++) XUartPs_SendByte(STDOUT_BASEADDRESS, *chptr++);
Many thanks for your help!
Cerilet
04-27-2020 08:14 AM
Thank you for the solution.
for(x=0;x<8*sizeof(f);x++)
But, I don't understand. what's the f in this block.?
11-26-2020 12:45 PM
It's a double in @guillaumebres 's answer:
double f = 0.5; uint64_t *temp, bytes_sent; char *_to_send; temp = (uint64_t*)&temp; // binary value for 0.5 _to_send = temp; for( k=0; k < 64/8; k++ ) _bytes_sent = send_uart( _to_send, sizeof( char )); // send one byte _to_send += _bytes_sent; // one byte offset