element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
ZedBoard Hardware Design Pmod BT2 and SD memory card
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 2 replies
  • Subscribers 325 subscribers
  • Views 643 views
  • Users 0 members are here
Related

Pmod BT2 and SD memory card

dagor
dagor over 7 years ago
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:
 
https://reference.digilentinc.com/learn/programmable-logic/tutorials/pmod-ips/start
 
https://embeddedcentric.com/data-logging-using-sd-cards/
 
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
  • Sign in to reply
  • Cancel
  • jafoste4
    0 jafoste4 over 7 years ago

    Hello,

    For educational support please ask your question over at the Digilent support forum.

    Thank you,

    Josh

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dagor
    0 dagor over 7 years ago in reply to jafoste4

    Hello JFoster.

    I am going to do that. thanks a lot.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube