CC26x2R1笔记(6) uart的使用

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(&params);
       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, &params);
       
       
       UART_write(handle, "ok", 2);
       
       
       wantedRxBytes = 1;//16; //每次要读取的字节数  
       int rxBytes = UART_read(handle, rxBuf, wantedRxBytes);
 

   }
 

可以加入QQ群:687360507
与大伙沟通交流,技术在于分享而进步

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值