当前位置:网站首页>基于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)引用出

效果如下

边栏推荐
猜你喜欢

对数学直观、感性的认知是理解数学、喜爱数学的必经之路,这本书做到了!

第三方bean使用ConfigurationProperties注解获取yml配置文件数据 & 获取yml配置文件数据的校验

.NET现代应用的产品设计 - DDD实践
![[免费专栏] Android安全之Xposed插件开发【从零手把手带】教程](/img/7b/a036ac664c7e27ed7d87e7ee18c05d.png)
[免费专栏] Android安全之Xposed插件开发【从零手把手带】教程
![[免费专栏] Android安全之Root检测和绕过(浅析)](/img/04/4170dea9c367c406fe3f36cb9c6501.png)
[免费专栏] Android安全之Root检测和绕过(浅析)

uniapp中使用网页录音并上传声音文件(发语音)——js-audio-recorder的使用【伸手党福利】

开源一夏 | 基于若依架构的列表详情展示

uniapp离线推送华为厂商申请流程

混动产品助力,自主SUV市场格局迎来新篇章

Sublime Text的安装过程记录
随机推荐
Paper sharing: "FED BN" uses the LOCAL BATCH NORMALIZATION method to solve the Non-iid problem
重庆智博会|2022智博会到底有哪些看点?拭目以待
MySQL备份与恢复
关于加强专业学位研究生课程体系建设的意见
字节二面:可重复读隔离级别下,这个场景会发生什么?
软件设计的七大原则
单片机编程-状态机
毕昇编译器优化:Lazy Code Motion
From functional testing to automated testing, do you know their shortcomings?
C语言知识补充
Sublime Text的安装过程记录
Samsung's flagship discount is 1,800, Apple's discount is over 1,000, and the domestic flagship is only reduced by 500 to send beggars
5.3.6 原子操作对非原子的操作排序
Fully automated machine learning modeling!The effect hangs the primary alchemist!
牛客网 Verilog 在线编程题库解答(VL1~VL10)
Open Source Summer | List Details Display Based on Ruoyi Architecture
ThreadLocal 夺命 11 连问,万字长文深度解析
IDEA工具常用配置
2022.08.08_每日一题
毕昇编译器优化:Lazy Code Motion