[DemoCode下载] ML51的PDMA传输串口数据到内存

[复制链接]
 楼主| 21mengnan 发表于 2025-1-25 14:29 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* SPDX-License-Identifier: Apache-2.0                                                                     */
  4. /* Copyright(c) 2020 Nuvoton Technology Corp. All rights reserved.                                         */
  5. /*                                                                                                         */
  6. /*---------------------------------------------------------------------------------------------------------*/

  7. #include "ml51.h"

  8. /* IMPORTANT !! This define for printf code only. Disable this define to reduce code size. */
  9. #define print_function
  10. /**
  11. * [url=home.php?mod=space&uid=247401]@brief[/url]        PDMA receiv from UART2(SC0) RX demo.
  12. * @param       None
  13. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  14. * [url=home.php?mod=space&uid=1543424]@Details[/url]     after PDMA transfer done UART2 RX data in XRAM 0x100 start area.
  15. */

  16. unsigned char xdata RxDatabuffer[100] _at_ 0x100;
  17. unsigned char ct;
  18. bit pdmaflag = 0;

  19. void PDMA0_ISR(void) interrupt 20          // Vector [url=home.php?mod=space&uid=72445]@[/url]  0xA3
  20. {
  21.   PDMA_Close(PDMA0);
  22.   SFRS=0;DMA0TSR=0;
  23. }

  24. void main (void)
  25. {

  26. #ifdef print_function
  27.   /* UART0 initial setting
  28.   ** include uart.c in Library for UART initial setting
  29.   **UART0 define P3.1 TXD multi function setting
  30.   **/
  31.   Enable_UART0_VCOM_printf();
  32.   printf("\n PDMA receiv UART2 RX intial...");
  33. #endif
  34.    
  35. /* Enable UART2 RX */      
  36.     MFP_P55_UART2_RXD;
  37.     P55_INPUT_MODE;
  38.     UART_Open(24000000,UART2,115200);
  39.   
  40. /* Clear XRAM base address area to 00h */
  41.     for(ct=0;ct<10;ct++)
  42.     {
  43.       RxDatabuffer[ct]=0;
  44.     }
  45. /* Define PMDA function as UART RX to memory, define base address and PDMA receive length */   
  46.     PDMA_Open(PDMA0,SMCRX,0x100,100);
  47. /* Define interrupt after full transfer */
  48.     PDMA_Interrupt_Enable(PDMA0,PDMAFULLINT);
  49. /* Global interrupt enable */
  50.     ENABLE_GLOBAL_INTERRUPT;
  51. /* Start PDMA transfer */
  52.     PDMA_Run(PDMA0);
  53.    
  54.     while(!pdmaflag);
  55. #ifdef print_function
  56.     printf (" \n PDMA receiv UART2 RX finish! " );
  57. #endif

  58.     while(1);

  59. }





 楼主| 21mengnan 发表于 2025-1-25 14:30 | 显示全部楼层
ML51系列提供了丰富的库函数,用于操作这些复杂的操作。非常棒,好用
您需要登录后才可以回帖 登录 | 注册

本版积分规则

87

主题

1140

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部

87

主题

1140

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部