ADI Blackfin DSP处理器-BF533的开发详解15:RS232串口的实现(含源代码)

news2024/10/7 14:33:11

硬件准备

ADSP-EDU-BF533:BF533开发板
AD-HP530ICE:ADI DSP仿真器

软件准备

Visual DSP++软件

硬件链接

在这里插入图片描述

实现原理

ADSP-EDU-BF533 开发板上设计了一个 RS232 接口,该接口通过 ADSP-BF53x 上的 UART 接口,扩展 RS232协议的芯片实现。通过串口延长线连接计算机可实现串口通讯功能。

UART 接口的通讯波特率是通过系统时钟分频实现的,系统时钟是通过输入晶振频率通过 PLL 后实现的,板卡上采用的晶振频率为 25MHz,具体波特率配置可以参考之前的 UART 接口介绍。

硬件连接示意图

在这里插入图片描述

代码实现功能

代码实现了 UART 接口的自动波特率检测功能,运行 Windows 上自带的超级中断软件,其路径在:“开始”菜单 ->所有程序->附件->通讯->超级终端。将超级终端设置的波特率为 9600。编译并运行 VisualDSP++ 5.0 工程文件
BF53x_RS232.dpj 的代码,打开超级中断窗口,通过计算机键盘输入”@”,这时板卡会自动识别当前超级终端通讯的波特率,与当前超级终端建立连接,并将超级中断发送的键值返回打印在超级终端窗口上。

测试步骤

1. 将仿真器(ICE)与 ADSP-EDU-BF53x 开发板和计算机连接好。
2. 先给 ADSP-EDU-BF53x 开发板上电,再为仿真器(ICE)上电。
3. 运行 VisualDSP++ 5.0 软件,选择合适的 BF533 的 session 将仿真器与软件连接。
4. 加载 VisualDSP++ 5.0 工程文件 BF53x_RS232.dpj,编译并全速运行。
5. 打开 Windows 自带的超级中断软件,按下图设置,点确定后建立连接。

在这里插入图片描述
6. 通过计算机键盘输入”@”,这时板卡会自动识别当前超级终端通讯的波特率,与当前超级终端建立连接,并将超级中断发送的键值返回打印在超级终端窗口上。

通过计算机键盘输入数据,超级终端窗口上打印当前按键信息。

在这里插入图片描述

超级终端输入“@”后,通过键盘输入的信息。

程序源码

#include <defBF533.h>
#include “uartlib.h”
#include “sicnames.h”

/*****************************************************************************
*

  • Example requires a simple hello-world string.
  • Initialize on-chip SRAM at boot time accordingly.

****************************************************************************/

.section data1;

.byte sHead[] = 13,10,‘-------------------------------’,
13,10,‘ADSP-BF533 Blackfin is speaking’,
13,10,‘(DL =’,0;
.byte sTail[] = ‘)’,
13,10,‘-------------------------------’,
13,10,0;
.byte sEcho[] = ‘Type any character. The Blackfin UART’,
13,10,'returns the echo> ',0;

.align 4;
.var aEchoFifo[16];

/*****************************************************************************
*

  • Main program starts here!

****************************************************************************/

.section L1_code;
.global _main;
_main:

[--sp] = rets;

/*****************************************************************************
*

  • First of all, initialize p0 to UART_GCTL register address.
  • p0 must not be changed within this example

****************************************************************************/

p0.l = lo(UART_GCTL);
p0.h = hi(UART_GCTL);
	
call uart_autobaud;

/*****************************************************************************
*

  • r0 holds the timer period value, now.
  • Apply formula DL = PERIOD / (16 x 8 bits) and call uart_init that writes
  • the result to the two 8-bit DL registers (DLH:DLL).

****************************************************************************/

r0 >>= 7;	

call uart_init;

/*****************************************************************************
*

  • Transmit a Hello World string and the content of the DL registers.

****************************************************************************/

p1.l = sHead;
p1.h = sHead;
call uart_puts;

/*****************************************************************************
*

  • Note that r0 still contains the DLH:DLL value

****************************************************************************/

call uart_putreg;

p1.l = sTail;
p1.h = sTail;
call uart_puts;

/*****************************************************************************
*

  • Wait until operation has finished completely. This is optional.

****************************************************************************/

call uart_wait4temt;

/*****************************************************************************
*

  • Transmit another string, but use interrupt mode, this time.
  • First TX interrupt channel must be assigned and enabled.
  • Assign to EVT9.
  • p3 points to the NULL-terminated string.
  • Important: if you enable all three UART interrupts channels, it is
  • recommended to keep this order of priorities:
  • PRIORITY(Error) >= PRIORITY(RX) >= PRIORITY(TX)

****************************************************************************/

p1.l = lo(IMASK);
p1.h = hi(IMASK);

p3.l = sEcho;
p3.h = sEcho;

/*****************************************************************************
*

  • Register TX service routine at EVT9.

****************************************************************************/

r0.l = isr_uart_tx;
r0.h = isr_uart_tx;
[p1 + EVT9 - IMASK] = r0;

/*****************************************************************************
*

  • Unmask EVT9 interrupt.

****************************************************************************/

r0 = [p1 + IMASK - IMASK];
bitset(r0, bitpos(EVT_IVG9));
[p1 + IMASK - IMASK] = r0;

/*****************************************************************************
*

  • Enable UART TX interrupt and assign it to EVT9.
  • Constants used below are defined in “sicnames.h” header.

****************************************************************************/

p1.l = lo(SIC_IMASK);
p1.h = hi(SIC_IMASK);	
		
r0.l = lo(IVG_SPT0_ERROR(15) | IVG_PPI_ERROR(15)  | IVG_DMA_ERROR(15)  | IVG_PLL_WAKEUP(15));
r0.h = hi(IVG_RTC(15)        | IVG_UART_ERROR(15) | IVG_SPT1_ERROR(15) | IVG_SPI_ERROR(15));	
[p1 + SIC_IAR0 - SIC_IMASK] = r0;	
r0.l = lo(IVG_SPT1_RX(15)    | IVG_SPT0_TX(15)    | IVG_SPT0_RX(15)    | IVG_PPI(15));
r0.h = hi(IVG_UART_TX( 9)    | IVG_UART_RX(16)    | IVG_SPI(15)        | IVG_SPT1_TX(15));	
[p1 + SIC_IAR1 - SIC_IMASK] = r0;			
r0.l = lo(IVG_PFA(15)        | IVG_TIMER2(15)     | IVG_TIMER1(15)     | IVG_TIMER0(15));
r0.h = hi(IVG_SWDT(15)       | IVG_MEMDMA1(15)    | IVG_MEMDMA0(15)    | IVG_PFB(15));	
[p1 + SIC_IAR2 - SIC_IMASK] = r0;
		
r0.l = lo(IRQ_UART_TX);
r0.h = hi(IRQ_UART_TX);
[p1 + SIC_IMASK - SIC_IMASK] = r0;

/*****************************************************************************
*

  • Enable Interrupt Nesting.

****************************************************************************/

[--sp] = reti;	

/*****************************************************************************
*

  • Finally enable interrupts inside UART module, by setting proper bits
  • in the IER register. It is good programming style to clear potential
  • UART interrupt latches in advance, by reading RBR, LSR and IIR.
  • Setting the ETBEI bit automatically fires a TX interrupt request.

****************************************************************************/

r0 = w[p0+UART_RBR-UART_GCTL] (z);
r0 = w[p0+UART_LSR-UART_GCTL] (z);
r0 = w[p0+UART_IIR-UART_GCTL] (z);
			
r0 = ETBEI;
w[p0+UART_IER-UART_GCTL] = r0;	

/*****************************************************************************
*

  • Wait until operation has finished completely. Again, this is optional.

****************************************************************************/

call uart_wait4temt;	 

/*****************************************************************************
*

  • Disable UART TX interrupt again, and enable UART RX interrupt and UART
  • Line Error Interrupt.
  • Simply echo all received characters back to TX.
  • Disable nesting during the setup.

****************************************************************************/

reti = [sp++];	

p1.l = lo(IMASK);
p1.h = hi(IMASK);

/*****************************************************************************
*

  • i0 and i1 are used to implement a little FIFO

****************************************************************************/

i0.l = aEchoFifo;
i0.h = aEchoFifo;

i1 = i0;	
b0 = i0;
b1 = i0;
l0 = length(aEchoFifo);
l1 = l0;

/*****************************************************************************
*

  • Register RX service routine at EVT8 and error routine to EVT7.

****************************************************************************/

r0.l = isr_uart_error;
r0.h = isr_uart_error;
[p1 + EVT7 - IMASK] = r0;

r0.l = isr_uart_rx;
r0.h = isr_uart_rx;
[p1 + EVT8 - IMASK] = r0;	

/*****************************************************************************
*

  • Mask EVT9 interrupt and unmask EVT7 and EVT8.

****************************************************************************/

r0 = [p1 + IMASK - IMASK];
bitclr(r0, bitpos(EVT_IVG9));
bitset(r0, bitpos(EVT_IVG7));
bitset(r0, bitpos(EVT_IVG8));
[p1 + IMASK - IMASK] = r0;

/*****************************************************************************
*

  • Enable and assign interrupts.

****************************************************************************/

p1.l = lo(SIC_IMASK);
p1.h = hi(SIC_IMASK);	
		
r0.l = lo(IVG_SPT0_ERROR(15) | IVG_PPI_ERROR(15)  | IVG_DMA_ERROR(15)  | IVG_PLL_WAKEUP(15));
r0.h = hi(IVG_RTC(15)        | IVG_UART_ERROR( 7) | IVG_SPT1_ERROR(15) | IVG_SPI_ERROR(15));	
[p1 + SIC_IAR0 - SIC_IMASK] = r0;	
r0.l = lo(IVG_SPT1_RX(15)    | IVG_SPT0_TX(15)    | IVG_SPT0_RX(15)    | IVG_PPI(15));
r0.h = hi(IVG_UART_TX(15)    | IVG_UART_RX( 8)    | IVG_SPI(15)        | IVG_SPT1_TX(15));	
[p1 + SIC_IAR1 - SIC_IMASK] = r0;			
r0.l = lo(IVG_PFA(15)        | IVG_TIMER2(15)     | IVG_TIMER1(15)     | IVG_TIMER0(15));
r0.h = hi(IVG_SWDT(15)       | IVG_MEMDMA1(15)    | IVG_MEMDMA0(15)    | IVG_PFB(15));	
[p1 + SIC_IAR2 - SIC_IMASK] = r0;
		
r0.l = lo(IRQ_UART_RX | IRQ_UART_ERROR);
r0.h = hi(IRQ_UART_RX | IRQ_UART_ERROR);
[p1 + SIC_IMASK - SIC_IMASK] = r0;	

/*****************************************************************************
*

  • Enable Interrupt Nesting.

****************************************************************************/

[--sp] = reti;	

/*****************************************************************************
*

  • Finally enable interrupts inside UART module, by setting proper bits
  • in the IER register. It is good programming style to clear potential
  • UART interrupt latches in advance, by reading RBR, LSR and IIR.

****************************************************************************/

r0 = w[p0+UART_RBR-UART_GCTL] (z);
r0 = w[p0+UART_LSR-UART_GCTL] (z);
r0 = w[p0+UART_IIR-UART_GCTL] (z);
			
r0 = ELSI | ERBFI;
w[p0+UART_IER-UART_GCTL] = r0;	

/*****************************************************************************
*

  • The following endless loop tests whether data is ready in the aEchoFifo
  • and trasnmits it, if required. The FIFO is filled by the UART RX ISR.

****************************************************************************/

echo:

r0 = i0;
r1 = i1;
CC = r0 == r1;
if CC jump echo;

	r0 = [i1++];
	call uart_putc;

jump echo;

_main.end: nop;

/*****************************************************************************
*

  • UART TX Interrupt Service Rouine.
  • Load next byte from p3 pointer and moves it to THR register until
  • p3 points to NULL character. Note that a write to THR clears the
  • TX interrupt request.

****************************************************************************/

isr_uart_tx:

[--sp] = r0;

r0 = b[p3++] (z);
CC = r0 == 0;

if CC jump isr_tx_done;

w[p0+UART_THR-UART_GCTL] = r0;	

r0 = [sp++];

nop;

ssync;
rti;		

/*****************************************************************************
*

  • Once a NULL character was detected, the transmission should stop.
  • There is a need to clear the TX interrupt request. Since we don’t
  • want to write to THR again, we can clear the request by reading the
  • IIR register. Note that system design needs to ensure that neigher
  • an UART RX or Line Status interrupt should be pending!
  • Note the double ssync instruction, required due to system latencies.

****************************************************************************/

isr_tx_done:

r0 = w[p0+UART_IIR-UART_GCTL] (z); 

r0 = [sp++];

ssync;
ssync;	

rti;		

isr_uart_tx.end:

/*****************************************************************************
*

  • UART RX Interrupt Service Rouine.
  • When new data is received this ISR puts the new data into the aEchoFifo.
  • Special handling is required for carriage return and backspace.
  • Note that reading RBR clears the interrupt request.

****************************************************************************/

isr_uart_rx:

[--sp] = r0;
[--sp] = r1;

r0 = w[p0+UART_RBR-UART_GCTL] (z);
	
[i0++] = r0;

r1 = 8;		// backspace
CC = r0 == r1; 
if !CC jump isr10;

	r1 = 32 (z); // blank
	[i0++] = r1;
	
	r1 = 8 (z); // another backspace
	[i0++] = r1;

isr10:

r1 = 13;	// carriage return
CC = r0 == r1; 
if !CC jump isr20;

	r1 = 10 (z); // line feed
	[i0++] = r1;

isr20:

r1 = [sp++];
r0 = [sp++];

ssync;
rti;

isr_uart_rx.end:

/*****************************************************************************
*

  • UART Error/Line Status Interrupt Service Rouine.
  • If an error is reported by the UART Line Status, then this ISR reads
  • the LSR register to determine the cause of the error (and to clear the
  • interrupt request).
  • To indicate the error a 0xFF character will be written to the FIFO.

****************************************************************************/

isr_uart_error:

[--sp] = r0;	

r0 = w[p0+UART_LSR-UART_GCTL] (z);
	
r0 = 0xFF (z);
[i0++] = r0;

r0 = [sp++];
ssync;
rti;	

isr_uart_error.end:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/77168.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java学习之Object类——equals方法

Object 类是类层次结构的根类。每个类都使用 Object 作为超类。所有对象&#xff08;包括数组&#xff09;都实现这个类的方法&#xff0c;学习Object 类的六个方法——equals(Object obj)、finalize、toString、hashCode、getClass、clone 目录 和equals的对比 一、的作用 …

ChatGPT惊人语录大赏

文 | 智商掉了一地这几天ChatGPT实在太火了&#xff0c;笔者的朋友圈已经被ChatGPT的各种金句刷屏了&#xff0c;实在忍不住整理下来&#xff0c;分享给大家。ChatGPT惊人语录1&#xff1a;建议娶奶奶为妻注&#xff1a;贾母是贾宝玉的奶奶ChatGPT惊人语录2&#xff1a;角色扮演…

【allegro 17.4软件操作保姆级教程十】文件输出

目录 1.1添加光绘层叠 1.1.1添加线路层 1.1.2添加表底阻焊层 1.1.3添加表底钢网层 1.1.4添加表底丝印层 1.1.5添加钻孔层 ​1.2输出文件 1.2.1输出光绘文件 1.2.2输出钻孔文件 1.2.3输出坐标文件 1.2.4输出文件打包 1.1添加光绘层叠 在输出文件之前需要先添加光绘层…

PyTorch中学习率调度器可视化介绍

神经网络有许多影响模型性能的超参数。一个最基本的超参数是学习率(LR)&#xff0c;它决定了在训练步骤之间模型权重的变化程度。在最简单的情况下&#xff0c;LR值是0到1之间的固定值。 选择正确的LR值是具有挑战性。一方面较大的学习率有助于算法快速收敛&#xff0c;但它也…

【车载开发系列】UDS诊断---输入输出控制($0x2F)

【车载开发系列】UDS诊断—输入输出控制&#xff08;$0x2F&#xff09; UDS诊断---输入输出控制&#xff08;$0x2F&#xff09;【车载开发系列】UDS诊断---输入输出控制&#xff08;$0x2F&#xff09;一.概念定义1&#xff09;与0x31例程控制服务的关系2&#xff09;与0x22读取…

数据传送类指令(PUSH,POP,LEA)

目录 数据传送类指令 堆栈的概念&#xff1a; 进栈指令 &#xff08;PUSH&#xff09; 出栈指令&#xff08;POP&#xff09; 练习 LEA取偏移地址&#xff08;有效地址EA&#xff09;指令&#xff08;去括号&#xff09; LEA和OFFSET区别&#xff1a; 用法注意 LEA和MO…

微服务框架 SpringCloud微服务架构 微服务保护 31 限流规则 31.6 热点参数限流

微服务框架 【SpringCloudRabbitMQDockerRedis搜索分布式&#xff0c;系统详解springcloud微服务技术栈课程|黑马程序员Java微服务】 微服务保护 文章目录微服务框架微服务保护31 限流规则31.6 热点参数限流31.6.1 热点参数限流31.6.2 案例31 限流规则 31.6 热点参数限流 3…

【代码审计-.NET】基于.NET框架开发的基本特征

目录 一、.NET基本架构 1、基本构成 2、可支持语言 3、封装 4、文件 5、指向解析 6、安全认证 二、工具 1、ILSpyi 2、dnSpy 3、Reflector &#xff08;网上找的一张图谱&#xff09; 本博客只面向讲安全相关内容 一、.NET基本架构 1、基本构成 可支持语言&#xf…

web shell控制目标

文章目录一、封神台五1、为什么提权2、如何寻找exp3、使用exp提权一、封神台五 1、为什么提权 进入目标机器后权限可能不够导致无法执行高权限操作 右键地址进入终端 发现没有操作权限 提权原理&#xff1a;借助高权限的进程执行我们的指令 2、如何寻找exp 什么是exp&a…

【MOSMA】基于粘菌算法求解多目标优化问题附matlab代码

✅作者简介&#xff1a;热爱科研的Matlab仿真开发者&#xff0c;修心和技术同步精进&#xff0c;matlab项目合作可私信。 &#x1f34e;个人主页&#xff1a;Matlab科研工作室 &#x1f34a;个人信条&#xff1a;格物致知。 更多Matlab仿真内容点击&#x1f447; 智能优化算法 …

【Java版oj】day02倒置字符串

目录 一、原题再现 二、问题分析 三、完整代码 一、原题再现 倒置字符串_牛客题霸_牛客网 描述 将一句话的单词进行倒置&#xff0c;标点不倒置。比如 I like beijing. 经过函数后变为&#xff1a;beijing. like I 输入描述&#xff1a; 每个测试输入包含1个测试用例&#x…

web前端期末大作业 html+css+javascript+jquery+bootstarp响应式鲜花售卖网站16页

&#x1f389;精彩专栏推荐 &#x1f4ad;文末获取联系 ✍️ 作者简介: 一个热爱把逻辑思维转变为代码的技术博主 &#x1f482; 作者主页: 【主页——&#x1f680;获取更多优质源码】 &#x1f393; web前端期末大作业&#xff1a; 【&#x1f4da;毕设项目精品实战案例 (10…

最新最全面的Java面试题及答案(212道)

文章目录一. Java 基础1. JDK 和 JRE 有什么区别&#xff1f;2. 和 equals 的区别是什么&#xff1f;3. 两个对象的 hashCode() 相同&#xff0c;则equals() 也一定为true&#xff0c;对吗&#xff1f;4. final 在 Java 中有什么作用&#xff1f;5. Java 中的 Math. round(-1.…

【图像分割】基于Kmean聚类 分水岭、oust、粒子群算法优化脂肪肝图像分割附matlab代码

✅作者简介&#xff1a;热爱科研的Matlab仿真开发者&#xff0c;修心和技术同步精进&#xff0c;matlab项目合作可私信。 &#x1f34e;个人主页&#xff1a;Matlab科研工作室 &#x1f34a;个人信条&#xff1a;格物致知。 更多Matlab仿真内容点击&#x1f447; 智能优化算法 …

OPT(奥普特)工控机新品上市,产品矩阵再扩大

近日&#xff0c;OPT&#xff08;奥普特&#xff09;发布工控机新品&#xff0c;进一步扩展产品矩阵&#xff0c;为制造业数字化转型提供更为全面的机器视觉产品和服务。 OPT&#xff08;奥普特&#xff09;上市的工控机共有两大系列&#xff0c;分别是3U桌面式和4U上架式的设…

【金猿人物展】映盛中国CEO谭运猛博士:数字化逆向重构将会占据行业红利成为新宠...

‍谭运猛本文由映盛中国创始人兼CEO谭运猛撰写并投递参与“数据猿年度金猿策划活动——2022大数据产业趋势人物榜单及奖项”评选。‍数据智能产业创新服务媒体——聚焦数智 改变商业2022年伴随着新冠疫情的反复和经济下行的持续影响&#xff0c;各行各业都面临着数字化转型的行…

【每日小技巧】如果Tomcat的端口被占用,怎么处理该报错

苦恼的问题&#xff1a;当我们在用Tomcat时&#xff0c;发现我们要用的端口被其他程序占用了&#xff0c;如图&#xff1a; 解决办法&#xff1a; ①winR&#xff0c;输入cmd&#xff0c;打开命令行 输入命令netstat -ano&#xff0c;列出所有的端口号使用情况 ②查看PID&#…

矩阵理论复习(四)

2003年试题 向量二范数也具有酉不变性 Schur定理的应用 向量范数的判定 向量范数的比较 酉矩阵的M-P广义逆就为该矩阵的转置 列满秩矩阵的左逆 一个矩阵乘以其逆矩阵等于单位矩阵&#xff0c;单位矩阵的算子范数均为1&#xff0c;算子范数的相容性 正规矩阵的性质 …

嵌入式:ARM的工作模式与寄存器组织

文章目录特权模式处理器启动时的模式转换图ARM的寄存器组织ARM寄存器组成概述ARM状态下的寄存器组织Thumb状态下的寄存器组织CPSR&#xff08;当前程序状态寄存器&#xff09;的低5位用于定义当前操作模式 , 如图示特权模式 除用户模式外的其他6种模式称为特权模式。 特权模式…

nodejs基于vue技术的小饰品购物商城网站

开发语言&#xff1a;nodejs 框架&#xff1a;Express 数据库&#xff1a;mysql 数据库工具&#xff1a;Navicat11 开发软件&#xff1a;VS code/HBuilder X 浏览器&#xff1a;谷歌浏览器 目录 1 绪论 1 1.1课题背景 1 1.2课题研究现状 1 1.3初步设计方法与实施方案 2 1.4本…