[MCU] 【MSP432评测】 -- 2、串口0驱动输出

[复制链接]
771|1
 楼主| tlled 发表于 2020-4-18 15:37 | 显示全部楼层 |阅读模式
本帖最后由 tlled 于 2020-4-18 15:37 编辑

    测试串口0输出信息。

    一、安装XDS110-ET驱动程序

    XDS110-ET带有串口,使用MSP432P401R的串口0输出。
    驱动下载地址:https://software-dl.ti.com/ccs/esd/documents/xdsdebugprobes/emu_xds_software_package_download.html
    安装完成后会找到串口号。   

    二、硬件电路

   串口0使用的是P1.2和P1.3端口,可以连接XDS110-ET仿真器。
   
   
    三、程序
   
    3.1、main.c
  1. #include "config.h"


  2. /* Initializes Clock System */
  3. void CS_init()
  4. {
  5.     /* Set the core voltage level to VCORE1 */
  6.     MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);

  7.     /* Set 2 flash wait states for Flash bank 0 and 1*/
  8.     MAP_FlashCtl_setWaitState(FLASH_BANK0, 2);
  9.     MAP_FlashCtl_setWaitState(FLASH_BANK1, 2);

  10.     /* Initializes Clock System */
  11.     MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
  12.     MAP_CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
  13.     MAP_CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
  14.     MAP_CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1 );
  15.     MAP_CS_initClockSignal(CS_ACLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
  16. }


  17. int main(void)
  18. {
  19.     uint32_t i;
  20.                 MAP_WDT_A_holdTimer();
  21.                 MAP_Interrupt_disableMaster();
  22.                 CS_init();
  23.                 LED_Init();
  24.                 UART0_Init();
  25.     while(1)
  26.     {
  27.                                 UART0_transmitString( "www.21ic.com -- msp432p401r\r\n" );
  28.                                 for(i=1000000; i>0; i--);
  29.     }
  30. }

   3.2、uart.c

  1. #include "config.h"


  2. const eUSCI_UART_ConfigV1 uart0Config =
  3. {
  4.         EUSCI_A_UART_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
  5.                                 26,                                      // BRDIV = 26
  6.         1,                                       // UCxBRF = 1
  7.         0,                                       // UCxBRS = 0
  8.         EUSCI_A_UART_NO_PARITY,                  // No Parity
  9.         EUSCI_A_UART_LSB_FIRST,                  // LSB First
  10.         EUSCI_A_UART_ONE_STOP_BIT,               // One stop bit
  11.         EUSCI_A_UART_MODE,                       // UART mode
  12.         EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION,  // Oversampling
  13.         EUSCI_A_UART_8_BIT_LEN                  // 8 bit data length
  14. };

  15. void UART0_initGPIO(void)
  16. {
  17.     /* Selecting P1.2 and P1.3 in UART mode */
  18.     MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1,GPIO_PIN2 | GPIO_PIN3,
  19.                                                                                                                                                                                                                 GPIO_PRIMARY_MODULE_FUNCTION);
  20. }

  21. void UART0_Init(void)
  22. {
  23.                 UART0_initGPIO();
  24.     MAP_UART_initModule(EUSCI_A0_BASE, &uart0Config);   /* Configuring UART Module */
  25.     MAP_UART_enableModule(EUSCI_A0_BASE);/* Enable UART module */

  26.         return;
  27. }

  28. /* Transmits String over UART */
  29. void UART0_transmitString( char *pStr )
  30. {
  31.         while( *pStr )
  32.         {
  33.                 UART_transmitData(EUSCI_A0_BASE, *pStr );
  34.                 pStr++;
  35.         }
  36. }


  3.3、 uart.h
  1. #ifndef FUN_UART_H_
  2. #define FUN_UART_H_

  3. void UART0_Init(void);
  4. void UART0_transmitString( char *pStr );

  5. #endif
   3.4、程序源码
   

   四、执行结果

    串口输出数据:
   



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
21ic小喇叭 发表于 2020-4-20 14:43 | 显示全部楼层
感谢分享,奖励您500家园币
您需要登录后才可以回帖 登录 | 注册

本版积分规则

132

主题

701

帖子

7

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