The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board - The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board Hello Admin, I am newbie in the field SOC- FPGA. I need to do a project for my thesis but I have encountered a problem that I spent a lot of time but couldn't fix. I really need admin help. Thank you so much for reading this post of mine. The error is: I write C code to control IP UART (rs232 serial port) send data to the Tx pin and use the uart to usb module (CP2102) to receive data but the received data shows up wrong with the transmitted data. For example, transmitting the character "PLEASE" will get "O"; "1234" get "Ê",... Connect hardware (1) Connect hardware (2) data received from CP2102 displayed on hercules terminal I made the project with the following steps: 1. Add ip into GHRD project Qsys connection address map QSYS(1) address map QSYS(2) address map QSYS(3) 2. Assignments pin Assignments pin (GPIO 6 - RX, GPIO7-TX) File top.v(1) File top.v(2) 3. File hex use for code C Define for IP UART 4. FILE CODE C: admin, please help me check carefully the C code that has set baudrate and especially send the data, is it correct? #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> #include "hwlib.h" #include "socal/socal.h" #include "socal/hps.h" #include "socal/alt_gpio.h" #include "hps_0.h" #include <string.h> #define HW_REGS_BASE ( ALT_STM_OFST ) #define HW_REGS_SPAN ( 0x04000000 ) #define HW_REGS_MASK ( HW_REGS_SPAN - 1 ) void uart_putc(char c ,unsigned long *h2p_lw_uart_addr) { unsigned short uart_status; do{ uart_status = *(h2p_lw_uart_addr + 2); }while(!(uart_status & 0x40)); *(h2p_lw_uart_addr + 1) = c; } void uart_printf(char *str ,unsigned long *h2p_lw_uart_addr) { while(*str != '\0') { uart_putc(*str ,h2p_lw_uart_addr); str++; } } int uart_getc(unsigned long *h2p_lw_uart_addr) { unsigned short uart_status; do { uart_status = *(h2p_lw_uart_addr + 2); } while (!(uart_status & 0x80)); return *(h2p_lw_uart_addr + 0); } int uart_scanf(char *p,unsigned long *h2p_lw_uart_addr) { int cnt = 0; while (1) { *p = uart_getc(h2p_lw_uart_addr); cnt++; if (*p == '\n') return cnt; else p++; } } int main() { void *virtual_base; int fd; int i; unsigned long *h2p_lw_uart_addr; // map the address space for the LED registers into user space so we can interact with them. // we'll actually map in the entire CSR span of the HPS since we want to access various registers within that span if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) { printf( "ERROR: could not open \"/dev/mem\"...\n" ); return( 1 ); } virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE ); if( virtual_base == MAP_FAILED ) { printf( "ERROR: mmap() failed...\n" ); close( fd ); return( 1 ); } h2p_lw_uart_addr=(unsigned long*) (virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + UART_0_BASE ) & ( unsigned long)( HW_REGS_MASK ) ));//uart地址 //h2p_lw_uart_addr=(unsigned long *)(virtual_base + ( ( unsigned long )( ALT_LWFPGASLVS_OFST + UART_0_BASE ) & ( unsigned long)( HW_REGS_MASK )));//uart地址 // toggle the LEDs a bit *(h2p_lw_uart_addr + 4) = (int) ((UART_0_FREQ / UART_0_BAUD)-1) ; //*(h2p_lw_uart_addr + 4) = (int) ((UART_0_FREQ / UART_0_BAUD)+1) ; I tried but not correct //*(h2p_lw_uart_addr + 4) = (int) (UART_0_FREQ / UART_0_BAUD + 0.5); I tried but not correct char c[20]="PLEASE"; while( 1 ) { // control led // wait 100ms uart_printf(&c[0],h2p_lw_uart_addr); usleep( 100*1000 ); } // while // clean up our memory mapping and exit if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) { printf( "ERROR: munmap() failed...\n" ); close( fd ); return( 1 ); } close( fd ); return( 0 ); } ------------------------------------------- Thank you very much admin. I hope you have amazing day. Regards, Kai. Replies: Re: The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board Hi, I’m glad that your question has been addressed, I now transition this thread to community support. If you have a new question, Please login to ‘ https://supporttickets.intel.com’ , view details of the desire request, and post a feed/response within the next 15 days to allow me to continue to support you. After 15 days, this thread will be transitioned to community support. The community users will be able to help you on your follow-up questions. p/s: If any answer from the community or Intel Support are helpful, please feel free to give best answer or rate 4/5 survey. Replies: Re: The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board Hi Thank you so much for your support. I succeeded in this application. Regards, Kai Replies: Re: The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board Hi, Did you had issue with the Intel example item no 3? Replies: Re: The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board Hi, I am not familiar with these example design, so I may only give the best support for this issue. Also, I advise that you consult Terasic on your project for your DE10 board. Replies: Re: The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board Hi EBERLAZARE_I_In tel, connect hardware The first, I have looked for examples of uart of this IP but there are very few examples and only got 1 example made with the GHRD project from this links: 1. https://blog.csdn.net/weixin_43649647/article/details/121069892 2. Page 140 to page 155: https://www.intel.com/programmable/technical-pdfs/683130.pdf 3. Project example for Nios (but I must use with GHRD): https://www.intel.com/content/www/us/en/design-example/715139/cyclone-v-uart-rs-232-maximum-baud-rate-reference-design.html?wapkw=uart Secondly, I got project GHRD from Terasic (CD Rom) or You can get at link I was upload: https://drive.google.com/file/d/1Bse1dQUNYEjjC0GkylL1VpXxlSVzFtoI/view?usp=sharing Also, I think this problem may be caused by asynchronous transfer speed (baundrate) of the two devices or another error? But I don't know how to fit it. please help me to fix this error of wrong data transmission. Thank you very much. Regards, Kai Replies: Re: The problem of wrong data transmission using ip uart (rs232 serial-port) with de10 standard board Hi, Since your board is Terasic based, it is best that you also get help from Terasic. Do they have an example for this? Maybe a simple Hello World, and we can work from there. Also, where did you get this GHRD? Is it from Terasic? - 2023-07-09

external_document