MSPML1306小练--外部连接TX和RX串口数据FIFO发送和接收

[复制链接]
 楼主| xyz549040622 发表于 2024-1-20 18:47 | 显示全部楼层 |阅读模式
开发板:LP-MSPM0L1306 LaunchPad
例程说明:通过短接TX和RX的引脚,让TX的数据直接发送到RX引脚上,来实现串口发送和接收的例程。使用FIFO的方式实现串口的发送和接收。如果发送和接收都完成,用户LED会闪烁,如果发送和接收没完成,用户LED常亮。
开发板的操作:需要断开J101上TXD和RXD与XDS110-ET下载板的连接,短接TXD与RXD。
例程分析:
1、首先是串口的配置,波特率照常配置,只需要使能FIFO,以及配置发送和接收FIFO的长度即可
屏幕截图 2024-01-20 184652.png
2、代码如下所示:
  1. #include "ti_msp_dl_config.h"

  2. /*
  3. * Configure the internal loopback mode.
  4. * Note that data received on the UART RXD IO pin will be ignored when
  5. * loopback is enabled.
  6. */
  7. #define ENABLE_LOOPBACK_MODE true

  8. /*
  9. * Number of bytes for UART packet size
  10. * The packet will be transmitted by the UART.
  11. * This example uses FIFOs with polling, and the maximum FIFO size is 4.
  12. * Refer to interrupt examples to handle larger packets.
  13. */
  14. #define UART_PACKET_SIZE (4)

  15. /* Delay for 5ms to ensure UART TX is idle before starting transmission */
  16. #define UART_TX_DELAY (160000)

  17. /* Data for UART to transmit */
  18. uint8_t txPacket[UART_PACKET_SIZE] = {'M', 'S', 'P', '!'};

  19. /* Data received from UART */
  20. uint8_t rxPacket[UART_PACKET_SIZE];


  21. int main(void)
  22. {
  23.     SYSCFG_DL_init();//系统初始化

  24.     /* Optional delay to ensure UART TX is idle before starting transmission */
  25.     delay_cycles(UART_TX_DELAY);

  26.     /* Set LED to indicate start of transfer */
  27.     DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);

  28.     /* Fills TX FIFO with data and transmits the data */
  29.     DL_UART_Main_fillTXFIFO(UART_0_INST, &txPacket[0], UART_PACKET_SIZE);//填充数据发送数组并发送数据

  30.     /* Wait until all bytes have been transmitted and the TX FIFO is empty */
  31.     while (DL_UART_Main_isBusy(UART_0_INST))//等待数据发送完毕
  32.         ;

  33.     /*
  34.      * Wait to receive the UART data
  35.      * This loop expects UART_PACKET_SIZE bytes
  36.      */
  37.     for (uint8_t i = 0; i < UART_PACKET_SIZE; i++) {
  38.         rxPacket[i] = DL_UART_receiveDataBlocking(UART_0_INST);
  39.     }//循环接收发送的数据到接收缓存区,因为TX和RX对接了

  40.     /* If write and read were successful, toggle LED */
  41.     //假如发送和接收成功的话,才会进去下面的while循环
  42.     while (1) {
  43.         DL_GPIO_togglePins(GPIO_LEDS_PORT,
  44.             GPIO_LEDS_USER_LED_1_PIN | GPIO_LEDS_USER_TEST_PIN);
  45.         delay_cycles(5000000);
  46.     }
  47. }


您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:qq群: 嵌入式系统arm初学者 224636155←← +→→点击-->小 i 精品课全集,21ic公开课~~←←→→点击-->小 i 精品课全集,给你全方位的技能策划~~←←

2841

主题

19330

帖子

110

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