Thread 中讨论的其他器件:CC3200、 CC3200MOD
工具/软件:Code Composer Studio
您好!
我对 UART 通信和配置有一些疑问。
我需要同时使用 uart1和 uart0 (我刚刚在 UART 演示中尝试过这么多、并读取了一些线程、例如:
)
CCS 是否有任何代码示例?
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.
工具/软件:Code Composer Studio
您好!
我对 UART 通信和配置有一些疑问。
我需要同时使用 uart1和 uart0 (我刚刚在 UART 演示中尝试过这么多、并读取了一些线程、例如:
)
CCS 是否有任何代码示例?
您好、Aju、
我不认为 CC3200有任何同时使用 UART0和 UART1的示例、因此必须由用户设置此配置。 您在上面附加的帖子包含有关如何执行此操作的具体说明。
另外、请参阅以下文章、了解各种 PIN_MODES 之间的差异:
https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/t/471553
大家好、Austin Tanner、
我在我发布的线程的帮助下编写了一个代码、但它不起作用、可以解释原因吗?、请建议错误
我的代码发布在下面。
(二 引脚多路复用器:
无效
PinMuxConfig (空)
{
//
//启用外设时钟
//
MAP_PRCMPeripheralClkEnable (PRCM_UARTA0、PRCM_RUN_MODE_CLK);
MAP_PRCMPeripheralClkEnable (PRCM_UARTA1、PRCM_RUN_MODE_CLK);
//
//为 UART0 UART0_TX 配置 PIN_55
//
MAP_PinTypeUART (PIN_55、PIN_MODE_3);
//
//为 UART0 UART0_RX 配置 PIN_57
//
MAP_PinTypeUART (PIN_57、PIN_MODE_3);
MAP_PinTypeUART (PIN_58、PIN_MODE_6);
//
//为 UART1 UART1_RX 配置 PIN_59
//
MAP_PinTypeUART (PIN_59、PIN_MODE_6);
}
(二 UART_IF.c
//标准包括
#include
#include
#include
#include
// Driverlib 包括
#include "hw_types.h"
#include "hw_memmap.h"
#include "prcm.h"
#include "pin.h"
#include "UART.h"
#include "rom.h"
#include "rom_map.h"
#if defined (use_freeRTOS)|| defined (use_TI_RTOS)
#include "OSI.h"
#endif
#include "UART_IF.h"
#define 是_space (x) (x = 32? 1:0)
//
//存在指示命令的全局变量
//
静态无符号长整型__Errorlog;
//
//指示输入长度的全局变量
//
unsigned int ilen=1;
//
//
//! 初始化
//!
//! 此函数
//! 配置要使用的 UART。
//!
//! \不返回任何内容
//
//
无效
InitTerm()
{
#ifndef NOTERM
MAP_UARTConfigSetExpClk (console、map_PRCMPeripheralClockGet (console_Periph)、
UART_BAUD_RATE、(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
MAP_UARTConfigSetExpClk (器件、MAP_PRCMPeripheralClockGet (DEVICE_PERIPh)、
UART_BAUD_RATE、(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
#endif
_Errorlog = 0;
}
//
//
//! 向控制台输出字符串
//!
//! \param str 是要打印的字符串的指针
//!
//! 此函数
//! 1.将输入字符串字符逐字符打印到控制台。
//!
//! \不返回任何内容
//
//
无效
消息(const char *str)
{
#ifndef NOTERM
if (str!= NULL)
{
while (*str!='0')
{
MAP_UARTCharPut (device、* str++);
}
}
#endif
}
//
//
//! 清除控制台窗口
//!
//! 此函数
//! 1.清除控制台窗口。
//!
//! \不返回任何内容
//
//
无效
ClearTerm()
{
消息("\33[2J\r");
}
//
//
//! 误差函数
//!
//! \param
//!
//! \不返回任何内容
//!
//
无效
错误(char *pcFormat,...)
{
#ifndef NOTERM
char cBuf[256];
va_list 列表;
va_start (list、pcFormat);
vsnprintf (cBuf、256、pcFormat、list);
消息(cBuf);
#endif
_Errorlog++;
}
//
//
//! 从 UART 获取命令字符串
//!
//! \param pucBuffer 是将填充命令的命令存储区
//! \param ucBufLen 是可用的缓冲区存储的长度
//!
//! \接收到的字节的返回长度。 如果超过缓冲器长度、则为-1。
//!
//
内部
GetCmd (char * pcBuffer、unsigned int uiBufLen)
{
char cChar;
int iLen = 0;
//
//等待通过 UART 接收字符
//
while (map_UARTCharsAvail (device)== false)
{
#if defined (use_freeRTOS)|| defined (use_TI_RTOS)
OSI_SLEEP (1);
#endif
}
cChar = MAP_UARTCharGetNonBlocking (器件);
//
//回显接收到的字符
//
MAP_UARTCharPut (器件、cChar);
iLen = 0;
//
//检查命令结束
//
while ((cChar!='\r')&&(cChar!='\n'))
{
//
//处理缓冲区溢出
//
if (iLen >= uiBufLen)
{
返回-1;
}
//
//将数据从 UART 复制到缓冲区中
//
if (cChar!='\b')
{
*(pcBuffer + iLen)= cChar;
iLen++;
}
其他
{
//
//删除回退时的最后一个字符
//
IF (iLen)
{
iLen--;
}
}
//
//等待通过 UART 接收字符
//
while (map_UARTCharsAvail (device)== false)
{
#if defined (use_freeRTOS)|| defined (use_TI_RTOS)
OSI_SLEEP (1);
#endif
}
cChar = MAP_UARTCharGetNonBlocking (器件);
//
//回显接收到的字符
//
MAP_UARTCharPut (器件、cChar);
}
*(pcBuffer + iLen)='\0';
报告("\n");
返回 iLen;
}
//
//
//! 从给定字符串的左端和右端剪裁空格
//!
//! 发生 修整的\param 输入字符串
//!
//! 剪裁字符串的返回长度
//
//
int TrimSpace (char * pcInput)
{
size_t size;
char *endStr,*strData = pcInput;
字符索引= 0;
大小= strlen (strData);
如果(!size)
返回0;
endStr = strData + Size - 1;
while (endStr >= strData && is_space (* endStr))
endStr --;
*(endStr + 1)='\0';
while (* strData && is_space (* strData))
{
strData++;
索引++;
}
memmove (pcInput、strData、strlen (strData)+1);
return strlen (pcInput);
}
//
//
//! 将格式化的字符串打印到控制台
//!
//! \param 格式是指向指定中格式的字符串的指针
//! 需要解释以下参数。
//! 根据第一个格式的\param [变量数量]参数
//! 参数
//! 此函数
//! 1.打印格式化的错误语句。
//!
//! 返回打印的字符数
//
//
int 报告(const char *pcFormat,...)
{
INT IRET = 0;
#ifndef NOTERM
char *pcBuff,*pcTemp;
int iSize = 256;
va_list 列表;
pcBuff =(char*) malloc (iSize);
if (pcBuff ==空)
{
返回-1;
}
while (1)
{
va_start (list、pcFormat);
IRET = vsnprintf (pcBuff、iSize、pcFormat、list);
va_end (list);
if (IRET >-1 && IRET < iSize)
{
中断;
}
其他
{
iSize*=2;
if ((pcTemp=realloc (pcBuff、iSize))=NULL)
{
消息("无法重新分配内存\n\r\n);
IRET =-1;
中断;
}
其他
{
pcBuff=pcTemp;
}
}
}
消息(pcBuff);
FREE (pcBuff);
#endif
返回 IRET;
}
***** UART_IF.h
#ifndef __UART_if_H__
#define __UART_IF_H__
//
//
//如果使用 C++编译器进行编译,请在此标头中进行所有定义
//具有 C 绑定。
//
//
#ifdef __cplusplus
外部"C"
{
#endif
/ /
/*宏*/
/ /
#define UART_BAUD_RATE 115200
#define SYSCLK 8000000
#define 器件 UARTA1_BASE
#define console UARTA0_BASE
#define console_Periph PRCM_UARTA0
#define DEVICE_PERIPh PRCM_UARTA1
//
//为 RX 定义 UART IF 缓冲器的大小
//
#define UART_IF_buffer 64
//
//定义 UART IF 缓冲器
//
extern unsigned char g_ucUARTBuffer[];
/ /
/*函数原型*/
/ /
extern void 派单器 UARTConfigure (void);
extern void DispatcherUartSendPacket (unsigned char * inBuff、unsigned short usLength);
extern int GetCmd (char * pcBuffer、unsigned int uiBufLen);
extern void InitTerm (void);
extern void ClearTerm (void);
extern void Message (const char *格式);
extern void 错误(char *格式...);
extern int TrimSpace (char * pcInput);
extern int Report (const char *格式,...);
//
//
//标记 C++编译器的 C 绑定部分的结尾。
//
//
#ifdef __cplusplus
}
#endif
#endif
********* main.c
// Driverlib 包括
#include "rom.h"
#include "rom_map.h"
#include "hw_memmap.h"
#include "hw_common_reg.h"
#include "hw_types.h"
#include "hw_ints.h"
#include "UART.h"
#include "interrupt.h"
#include "pinmux.h"
#include "utils.h"
#include "prcm.h"
#include "common.h"
//通用接口包括
#include "UART_IF.h"
//
//宏
//
#define application_version "1.1.1"
#define APP_NAME "UART 回波"
#define console UARTA0_BASE
#define 器件 UARTA1_base
#define UartGetChar() MAP_UARTCharGet (器件)
#define UartPutChar (c) map_UARTCharPut (器件、c)
#define MAX_STRING_LENGTH 80
//
//全局变量--启动
//
volatile int g_iCounter = 0;
#if defined (CCS)(如果已定义)
extern void (* const g_pfnVectors [])(void);
#endif
#IF 定义(ewarm)
extern uVectorEntry __vector_table;
#endif
//
//全局变量--结束
//
//
//本地定义
//
//
//
//! UART 上的应用启动显示
//!
//! \param 无
//!
//! \不返回任何内容
//!
//
静态空
DisplayBanner (char * AppName)
{
报告("\n\n\r\n");
报告("\t \n\n");
报告("\t\tCC3200 %s 应用程序\n"AppName");
报告("\t \n\n");
报告("\n\n\r\n");
}
//
//
//! 电路板初始化和配置
//!
//! \param 无
//!
//! \无返回
//
//
静态空
BoardInit(空)
{
/*如果 TI-RTOS 矢量表由操作系统本身初始化*/
#ifndef use_TIRTOS
//
//设置矢量表基址
//
#if defined (CCS)(如果已定义)
MAP_IntVTableBaseSet ((无符号长整型)&g_pfnVectors[0]);
#endif
#IF 定义(ewarm)
MAP_IntVTableBaseSet ((unsigned long)&__vector_table);
#endif
#endif
//
//启用处理器
//
MAP_IntMasterEnable();
MAP_IntEnable (FAULT_SysTick);
PRCMCC3200MCUInit();
}
//
//
//! 处理 UART 回波的主函数。 它从中获取输入字符串
//! 显示字符串的每个字符时的终端。 只要输入命令
//! 它将回显字符串(display)。 如果输入为最大输入
//! 可以是80个字符、之后字符将被视为部分字符
//! 下一个字符串。
//!
//! \param 无
//!
//! \无返回
//!
//
void main()
{
char Cstring[MAX_STRING_LENGTH+1];
字符字符字符字符字符字符;
int iStringLength = 0;
//
//对电路板进行初始化
//
BoardInit();
//
//启用 UART_TX 和 UART_RX 的多路复用。
//
PinMuxConfig();
//
//初始化终端。
//
InitTerm();
//
//清除终端。
//
ClearTerm();
DisplayBanner (app_name);
消息("\t\t******** \n\n");
消息("\t\t\t CC3200 UART 回显用法\n");
消息("\t\t\t 键入字母数字字符串和\n");
message("\t\t pressenter,字符串将被回传。 \n\n");
Message ("\t\t\t 注意:如果字符串长度达到80个字符、它将\n");
消息("\t\t\t 回显字符串而不等待输入命令\n");
信息("\t\t" \n\n");
消息("\n\n\r\n");
消息("cmd#");
while (1)
{
//
//从终端获取输入。
//
cCharacter = UartGetChar();
G_iCounter++;
if (cCharacter ='\r'|| cCharacter ='\n'||
(iStringLength >= MAX_STRING_LENGTH -1)
{
if (iStringLength >= MAX_STRING_LENGTH - 1)
{
UartPutChar (cCharacter);
Cstring[iStringLength ]= cCharacter;
iStringLength ++;
}
Cstring[iStringLength ]='\0';
iStringLength = 0;
//
//回显输入字符串
//
UART_PRINT ("海");
报告("\n\rcmd#%s\n\rcmd#"、Cstring);
}
其他
{
UartPutChar (cCharacter);
Cstring[iStringLength ]= cCharacter;
iStringLength ++;
}
}
}
//
//
//关闭 Doxygen 组。
//! @}
//
//