TIMAC实现串口收发功能
时间:10-02
整理:3721RD
点击:
1.设置IAR的C/C++编译参数
Project> Options> C/C++ Compiler> Preprocessor> Defined Symbols.
CC2530EB
HAL_DMA=FALSE
HAL_UART_ISR=TRUE
HAL_UART=TRUE
2.更改msa.c中的内容
(1).包含头文件和添加宏定义
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "hal_uart.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#define SERIAL_APP_PORT 0
#define SERIAL_APP_BAUD HAL_UART_BR_38400
//#define SERIAL_APP_BAUD HAL_UART_BR_115200
// When the Rx buf space is less than this threshold, invoke the Rx callback.
#define SERIAL_APP_THRESH 64
#define SERIAL_APP_RX_SZ 128
#define SERIAL_APP_TX_SZ 128
// Millisecs of idle time after a byte is received before invoking Rx callback.
#define SERIAL_APP_IDLE 6
// This is the max byte count per OTA message.
#define SERIAL_APP_TX_MAX 80
#define SERIAL_APP_RSP_CNT 4
///////////////////////////////////////////////////////////////////////////////////////////////////
(2).串口参数配置
在函数 void MSA_Init(uint8 taskId) 中添加内容
/////////////////////////////////////////////////////////////////////////////////////////
halUARTCfg_t uartConfig;
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
uartConfig.configured = TRUE; // 2x30 don't care - see uart driver.
uartConfig.baudRate = SERIAL_APP_BAUD;
uartConfig.flowControl = TRUE;
uartConfig.flowControlThreshold = SERIAL_APP_THRESH; // 2x30 don't care - see uart driver.
uartConfig.rx.maxBufSize = SERIAL_APP_RX_SZ; // 2x30 don't care - see uart driver.
uartConfig.tx.maxBufSize = SERIAL_APP_TX_SZ; // 2x30 don't care - see uart driver.
uartConfig.idleTimeout = SERIAL_APP_IDLE; // 2x30 don't care - see uart driver.
uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver.
uartConfig.callBackFunc = SerialApp_CallBack;
HalUARTOpen (SERIAL_APP_PORT, &uartConfig);
/////////////////////////////////////////////////////////////////////////////////////////
(3).添加串口回调函数和函数声明
static void SerialApp_CallBack(uint8 port, uint8 event);
///////////////////////////////////////////////////////////////////////////////////////////////////
static void SerialApp_CallBack(uint8 port, uint8 event)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////
(4).使用串口输出
我串口输出函数放在了按键处理中了,按sw1键,输出 hello
void MSA_HandleKeys(uint8 keys, uint8 shift)
{
if ( keys & HAL_KEY_SW_1 )
{
//////////////////////////////////////////////
HalUARTWrite( 0, "hello", 5);
///////////////////////////////////////////////
TI 官网社区提供的回调函数
MT_UartProcessRxData is the callback function for the UART.
This is what is contained in mine for reading a single character:
static void MT_UartProcessRxData(uint8 port, uint8 event)
{
uint8 cmdbuff[6];
HalUARTRead( SERIAL_APP_PORT, cmdbuff, 1);
switch (cmdbuff[0])
{
case '1':
HalUARTWrite( SERIAL_APP_PORT, "CMD - 1\n\r", 10 ); // Echo character
break;
case 'f':
HalUARTWrite( SERIAL_APP_PORT, "CMD - f\n\r", 10 );
break;
default:
break;
}
}
This callback did not work until I set HAL_UART_ISR=TRUE and HAL_UART_DMA=FALSE. in the preprocessor directives.
Hope this helps. I know how frustrating this can be.
。。。。。。。。。。。。。。。。。。。。。。。。。。。。
(5).此方法来自TI官网技术交流社区的帖子,我验证了一下可行,感兴趣的话大家可以浏览 具体内容如下
###########################################################################################
In the IAR Workbench go to
Project> Options> C/C++ Compiler> Preprocessor> Defined Symbols.
This is what mine has defined:
CC2430EB
POWER_SAVING
HAL_DMA=FALSE
HAL_AES=FALSE
HAL_UART_ISR=TRUE
HAL_UART=TRUE
I think if you are using another compiler such as Keil, maybe you would
just use the #define statement for these definitions in your include .h file, such as:
#define HAL_UART_ISR=TRUE
Hope this helps
###############################################################################################
###############################################################################################
Here are some really basic steps to send and receive serial I/O with TIMAC:
1. Make sure the following files are included in the project: hal_uart.c and hal_driver.c
2. Define HAL_UART=TRUE in the IDE compiler pre-processor options
3. Call HalUARTInit() in main()
4. Call HalUARTOpen() in your program -- see sample code below:
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_38400;
uartConfig.flowControl = TRUE;
uartConfig.flowControlThreshold = 5;
uartConfig.rx.maxBufSize = 120;
uartConfig.tx.maxBufSize = 120;
uartConfig.idleTimeout = 5;
uartConfig.intEnable = TRUE;
uartConfig.callBackFunc = MT_UartProcessRxData;
HalUARTOpen (0, &uartConfig); //0 for port 0 and 1 for port 1
5. Define a callback function MT_UartProcessRxData (defined in the call to HalUARTOpen()) somewhere in your program. This function will be called when the UART receives stuff. The user program can call HalUARTRead() here to read the buffer -- it's totally up to the user to handle the buffer here.
6. Use HalUARTWrite() to write stuff to the serial port.
#################################################################################################
#################################################################################################
MT_UartProcessRxData is the callback function for the UART.
This is what is contained in mine for reading a single character:
static void MT_UartProcessRxData(uint8 port, uint8 event)
{
uint8 cmdbuff[6];
HalUARTRead( SERIAL_APP_PORT, cmdbuff, 1);
switch (cmdbuff[0])
{
case '1':
HalUARTWrite( SERIAL_APP_PORT, "CMD - 1\n\r", 10 ); // Echo character
break;
case 'f':
HalUARTWrite( SERIAL_APP_PORT, "CMD - f\n\r", 10 );
break;
default:
break;
}
}
This callback did not work until I set HAL_UART_ISR=TRUE and HAL_UART_DMA=FALSE. in the preprocessor directives.
Hope this helps. I know how frustrating this can be.
###################################################################################################
本人把串口输出函数移植到MAC层,也能读取MAC层的数据,但是不能不加区分的读取RF接受的所有数据,只能读取已关联设备发送过来的数据包。
Project> Options> C/C++ Compiler> Preprocessor> Defined Symbols.
CC2530EB
HAL_DMA=FALSE
HAL_UART_ISR=TRUE
HAL_UART=TRUE
2.更改msa.c中的内容
(1).包含头文件和添加宏定义
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "hal_uart.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
#define SERIAL_APP_PORT 0
#define SERIAL_APP_BAUD HAL_UART_BR_38400
//#define SERIAL_APP_BAUD HAL_UART_BR_115200
// When the Rx buf space is less than this threshold, invoke the Rx callback.
#define SERIAL_APP_THRESH 64
#define SERIAL_APP_RX_SZ 128
#define SERIAL_APP_TX_SZ 128
// Millisecs of idle time after a byte is received before invoking Rx callback.
#define SERIAL_APP_IDLE 6
// This is the max byte count per OTA message.
#define SERIAL_APP_TX_MAX 80
#define SERIAL_APP_RSP_CNT 4
///////////////////////////////////////////////////////////////////////////////////////////////////
(2).串口参数配置
在函数 void MSA_Init(uint8 taskId) 中添加内容
/////////////////////////////////////////////////////////////////////////////////////////
halUARTCfg_t uartConfig;
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
uartConfig.configured = TRUE; // 2x30 don't care - see uart driver.
uartConfig.baudRate = SERIAL_APP_BAUD;
uartConfig.flowControl = TRUE;
uartConfig.flowControlThreshold = SERIAL_APP_THRESH; // 2x30 don't care - see uart driver.
uartConfig.rx.maxBufSize = SERIAL_APP_RX_SZ; // 2x30 don't care - see uart driver.
uartConfig.tx.maxBufSize = SERIAL_APP_TX_SZ; // 2x30 don't care - see uart driver.
uartConfig.idleTimeout = SERIAL_APP_IDLE; // 2x30 don't care - see uart driver.
uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver.
uartConfig.callBackFunc = SerialApp_CallBack;
HalUARTOpen (SERIAL_APP_PORT, &uartConfig);
/////////////////////////////////////////////////////////////////////////////////////////
(3).添加串口回调函数和函数声明
static void SerialApp_CallBack(uint8 port, uint8 event);
///////////////////////////////////////////////////////////////////////////////////////////////////
static void SerialApp_CallBack(uint8 port, uint8 event)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////
(4).使用串口输出
我串口输出函数放在了按键处理中了,按sw1键,输出 hello
void MSA_HandleKeys(uint8 keys, uint8 shift)
{
if ( keys & HAL_KEY_SW_1 )
{
//////////////////////////////////////////////
HalUARTWrite( 0, "hello", 5);
///////////////////////////////////////////////
TI 官网社区提供的回调函数
MT_UartProcessRxData is the callback function for the UART.
This is what is contained in mine for reading a single character:
static void MT_UartProcessRxData(uint8 port, uint8 event)
{
uint8 cmdbuff[6];
HalUARTRead( SERIAL_APP_PORT, cmdbuff, 1);
switch (cmdbuff[0])
{
case '1':
HalUARTWrite( SERIAL_APP_PORT, "CMD - 1\n\r", 10 ); // Echo character
break;
case 'f':
HalUARTWrite( SERIAL_APP_PORT, "CMD - f\n\r", 10 );
break;
default:
break;
}
}
This callback did not work until I set HAL_UART_ISR=TRUE and HAL_UART_DMA=FALSE. in the preprocessor directives.
Hope this helps. I know how frustrating this can be.
。。。。。。。。。。。。。。。。。。。。。。。。。。。。
(5).此方法来自TI官网技术交流社区的帖子,我验证了一下可行,感兴趣的话大家可以浏览 具体内容如下
###########################################################################################
In the IAR Workbench go to
Project> Options> C/C++ Compiler> Preprocessor> Defined Symbols.
This is what mine has defined:
CC2430EB
POWER_SAVING
HAL_DMA=FALSE
HAL_AES=FALSE
HAL_UART_ISR=TRUE
HAL_UART=TRUE
I think if you are using another compiler such as Keil, maybe you would
just use the #define statement for these definitions in your include .h file, such as:
#define HAL_UART_ISR=TRUE
Hope this helps
###############################################################################################
###############################################################################################
Here are some really basic steps to send and receive serial I/O with TIMAC:
1. Make sure the following files are included in the project: hal_uart.c and hal_driver.c
2. Define HAL_UART=TRUE in the IDE compiler pre-processor options
3. Call HalUARTInit() in main()
4. Call HalUARTOpen() in your program -- see sample code below:
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_38400;
uartConfig.flowControl = TRUE;
uartConfig.flowControlThreshold = 5;
uartConfig.rx.maxBufSize = 120;
uartConfig.tx.maxBufSize = 120;
uartConfig.idleTimeout = 5;
uartConfig.intEnable = TRUE;
uartConfig.callBackFunc = MT_UartProcessRxData;
HalUARTOpen (0, &uartConfig); //0 for port 0 and 1 for port 1
5. Define a callback function MT_UartProcessRxData (defined in the call to HalUARTOpen()) somewhere in your program. This function will be called when the UART receives stuff. The user program can call HalUARTRead() here to read the buffer -- it's totally up to the user to handle the buffer here.
6. Use HalUARTWrite() to write stuff to the serial port.
#################################################################################################
#################################################################################################
MT_UartProcessRxData is the callback function for the UART.
This is what is contained in mine for reading a single character:
static void MT_UartProcessRxData(uint8 port, uint8 event)
{
uint8 cmdbuff[6];
HalUARTRead( SERIAL_APP_PORT, cmdbuff, 1);
switch (cmdbuff[0])
{
case '1':
HalUARTWrite( SERIAL_APP_PORT, "CMD - 1\n\r", 10 ); // Echo character
break;
case 'f':
HalUARTWrite( SERIAL_APP_PORT, "CMD - f\n\r", 10 );
break;
default:
break;
}
}
This callback did not work until I set HAL_UART_ISR=TRUE and HAL_UART_DMA=FALSE. in the preprocessor directives.
Hope this helps. I know how frustrating this can be.
###################################################################################################
本人把串口输出函数移植到MAC层,也能读取MAC层的数据,但是不能不加区分的读取RF接受的所有数据,只能读取已关联设备发送过来的数据包。