cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
suhaider
Visitor
Visitor
7,685 Views
Registered: ‎09-21-2009

I need help in 32 bit serial communication between microblaze and simulink

Jump to solution
Hi,

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 loop
 {
   err=XUartLite_RecvByte(0x40600000);
   xil_printf("%d", err);
 }              
}
0 Kudos
1 Solution

Accepted Solutions
suhaider
Visitor
Visitor
9,175 Views
Registered: ‎09-21-2009

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

View solution in original post

0 Kudos
6 Replies
prateek_bhatt
Scholar
Scholar
7,675 Views
Registered: ‎08-21-2008

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);
}
}

 

Best of luck.
--
Unlimited in my Limits.
suhaider
Visitor
Visitor
7,644 Views
Registered: ‎09-21-2009

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

0 Kudos
prateek_bhatt
Scholar
Scholar
7,639 Views
Registered: ‎08-21-2008

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. 

Best of luck.
--
Unlimited in my Limits.
0 Kudos
suhaider
Visitor
Visitor
7,621 Views
Registered: ‎09-21-2009

 

Can you please direct me to an example code for using the uartlite in in this way (i.e use  with interrupts)?

Thankyou.

0 Kudos
prateek_bhatt
Scholar
Scholar
7,590 Views
Registered: ‎08-21-2008

Hello.

I do have one project but its not for some length of data rather it is for byte only. 

In your MHS file take UART and enable interrupt along with it.

Rest the C file i am attaching here. 

Best of luck.
--
Unlimited in my Limits.
0 Kudos
suhaider
Visitor
Visitor
9,176 Views
Registered: ‎09-21-2009

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

View solution in original post

0 Kudos