cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Bish_Lei
Visitor
Visitor
140 Views
Registered: ‎03-14-2021

MicroBlaze Uart Communication using EDK

I am  developing a Embedded system  using microblaze in Spartan 6 lx150 fgg 900 for serial communication using UART and PLB bus interface.

But in my sdk code I want to accept my multiple byte sequence. Not only one sequence but sequence after sequence.I use simple for loops and the XUartLite_RecvByte function in my code.But the outerfor loop in my code is running once to accept the fisrt sequence only.And the loop stops without any error and the FPGA programme comples without any error but it is behaving as I am expecting.

I have attatched the code here.

#include<stdio.h>
#include"xparameters.h"
#include"xuartlite.h"
#include"xuartlite_i.h"
#include "xuartlite_l.h"
#include"xbasic_types.h"
#include"xstatus.h"

#define buffersize 11
#define uart_id XPAR_UARTLITE_1_DEVICE_ID
#define uart_baseadd XPAR_UARTLITE_1_BASEADDR

XUartLite Uart;

u8 C;
u8 RecvBuffer[buffersize]={0};
//u8 *RecvBufferPtr=&RecvBuffer[0];
int i=0,j;
u8 CS=0x00;

void resetbuffer();
void printbuffer();
void delay(int );

//start the main function

int main()
{
int Status;

//Initialize Uart device
Status=XUartLite_Initialize(&Uart,uart_id);
if(Status!=XST_SUCCESS)
xil_printf("\n....Init Failure....\n");
xil_printf("Start Receiving\n");
RecvBuffer[0]=XUartLite_RecvByte(uart_baseadd);
for(j=0;j<3;j++)
{
if(RecvBuffer[0]==0x02)
{
xil_printf("%c",RecvBuffer[0]);
for(i=1;i<buffersize;i++)
{
RecvBuffer[i]=XUartLite_RecvByte(uart_baseadd);
xil_printf("%c",RecvBuffer[i]);
delay(5);
}
}
for(i=3;i<9;i++)
{
CS+=RecvBuffer[i];
}
if((CS & 0xFF)==RecvBuffer[9])
{
xil_printf("\nCorrect Message\n");
}


/*XUartLite_ResetFifos(&Uart);
delay(100);
resetbuffer();*/
xil_printf("Start Receiving again\n");
delay(5);
RecvBuffer[0]=XUartLite_RecvByte(uart_baseadd);
}

return 0;

}

 


///printBuffer function
/*void printbuffer()
{
xil_printf("I am in print buffer\n");
i=0;
while(i<buffersize)
{
xil_printf("%c",RecvBuffer[i]);
i++;
//delay(2);
}
}*/


///resetbuffer function
void resetbuffer()
{
for(i=0;i<buffersize;i++)
{
RecvBuffer[i]=0;
}
}


//delay function

void delay(int n)
{
int i;
for(i=0;i<n;i++)
{
for(j=0;j<n/2;j++)
{

}
}
}

 

 

 

Some other additional problems I am facing are

1. infinite loops are not   working.

2. The XUartLite_RecvByte is not waiting for the user to send the byte.

3. Unable to run theapplication.

Error: Unable to connect to MicroBlaze.Microblaze is under reset.

0 Kudos
0 Replies