09-22-2009 01:31 PM
I am working on a Hardware in the Loop application involving microblaze and simulink communicating each other serially.
Till the time I receive and send 8 bit data, things are okay but I am unable to perform 16 or 32 bit data send and receive with Simulink.
Can someone please give me an advice.Thanks
my code is as under:
#include "xparameters.h"
#include "xstatus.h"
#include "xbasic_types.h"
#include "xuartlite.h"
int main (void)
{
int err;
for (;;) //infinite loop09-30-2009 02:15 AM
Dear Brother Prateek
I am thankful to you for taking interest and being considerate to solve my problem.
My problem has been solved. Your previous message regarding reading uart byte by byte helped me a lot. After receiving those bytes i combined them to for 32 bit number using following listing. And for the float numbers i used scaling technique i.e multiplying my number to a scaling factor (e.g 1000) and transmitting it over serial channel and upon receivng i divided it by the same scaling factor. by doing so preceision upto three decimal places was preserved witout going into comlications of float numbers.
This is how i reconstructed the 32 bit number received from simulink, in microblaze.
i[0]=XUartLite_RecvByte(0x40600000); //Reads least significant byte i[1]=XUartLite_RecvByte(0x40600000); i[2]=XUartLite_RecvByte(0x40600000); i[3]=XUartLite_RecvByte(0x40600000); err[temp]=i[0]+i[1]*256+i[2]*256*256+i[3]*256*256*256;
Thankyou and Best regards
suhaider
09-22-2009 10:11 PM
Hello.
As far as UART is concerned it is a serial protocol with byte transfer only.
That is UART can only send and receive a byte at a time.
So in your code you will have to break the 32 bit number coming from simulink into four numbers of 8bit and then you send these four 8 bit numbers on UART one by one to microblaze.
Similarly you will have to break the 32 bit number coming from microblaze into four 8 bit numbers and send these four numbers through UART one by one to simulink.
For example,
int main (void)
{
int err1,err2,err3,err4;
for (;;) //infinite loop
{
err1=XUartLite_RecvByte(0x40600000);
xil_printf("%d", err1);
err2=XUartLite_RecvByte(0x40600000);
xil_printf("%d", err2);
err3=XUartLite_RecvByte(0x40600000);
xil_printf("%d", err3);
err4=XUartLite_RecvByte(0x40600000);
xil_printf("%d", err4);
}
}
09-23-2009 08:02 PM
Dear prateek thanks for your advice .
It is difficult tp perform byte operations in Simulink.
Another expert is suggesting to use :
unsigned int XUartLite_Send(XUartLite *InstancePtr, u8 *DataBufferPtr, unsigned int NumBytes);
unsigned int XUartLite_Recv(XUartLite *InstancePtr, u8 *DataBufferPtr, unsigned
What do you think?.
Regards
09-23-2009 09:52 PM
Hello.
It seems to be a good solution except that the function is non blocking. You will have to play with interrupts or you have to continously poll.
09-25-2009 03:08 AM
Can you please direct me to an example code for using the uartlite in in this way (i.e use with interrupts)?
Thankyou.
09-29-2009 12:31 AM
09-30-2009 02:15 AM
Dear Brother Prateek
I am thankful to you for taking interest and being considerate to solve my problem.
My problem has been solved. Your previous message regarding reading uart byte by byte helped me a lot. After receiving those bytes i combined them to for 32 bit number using following listing. And for the float numbers i used scaling technique i.e multiplying my number to a scaling factor (e.g 1000) and transmitting it over serial channel and upon receivng i divided it by the same scaling factor. by doing so preceision upto three decimal places was preserved witout going into comlications of float numbers.
This is how i reconstructed the 32 bit number received from simulink, in microblaze.
i[0]=XUartLite_RecvByte(0x40600000); //Reads least significant byte i[1]=XUartLite_RecvByte(0x40600000); i[2]=XUartLite_RecvByte(0x40600000); i[3]=XUartLite_RecvByte(0x40600000); err[temp]=i[0]+i[1]*256+i[2]*256*256+i[3]*256*256*256;
Thankyou and Best regards
suhaider