I am a beginner with zedboard. I want to connect two Pmod BT and see the data received in a terminal of sdk and write it in a SD memory card. My block design is in Vivado 2014.3. When I run the application project without SD memory part, it works fine, but when I add the SD inicialization and write code, it don´t work.
I heve based the project in these tutorials:
This is my code
#include "xil_cache.h"
#include "xparameters.h"
#include "PmodBT2.h"
#include "xbasic_types.h"
#include "xscugic.h"
#include "xil_exception.h"
#include "xsdps.h"
#include "xil_printf.h"
#include "ff.h"
static FATFS FS_instance; // File System instance
static FIL file1; // File instance
FRESULT result; // FRESULT variable
static char FileName[32] = "received_data.txt"; // name of the log
static char *Log_File; // pointer to the log
char *Path = "0:/"; // string pointer to the logical drive number
unsigned int BytesWr, BytesRd;
u8 Buffer_logger_0[32] __attribute__ ((aligned(32))); // Buffer should be word aligned (multiple of 4)
u8 Buffer_logger_1[32] __attribute__ ((aligned(32))); // Buffer should be word aligned (multiple of 4)
u32 Buffer_size = 32, line_size;
//required definitions for sending & receiving data over the host board's UART port
#include "xuartps.h"
typedef XUartPs SysUart;
#define SysUart_Send XUartPs_Send
#define SysUart_Recv XUartPs_Recv
#define SYS_UART_DEVICE_ID XPAR_PS7_UART_1_DEVICE_ID
#define BT2_UART_AXI_CLOCK_FREQ 100000000
PmodBT2 myDevice1, myDevice2;
SysUart myUart;
void DemoInitialize();
void DemoRun();
void SysUartInit();
void EnableCaches();
void DisableCaches();
int main()
{
// Mount SD Card and initialize device
result = f_mount(&FS_instance,Path, 0);
// Open log for writing
Log_File = (char *)FileName;
result = f_open(&file1, Log_File, FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
if (result!= 0) {
return XST_FAILURE;
}
DemoInitialize();
DemoRun();
return XST_SUCCESS;
}
void DemoInitialize()
{
SysUartInit();
BT2_Begin (
&myDevice1,
XPAR_PMODBT2_0_AXI_LITE_GPIO_BASEADDR,
XPAR_PMODBT2_0_AXI_LITE_UART_BASEADDR,
BT2_UART_AXI_CLOCK_FREQ,
115200
);
BT2_Begin (
&myDevice2,
XPAR_PMODBT2_1_AXI_LITE_GPIO_BASEADDR,
XPAR_PMODBT2_1_AXI_LITE_UART_BASEADDR,
BT2_UART_AXI_CLOCK_FREQ,
115200
);
}
void DemoRun()
{
u8 buf[1];
int n;
xil_printf("Initialized PmodBT2 Demo, received data will be echoed here, type to send data\r\n");
while(1) {
n = SysUart_Recv(&myUart, buf, 1);
if (n != 0) {
SysUart_Send(&myUart, buf, 1);
BT2_SendData(&myDevice1, buf, 1);
BT2_SendData(&myDevice2, buf, 1);
}
n = BT2_RecvData(&myDevice1, buf, 1);
if (n != 0) {
SysUart_Send(&myUart, buf, 1);
sprintf(Buffer_logger_0, "%s", buf);
Log_File = (char *)FileName;
result = f_open(&file1, Log_File,FA_WRITE);
if (result!=0) {
return XST_FAILURE;
}
result = f_write(&file1, (const void*)Buffer_logger_0, Buffer_size, &BytesWr);
result = f_close(&file1);
result = f_mount(NULL, Path, 0);
xil_printf("Data written to log Successfully\r\n");
}
n = BT2_RecvData(&myDevice2, buf, 1);
if (n != 0) {
SysUart_Send(&myUart, buf, 1);
sprintf(Buffer_logger_0, "%s", buf);
Log_File = (char *)FileName;
result = f_open(&file1, Log_File,FA_WRITE);
if (result!=0) {
return XST_FAILURE;
}
result = f_write(&file1, (const void*)Buffer_logger_0, Buffer_size, &BytesWr);
result = f_close(&file1);
result = f_mount(NULL, Path, 0);
xil_printf("Data written to log Successfully\r\n");
}
}
}
//initialize the system uart device, AXI uartlite for microblaze, uartps for Zynq
void SysUartInit()
{
XUartPs_Config *myUartCfgPtr;
myUartCfgPtr = XUartPs_LookupConfig(SYS_UART_DEVICE_ID);
XUartPs_CfgInitialize(&myUart, myUartCfgPtr, myUartCfgPtr->BaseAddress);
}
¿Can anybody tell me what is the mistake and how can i correct it?
I appreciate thehelp
regards