Da14580 有两个串口 UART1和UART2,   2个串口的使用配置类似。

1,先定义端口

        #define UART2_TX_GPIO_PORT  GPIO_PORT_0#define UART2_TX_GPIO_PIN   GPIO_PIN_4#define UART2_RX_GPIO_PORT  GPIO_PORT_0#define UART2_RX_GPIO_PIN   GPIO_PIN_5

2,注册UART2的 IO口

//注册UART2 IO口
#ifdef CFG_PRINTF_UART2RESERVE_GPIO(UART2_TX, UART2_TX_GPIO_PORT, UART2_TX_GPIO_PIN, PID_UART2_TX);RESERVE_GPIO(UART2_RX, UART2_RX_GPIO_PORT, UART2_RX_GPIO_PIN, PID_UART2_RX);
#endif

3, UART2的 端口配置

//UART2,tx rx口配置
#ifdef CFG_PRINTF_UART2GPIO_ConfigurePin(UART2_TX_GPIO_PORT, UART2_TX_GPIO_PIN, OUTPUT, PID_UART2_TX, false);GPIO_ConfigurePin(UART2_RX_GPIO_PORT, UART2_RX_GPIO_PIN, INPUT, PID_UART2_RX,  false);
#endif

4, uart2的使能,初始化端口,配置波特率。

#ifdef CFG_PRINTF_UART2SetBits16(CLK_PER_REG, UART2_ENABLE, 1);uart2_init(UART_BAUDRATE_115K2, 3);
#endif

库文件 uart2.c中

5,发生和接收函数

在uart2.c中添加:

char uart_receive_byte(void)
{do{ }while((GetWord16(UART2_LSR_REG)&0x01)==0);  // wait until serial data is ready return 0xFF&GetWord16(UART2_RBR_THR_DLL_REG);    // read from receive data buffer
}void uart_send_byte(char ch)
{while((GetWord16(UART2_LSR_REG)&0x20)==0);   // read status reg to check if THR is emptySetWord16(UART2_RBR_THR_DLL_REG,(0xFF&ch)); // write to THR registerreturn;
}void printf_string(char * str)
{while(*str!=0){         // while not reach the last string characteruart_send_byte(*str); // send next string characterstr++;}
}

在uart.h中添加:

char uart_receive_byte(void);
void uart_send_byte(char ch);
void printf_string(char * str);

6,使用

  printf_string("\n UART TEST!\n");

方案二:

直接添加 common_uart.c 文件   在kile的.h文件路径下添加common_uart.h路径

/******************************************************************************************** @file common_uart.c** @brief (Do not use for your designs) - (legacy) uart initialization & print functions*        Please, refer to the Peripheral Drivers documentation for the current uart.c driver** Copyright (C) 2012. Dialog Semiconductor Ltd, unpublished work. This computer * program includes Confidential, Proprietary Information and is a Trade Secret of * Dialog Semiconductor Ltd.  All use, disclosure, and/or reproduction is prohibited * unless authorized in writing. All Rights Reserved.** <bluetooth.support@diasemi.com> and contributors.******************************************************************************************/#include "global_io.h"
#include "gpio.h"
#include <core_cm0.h>
#include "common_uart.h"/******************************************************************************************* @brief print a Byte in hex format* @param ch  character to print* *****************************************************************************************/
void printf_byte(char ch)
{// print a Byte in hex formatchar b;b = ((0xF0 & ch) >> 4);b += (b < 10) ? 48 : 55;uart2_write((uint8_t *)&b,1, NULL);uart2_finish_transfers();b = (0xF & ch);b += (b < 10) ? 48 : 55;uart2_write((uint8_t *)&b,1, NULL);uart2_finish_transfers();
}/******************************************************************************************* @brief Uart print string fucntion** *****************************************************************************************/
void printf_string(char * str)
{uart2_write((uint8_t *)str, strlen(str), NULL); // send next string characteruart2_finish_transfers();
}/******************************************************************************************* @brief prints a (16-bit) half-word in hex format using printf_byte* @param aHalfWord The 16-bit half-word to print* *****************************************************************************************/void print_hword(uint16_t aHalfWord)
{printf_byte((aHalfWord >> 8) & 0xFF);printf_byte((aHalfWord) & 0xFF);
}/******************************************************************************************* @brief prints a (32-bit) word in hex format using printf_byte* @param aHalfWord The 32-bit word to print* *****************************************************************************************/
void print_word(uint32_t aWord)
{printf_byte((aWord >> 24) & 0xFF);printf_byte((aWord >> 16) & 0xFF);printf_byte((aWord >> 8) & 0xFF);printf_byte((aWord) & 0xFF);
}/* reverse:  reverse string s in place */void reverse(char s[]){int i, j;char c;for (i = 0, j = strlen(s)-1; i<j; i++, j--) {c = s[i];s[i] = s[j];s[j] = c;}}/* itoa:  convert n to characters in s */void itoa(int n, char s[])
{int i, sign;if ((sign = n) < 0)  /* record sign */n = -n;          /* make n positive */i = 0;do {       /* generate digits in reverse order */s[i++] = n % 10 + '0';   /* get next digit */} while ((n /= 10) > 0);     /* delete it */if (sign < 0)s[i++] = '-';s[i] = '\0';reverse(s);
}void printf_byte_dec(int a){         // print a Byte in decimal format
#ifndef UART_ENABLEDreturn ;
#elsechar temp_buf[4];//    if ( a>255 )
//    return;itoa( a,   temp_buf ); printf_string(temp_buf);#endif
}

common_uart.h

/******************************************************************************************** @file common_uart.h** @brief uart initialization and print functions header file.** Copyright (C) 2012. Dialog Semiconductor Ltd, unpublished work. This computer * program includes Confidential, Proprietary Information and is a Trade Secret of * Dialog Semiconductor Ltd.  All use, disclosure, and/or reproduction is prohibited * unless authorized in writing. All Rights Reserved.** <bluetooth.support@diasemi.com> and contributors.******************************************************************************************/#include <stdint.h>#ifndef UART_H_INCLUDED
#define UART_H_INCLUDED
#include "uart.h"
#include "user_periph_setup.h" /** ENUMERATION DEFINITIONS******************************************************************************************//** FUNCTION DECLARATIONS*****************************************************************************************/void printf_byte(char ch);
/******************************************************************************************* @brief Uart print string fucntion** *****************************************************************************************/
void printf_string(char * str);/******************************************************************************************* @brief prints a (16-bit) half-word in hex format using printf_byte* @param aHalfWord The 16-bit half-word to print* *****************************************************************************************/
void print_hword(uint16_t aHalfWord);/******************************************************************************************* @brief prints a (32-bit) word in hex format using printf_byte* @param aWord The 32-bit word to print* *****************************************************************************************/
void print_word(uint32_t aWord);/******************************************************************************************* @brief prints a byte in dec format * @param a The byte to print* *****************************************************************************************/
void printf_byte_dec(int a); #endif

common_uart.c 文件中,有print比较详细的功能函数,

比如void printf_byte_dec(int a)  可以直接将 char int类型的数据,转出字符串打印出

参考:https://blog.csdn.net/a13306058739/article/details/80365229

DA14580 UART2 的使用相关推荐

  1. 拼写检查_拼写检查属性

    拼写检查 Many useful attributes have been provided to web developers recently:  download, placeholder, a ...

  2. ESP32-S的UART2的初始化需要注意的问题

    简 介: 在使用ESP32-S的UART2的时候,初始化UART的ID需要设置成1,而不是2,这样可以避免ESP32热启动出现故障.具体原因并不清楚,但可以解决热启动程序执行的问题.在MicroPyt ...

  3. STM32 UART2程序--端口重映射

    STM32 UART2程序 2012-12-04 16:26:05 分类: LINUX USART1程序很多,看看USART2程序.注意红色部分,首先要使能相关端口的时钟. 因为USART2可以映射成 ...

  4. Hi3520D UART2和UART3是如何加载到内核的

    Hi3520D的UART驱动位于linux-3.0.y/drivers/tty/serial/amba-pl011.c 添加UART2和UART3需要修改的文件为:linux-3.0.y/arch/a ...

  5. 转 主流蓝牙BLE控制芯片详解(5):Dialog DA14580

    [导读] Dialog推出的号称全球功率最低.体积最小的SmartBond DA14580蓝牙智能系统级芯片(SoC),与竞争方案相比,该产品可将搭载应用的智能型手机配件,或计算机周边商品的电池巡航时 ...

  6. DA14580软件开发平台参考(一)

    翻译的是这个文档. 它介绍了整个系统架构,组件,应用程序编程接口(API)以及开发工具链,环境和过程. 问题点请在评论中留言,我看到了回去改正. 3 介绍 本文档旨在通过为蓝牙低功耗标准提供实用的高级 ...

  7. lx2160a - uart2(ttyAMA1)调试

    问题描述:uart1作为调试串口使用,uart2作为和cpld通信传输数据使用.当前uart2设备可以在内核中识别到,但是无法通信,tx rx线检测不到数据数据.使用示波器测量不到波形,cpld也抓不 ...

  8. DA14580的AD转换

    DA14580在两处体现了ADC功能.一是电源管理方面,10bit的ADC能够测量电池电压:二是模拟接口方面,有4通道的10bit AD转换. 10bit ADC可单端可差分,一次转换耗时65ns,最 ...

  9. S32K系列S32K144学习笔记——UART2

    一用S32K144苦似海,道友,能不用,千万不去用. 本例程,以MCU为S32K144,开发平台S32DSworkspace 功能描述:配置UART2,输出打印"just do it!&qu ...

最新文章

  1. Windows窗口风格
  2. 操作系统(七)进程的概念、组成、特征
  3. 业界萌新对斯坦纳树的小结
  4. SpringBoot------全局异常捕获
  5. BASE64学习小记
  6. Android Studio Cmake C++ JNI demo
  7. matlab仿真限幅发散,GSM通信系统性能分析与MATLAB仿真.doc
  8. hdu2084数塔----DP入门
  9. 月薪30K+的电子工程师应具备什么?
  10. SQL Server 2000/2005/2008 系列产品下载地址
  11. Ubuntu安装python步骤
  12. 为你的域名添加子域名(二级域名)并绑定网站
  13. python numpy 矩阵加减规则 ValueError: operands could not be broadcast together with shapes
  14. win7电脑蓝屏没有修复计算机,技术编辑教您win7电脑蓝屏怎么办
  15. mysql wresp_mysql
  16. point\polyline\polygon的转化(转)
  17. 计算机账户注销重新登录,win10系统注销账户切换账号登录的方法
  18. python集合为什么不能用下标运算_Python的Set操作,python,集合
  19. laytpl--前端数据绑定 (示例)
  20. 计算机网络:划分子网和构造超网

热门文章

  1. JavaScript原生-网页版计算器
  2. Java实现的基于欧式距离的聚类算法的Kmeans作业
  3. JS中怎么表示 π (pai)
  4. 对于初学者来说,数据科学家需要具备哪些基本技能?
  5. unity survival shooter ZSpace
  6. R言rvest包爬取南京二手房信息
  7. python 操作excel坐标_Python - openpyxl 读写操作Excel
  8. win7打印机不显示服务器错误,打印机连接不上,教你win7连接打印机提示错误0x00000002的解决教程...
  9. B2B订货系统源码就这样选
  10. Springboot 整合微信小程序 城市服务实名信息校验