This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

串口配置

Other Parts Discussed in Thread: EK-TM4C1294XL, TM4C1294NCPDT, EK-TM4C123GXL

使用MDk编译时出现错误,函数是GPIOPinConfigure();

芯片型号是ek-tm4c1294xl

user\chuankou.c(17): error: #20: identifier "GPIO_PC4_U7Rx" is undefined
user\chuankou.c(18): error: #20: identifier "GPIO_PC5_U7Tx" is undefined

  • 确认源码中包含了头文件:#include "driverlib/pin_map.h"

    增加器件型号定义,Keil是在工程设置~CC~Predefined Symbols里面的Define:填入PART_TM4C1294NCPDT和TARGET_IS_SNOWFLAKE_RA1

  • 谢谢,已经解决了。但是你看一下我的串口程序:uartPuts("hello world!");//这个函数进不去是什么原因,单个字符就可以发出去,我找不出原因

    #include <stdint.h>
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdbool.h>
    #include <sysctl.h>
    #include "hw_gpio.h"
    #include <hw_memmap.h>
    #include "gpio.h"
    #include "uart.h"
    #include "SystemInit.h"
    #include "pin_map.h"
    #include "string.h"
    void uartInit()
    {
     SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6);//ʹÄÜUARTÄ£¿é
     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); //ʹÄÜRX/TXËùÔÚµÄGPIO¶Ë¿Ú
     GPIOPinTypeUART(GPIO_PORTP_BASE, GPIO_PIN_0|GPIO_PIN_1);
     GPIOPinConfigure(GPIO_PP0_U6RX);
     GPIOPinConfigure(GPIO_PP1_U6TX);
     UARTConfigSetExpClk(UART6_BASE,  //ÅäÖÃUART¶Ë¿Ú
               TheSysClock,   //
                  9600,  //²¨ÌØÂÊΪ9600
           UART_CONFIG_WLEN_8|  //8¸öÊý¾Ýλ
          UART_CONFIG_STOP_ONE|  //Ò»¸öֹͣλ
          UART_CONFIG_PAR_NONE); //ÎÞУÑé
     
     UARTEnable(UART6_BASE);//ʹÄÜUART¶Ë¿Ú
     
    }

    //´®¿Ú·¢ËÍ×Ö·û´®º¯Êý
    void uartPuts(char *s)
    {
     uint32_t len=strlen(s)-1;
     uint32_t i;
     for(i=0;i<len;i++)
      UARTCharPut(UART6_BASE,s[i]);

    }

    int main(void)
    {
     char c;
     jtagWait();//·ÀÖ¹JTAGʧЧ
     clockInit();//ʱÖÓ³õʼ»¯
     uartInit();//UART³õʼ»¯
     uartPuts("hello world!");//
     for(;;)
     {
      c=UARTCharGet(UART6_BASE);//µÈ´ý½ÓÊÜ×Ö·û
      UARTCharPut(UART6_BASE,c);
      if(c=='\r')
      {
       UARTCharPut(UART6_BASE,'\n');
      }

     }

    }

     

     

  • 串口的收发数据程序请参考:

    TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c123gxl\uart_echo

    这里面发送单个字节,多个字节的用法都有。

  • 请问一下,串口的发送数据一定要用到中断吗?我看了好多例子都是这样的

  • 都可以。如果发送的数据量很大,用中断发可以节省MCU开销。

    如果数据量小,用查询方式也没问题。而且我们的Tiva系列MCU的串口带FIFO的,小于16字节的数据可以直接都写入fifo,程序不用等待。