1、前提条件
1、硬件:cc2642r1
2、sdk软件:simplelink_cc13x2_26x2_sdk_3_30_00_03
3、在例程:simple_peripheral_oad_onchip
2、使用的回调串口
在原本的工程中是用uart进行输出display显示,需要用TI System Configuration Tool进行移除,且屏蔽掉一下函数 display_open
2.1 串口的使用
#include "simple_uart.h"
/*
* ======== uartecho.c ========
*/
#include <stdint.h>
#include <stddef.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>
/* Driver configuration */
#include "ti_drivers_config.h"
#include "string.h"
#include <ti/drivers/UART.h>
#include <ti/drivers/uart/UARTCC26XX.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/power/PowerCC26X2.h>
#include <ti/devices/cc13x2_cc26x2/inc/hw_memmap.h>
#include <ti/devices/cc13x2_cc26x2/inc/hw_ints.h>
#if 1
#define CONFIG_UART_COUNT 1
UARTCC26XX_Object uartCC26XXObjects[CONFIG_UART_COUNT];
static unsigned char uartCC26XXRingBuffer0[32];
static const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CONFIG_UART_COUNT] = {
{
.baseAddr = UART1_BASE,
.intNum = INT_UART1_COMB,
.intPriority = (~0),
.swiPriority = 0,
.powerMngrId = PowerCC26X2_PERIPH_UART1,
.ringBufPtr = uartCC26XXRingBuffer0,
.ringBufSize = sizeof(uartCC26XXRingBuffer0),
.rxPin = IOID_2,
.txPin = IOID_3,
.ctsPin = PIN_UNASSIGNED,
.rtsPin = PIN_UNASSIGNED,
.txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8,
.rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8,
.errorFxn = NULL
},
};
const UART_Config UART_config[CONFIG_UART_COUNT] = {
{
.fxnTablePtr = &UARTCC26XX_fxnTable,
.object = &uartCC26XXObjects[0],
.hwAttrs = &uartCC26XXHWAttrs[0]
},
};
const uint_least8_t UART_count = CONFIG_UART_COUNT;
#endif
#define MAX_NUM_RX_BYTES 1000 // Maximum RX bytes to receive in one go
#define MAX_NUM_TX_BYTES 1000 // Maximum TX bytes to send in one go
uint32_t wantedRxBytes; // Number of bytes received so far
uint8_t rxBuf[MAX_NUM_RX_BYTES]; // Receive buffer
uint8_t txBuf[MAX_NUM_TX_BYTES]; // Transmit buffer
static uint8_t tx_data[MAX_NUM_TX_BYTES];
// Read callback function
static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
if(size>=1)
{
// Copy bytes from RX buffer to TX buffer
for (size_t i = 0; i < size; i++)
txBuf[i] = ((uint8_t*)rxBuf)[i];
UART_write(handle, "aaaabbbbbbbbbbbbbbbbbb", strlen("aaaabbbbbbbbbbbbbbbbbb"));
}
UART_read(handle, rxBuf, wantedRxBytes);
}
else
{
// Handle error or call to UART_readCancel()
}
}
static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
// Do nothing
}
#define CONFIG_UART 0
void simple_uart_init(void )
{
UART_Handle handle;
UART_Params params;
// Init UART
UART_init();
// Specify non-default parameters
UART_Params_init(¶ms);
params.baudRate = 9600;
params.dataLength = UART_LEN_8;
params.stopBits = UART_STOP_ONE;
params.parityType = UART_PAR_NONE;
params.writeMode = UART_MODE_CALLBACK;
params.writeDataMode = UART_DATA_BINARY;
params.writeCallback = writeCallback;
params.readMode = UART_MODE_CALLBACK;
params.readDataMode = UART_DATA_BINARY;
params.readCallback = readCallback;
// Open the UART and initiate the first read
handle = UART_open(CONFIG_UART, ¶ms);
UART_write(handle, "ok", 2);
wantedRxBytes = 1;//16; //每次要读取的字节数
int rxBytes = UART_read(handle, rxBuf, wantedRxBytes);
}
可以加入QQ群:687360507
与大伙沟通交流,技术在于分享而进步