当前位置:网站首页>基于CC2530 E18-MS1-PCB Zigbee DIY作品(三)
基于CC2530 E18-MS1-PCB Zigbee DIY作品(三)
2022-08-09 18:08:00 【分享大师】
目录
写作前情
由于没有买cc2530的仿真烧录器,所以在调试过程中,遇到bug或者程序运行情况无法确认,之前使用esp8266时,可以用串口来输出相关信息,所以想着如果cc2530可以用串口输出log,将更有利于分析问题,
实现过程
网上搜索相关例程,找到这篇比较简单易懂,故采用,大致思路是寄存器直接发送,比较可靠。不过因为只是用来打印log的,没有用来接收,所以只有发送,如果打印太多,比较占cpu。
原作者实现例程,需要用哪个串口,哪个引脚,直接加入宏就好,打印log推荐使用SendDebugString()函数,用法类似printf,可变参数打印,比较方便。波特率选择的是115200
serialprintf.c文件
serialprintf.c文件
#include "iocc2530.h"
#include "hal_types.h"
#include "string.h"
#include "uart_debug.h"
#include <stdarg.h>
#include "stdio.h"
#include "cfg.h"
/*choose which IO to use*/
void UART_Debug_Init(void)
{
#ifdef UARTDEBUG
#ifdef UART0_ALT0_DEBUG/* Uart0 Alt0 TX:P0.3 RX:P0.2 */
PERCFG &= 0xFE ;
P0SEL |= 0x0C;
U0CSR = 0x80;
U0GCR = 11;
U0BAUD = 216;
U0CSR |= 0x40;
#elif (defined UART0_ALT1_DEBUG)/* Uart0 Alt1 TX:P1.5 RX:P1.4 */
PERCFG |= 0x01;
P1SEL |= 0x30;
U0CSR = 0x80;
U0GCR = 11;
U0BAUD = 216;
U0CSR |= 0x40;
#elif (defined UART1_ALT0_DEBUG) /* Uart1 Alt0 TX:P0.4 RX:P0.5 */
PERCFG &= 0xFD ;
P0SEL |= 0x30;
U1CSR = 0x80;
U1GCR = 11;
U1UCR = 0x80;
U1UCR |= 0x02;
U1BAUD = 216;
U1CSR |= 0x40;
#elif (defined UART1_ALT1_DEBUG) /* Uart1 Alt1 TX:P1.6 RX:P1.7 */
PERCFG |= 0x02 ;
P1SEL |= 0xC0;
U1CSR = 0x80;
U1GCR = 11;
U1UCR = 0x80;
U1UCR |= 0x02;
U1BAUD = 216;
U1CSR |= 0x40;
#endif
#endif
}
uint16 SendDebugWordData(uint8 worddata)
{
#ifdef UARTDEBUG
#if ((defined UART0_ALT1_DEBUG) || (defined UART1_ALT0_DEBUG))
while(U1CSR&0x01); //等待UART空闲时发送数据
U1DBUF = worddata;
#elif ((defined UART0_ALT1_DEBUG) || (defined UART0_ALT0_DEBUG))
while(U0CSR&0x01); //等待UART空闲时发送数据
U0DBUF = worddata;
#endif
#endif
return 1;
}
uint16 SendDebugString(char* string,...) //it's used like printf()
{
#ifdef UARTDEBUG
va_list ap;
char pstring[150];
va_start(ap,string);
vsprintf(pstring,string,ap);
SendDebugData((uint8*)pstring,strlen(pstring));
va_end(ap);
#endif
return 1;
}
uint16 SendDebugIfo(char* string,uint16 data)
{
#ifdef UARTDEBUG
uint8 stringbuf[100] = "";
sprintf((char *)stringbuf,string,data);
SendDebugData(stringbuf,strlen((char *)stringbuf));
#endif
return 1;
}
uint16 SendDebugData(uint8 *buf,uint8 len)
{
#ifdef UARTDEBUG
#if ((defined UART1_ALT0_DEBUG) || (defined UART1_ALT1_DEBUG))
while(len--)
{
while(U1CSR & 0x01 == 0x01);
U1DBUF = *buf++;
}
#elif ((defined UART0_ALT1_DEBUG) || (defined UART0_ALT0_DEBUG))
while(len--)
{
while(U0CSR & 0x01 == 0x01);
U0DBUF = *buf++;
}
#endif
#endif
return 1;
}
serialprintf.h文件
serialprintf.h文件
#ifndef SERIALPRINTF_H
#define SERIALPRINTF_H
extern void UART_Debug_Init(void);
extern uint16 SendDebugString(char* string,...);
extern uint16 SendDebugData(uint8 *buf,uint8 len);
extern uint16 SendDebugWordData(uint8 worddata);
extern uint16 SendDebugIfo(char* string,uint16 data);
//const float BH1750_CONV_FACTOR = 1.2;
#endif
在使用的地方加入如下,方便输出
#include "serialprintf.h"
#define APS_TAG "[CC2530]"
#define APS_LOG(fmt, args...) SendDebugString(APS_TAG" %s %d: "fmt"\n", __FUNCTION__, __LINE__, ##args)
引用出
效果如下
边栏推荐
- 基于AWS构建云上数仓第一步:云平台的基础概念
- PHP 变量注释/**@var*/
- Detailed explanation of VIT transformer
- [免费专栏] Android安全之数据存储与数据安全【大集合】
- C的一些琐碎
- [免费专栏] Android安全之和平精英(FZ)APK逆向分析
- MySQL备份与恢复
- ceph集群部署
- Mysql table structure change scheme comparison and analysis
- Fully automated machine learning modeling!The effect hangs the primary alchemist!
猜你喜欢
16 张图解 | 淘宝 10年架构演进
What is the Treasure Project (TPC), a dark horse with wings in 2022!
Ng DevUI 周下载量突破1000啦!
[免费专栏] Android安全之Root检测和绕过(浅析)
[Free Column] Android Fragment Injection for Android Security
YOLO v3源码详解
全自动化机器学习建模!效果吊打初级炼丹师!
每周给我10分钟,我给你一个Flink SQL 菜谱——甜点:数据过滤
Fully automated machine learning modeling!The effect hangs the primary alchemist!
C#/VB.NET: Extract text and pictures from PowerPoint document
随机推荐
C语言知识补充
AWS CodePipeLine 跨账号部署ECS
电商项目架构图
Detailed explanation of VIT transformer
渗透测试——CFS三层靶机内网渗透实操
[Free Column] Android Security for Peace Elite (FZ) APK Reverse Analysis
uniapp 实现底部导航栏tabbar
How to stop the test after reaching a given number of errors during stress testing in JMeter
.NET现代应用的产品设计 - DDD实践
鹅厂机器狗花式穿越10m梅花桩:前空翻、单桩跳、起身作揖...全程不打一个趔趄...
C#/VB.NET:从PowerPoint文档中提取文本和图片
韩国严厉监管元宇宙相关企业
Mysql table structure change scheme comparison and analysis
毕昇编译器优化:Lazy Code Motion
[免费专栏] Android安全之Android工程模式
释放数据价值的真正法宝,数据要素市场化开发迫在眉睫
宝塔面板安装使用
[Free Column] Android Fragment Injection for Android Security
Unix domain socket
三面(技术 +HR 面试)网易,分享我的面试经验!(已拿 offer)