此博客为个人博客,不涉及商业用途,仅提供学习参考,内容均来自个人原创以及互联网转载和摘录。
此博客上带有原创标识的文章、图片、文件等,未经本人允许,不得用于商业用途以及传统媒体。
本文首发于CSDN,版权所有,禁止转载。
如需转载,请在评论区留言或私信申请,经同意后可转载,否则属于侵权行为

原博客链接:https://blog.csdn.net/qq_38305370
原博主昵称:城外南风起
————————————————

最近在做HDLBits的串行通讯协议(serial communications protocols)部分。记录在此。

目录

  • Serial receiver
  • Serial receiver and datapath
  • Serial receiver with parity checking

Serial receiver

原题目:

In many (older) serial communications protocols, each data byte is sent along with a start bit and a stop bit, to help the receiver delimit bytes from the stream of bits. One common scheme is to use one start bit (0), 8 data bits, and 1 stop bit (1). The line is also at logic 1 when nothing is being transmitted (idle).

Design a finite state machine that will identify when bytes have been correctly received when given a stream of bits. It needs to identify the start bit, wait for all 8 data bits, then verify that the stop bit was correct. If the stop bit does not appear when expected, the FSM must wait until it finds a stop bit before attempting to receive the next byte.

波形demo:


本题实现时设置了12个状态,分别为8个位状态BIT0至BIT7,4个描述状态DONE、STOP、IDLE、ERROR。
在波形中标注如下:

需要明确的逻辑是:当前的状态和当前的in没有关系,只和当前周期的上升沿时刻的in信号以及前一个状态有关。这里没有START状态,因为只要在BIT0状态前,接收器就是空转(IDLE)状态,不需要进行区分。

实现代码:

module top_module(input clk,input in,input reset,    // Synchronous resetoutput done
); parameter    BIT0 = 4'b0000, BIT1 = 4'b0001, BIT2 = 4'b0010, BIT3 = 4'b0011, BIT4 = 4'b0100, BIT5 = 4'b0101, BIT6 = 4'b0110, BIT7 = 4'b0111,DONE = 4'b1000, STOP = 4'b1001, IDLE = 4'b1010, ERROR = 4'b1011;reg [3:0] state, next_state;// State transition logic (combinational)always @(*) begin// State transition logiccase(state)IDLE: next_state = in ? IDLE : BIT0;BIT0: next_state = BIT1;BIT1: next_state = BIT2;BIT2: next_state = BIT3;            BIT3: next_state = BIT4;BIT4: next_state = BIT5;BIT5: next_state = BIT6;BIT6: next_state = BIT7;BIT7: next_state = STOP;STOP: next_state = in ? DONE : ERROR;ERROR: next_state = in ? IDLE : ERROR;DONE: next_state = in ? IDLE : BIT0;default: next_state = IDLE;endcaseend// State flip-flops (sequential)always @(posedge clk) beginif(reset) beginstate <= IDLE;endelse begin            state <= next_state;            endendassign done = (state == DONE);endmodule

Serial receiver and datapath

原题目:

Now that you have a finite state machine that can identify when bytes are correctly received in a serial bitstream, add a datapath that will output the correctly-received data byte. out_byte needs to be valid when done is 1, and is don’t-care otherwise.

Note that the serial protocol sends the least significant bit first.

波形demo见题目链接。从波形可以看出数据遵循LSB传输。

本题只是在Serial receiver的基础上加上了数据输出。

与verilog实现鼠标协议PS/2 mouse protocol的实现方法类似。注意在时序逻辑中获取数据即可。

此处给出代码:

module top_module(input clk,input in,input reset,    // Synchronous resetoutput [7:0] out_byte,output done
); //parameter  BIT0 = 4'b0000, BIT1 = 4'b0001, BIT2 = 4'b0010, BIT3 = 4'b0011, BIT4 = 4'b0100, BIT5 = 4'b0101, BIT6 = 4'b0110, BIT7 = 4'b0111,DONE = 4'b1000, STOP = 4'b1001, IDLE = 4'b1010, ERROR = 4'b1011;reg [3:0] state, next_state;// State transition logic (combinational)always @(*) begin// State transition logiccase(state)IDLE: next_state = in ? IDLE : BIT0;BIT0: next_state = BIT1;BIT1: next_state = BIT2;BIT2: next_state = BIT3;            BIT3: next_state = BIT4;BIT4: next_state = BIT5;BIT5: next_state = BIT6;BIT6: next_state = BIT7;BIT7: next_state = STOP;STOP: next_state = in ? DONE : ERROR;ERROR: next_state = in ? IDLE : ERROR;DONE: next_state = in ? IDLE : BIT0;default: next_state = IDLE;endcaseend// State flip-flops (sequential)reg bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7;always @(posedge clk) beginif(reset) beginstate <= IDLE;endelse begincase(state)BIT0: bit0 <= in;BIT1: bit1 <= in;BIT2: bit2 <= in;BIT3: bit3 <= in;BIT4: bit4 <= in;BIT5: bit5 <= in;BIT6: bit6 <= in;BIT7: bit7 <= in;endcasestate <= next_state;            endendassign done = (state == DONE);assign out_byte = {bit7, bit6, bit5, bit4, bit3, bit2, bit1, bit0};endmodule

Serial receiver with parity checking

原题目:

We want to add parity checking to the serial receiver. Parity checking adds one extra bit after each data byte. We will use odd parity, where the number of 1s in the 9 bits received must be odd. For example, 101001011 satisfies odd parity (there are 5 1s), but 001001011 does not.

Change your FSM and datapath to perform odd parity checking. Assert the done signal only if a byte is correctly received and its parity check passes. Like the serial receiver FSM, this FSM needs to identify the start bit, wait for all 9 (data and parity) bits, then verify that the stop bit was correct. If the stop bit does not appear when expected, the FSM must wait until it finds a stop bit before attempting to receive the next byte.

You are provided with the following module that can be used to calculate the parity of the input stream (It’s a TFF with reset). The intended use is that it should be given the input bit stream, and reset at appropriate times so it counts the number of 1 bits in each byte.

Note that the serial protocol sends the least significant bit first, and the parity bit after the 8 data bits.

波形demo见题目链接。

本题只是在Serial receiver and datapath的基础上加上了奇校验。所以需在BIT7后增加一个校验状态VER,在VER状态时利用异或检验1的奇偶个数。

实现代码:

module top_module(input clk,input in,input reset,    // Synchronous resetoutput [7:0] out_byte,output done
); //// Modify FSM and datapath from Fsm_serialdataparameter    BIT0 = 4'b0000, BIT1 = 4'b0001, BIT2 = 4'b0010, BIT3 = 4'b0011, BIT4 = 4'b0100, BIT5 = 4'b0101, BIT6 = 4'b0110, BIT7 = 4'b0111,DONE = 4'b1000, STOP = 4'b1001, IDLE = 4'b1010, ERROR = 4'b1011, VER = 4'b1100;reg [3:0] state, next_state;    // State transition logic (combinational)always @(*) begin// State transition logiccase(state)IDLE: next_state = in ? IDLE : BIT0;BIT0: next_state = BIT1;BIT1: next_state = BIT2;BIT2: next_state = BIT3;            BIT3: next_state = BIT4;BIT4: next_state = BIT5;BIT5: next_state = BIT6;BIT6: next_state = BIT7;BIT7: next_state = VER;VER: next_state = STOP;STOP: next_state = in ? DONE : ERROR;ERROR: next_state = in ? IDLE : ERROR;DONE: next_state = in ? IDLE : BIT0;default: next_state = IDLE;endcaseend// State flip-flops (sequential)reg bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7,odd;always @(posedge clk) beginif(reset) beginstate <= IDLE;endelse begin            case(state)BIT0: bit0 <= in;BIT1: bit1 <= in;BIT2: bit2 <= in;BIT3: bit3 <= in;BIT4: bit4 <= in;BIT5: bit5 <= in;BIT6: bit6 <= in;BIT7: bit7 <= in;VER: odd <= ^out_byte[7:0]^in;endcase            state <= next_state;            endendassign done = (state == DONE && odd);assign out_byte = {bit7, bit6, bit5, bit4, bit3, bit2, bit1, bit0};// New: Add parity checking.endmodule

————————————————
感谢您的阅读,如果您有收获,请给我一个三连吧!
如果您觉得这还不够,可以点击 打赏 按钮,告诉我: 你币有了!

verilog实现串行通讯协议(serial communications protocols)相关推荐

  1. UART、SPI、I2C串行通讯协议解释 同步/异步 全双工/半双工通信含义

    欢迎加入QQ技术交流群:100479172 一.什么是同步/异步通信? 同步通信:一方发送,另一方应答,否则不进行下一次传输(带时钟同步信号传输). 异步通信:一方发送,不考虑另一方是否收到,直接进行 ...

  2. 三菱 fx2n 通信 linux 代码,三菱FX2N PLC串行通讯指令(FNC 80 RS)

    三菱FX2N PLC串行通讯指令(FNC 80 RS) 串行通讯指令(FNC 80 RS) 1.指令格式:    [RS     D0     K8     D10    K8] 发送数据帧起始地址和 ...

  3. 嵌入式硬件协议: SPI串行外设接口 Serial Peripheral Interface

    简介 SPI 协议是由摩托罗拉公司提出的通讯协议(Serial Peripheral Interface),即串行外围设备接口,是 一种高速全双工的通信总线.它被广泛地使用在ADC.LCD 等设备与M ...

  4. 硬件通讯协议:串行通讯、IPMI、IPMB、SMbus、NCSI等

    串行通讯和串口的关系 串行是指在数字电路或通信中,数据位按照一定的顺序逐个传输的方式.在串行传输中,每个数据位都是依次传输的,而不是同时传输的.相对于并行传输,串行传输需要更长的传输时间,但是可以使用 ...

  5. 基于51的串行通讯原理及协议详解(uart)

    串行与并行通讯方式 并行:控制简单,传输速度快.线多,长距离成本较高且同时接受困难. 串行:将数据字节分成一位一位的行驶在一条传输线上进行传输.如图: 同步与异步串行通讯方式 同步串行通讯方式:同步通 ...

  6. 串行通讯RS485 Modbus RTU协议控制

    一.内容简介 本文主要介绍欧姆龙CP1E做上位与SMC的LECP6电缸 之间串行通讯RS485 Modbus RTU协议程序控制说明. 二.设备简介         硬件:CP1E.CP1W-CIF1 ...

  7. SPI、I2C、UART三种串行总线协议的区别和SPI接口介绍(转)

    SPI.I2C.UART三种串行总线协议的区别 第一个区别当然是名字: SPI(Serial Peripheral Interface:串行外设接口); I2C(INTER IC BUS) UART( ...

  8. 单片机的串行通讯就是排成一队走,并行就是排成一列走

    单片机的串行通讯就是排成一队走,并行就是排成一列走 ///插播一条:我自己在今年年初录制了一套还比较系统的入门单片机教程,想要的同学找我拿就行了免費的,私信我就可以哦~点我头像黑色字体加我地球呺也能领 ...

  9. 三种串行总线协议的区别(SPI、I2C和UART)

    SPI.I2C跟UART三种串行总线协议的区别: (如果想了解SPI和I2C更多详细内容,可看 SPI总线(一):基本原理篇, SPI总线(二):驱动分析篇,SPI总线(三):驱动实例,i2c总线(基 ...

  10. [转载]Palm 串行通讯GPS数据读取的实现

    Palm 串行通讯GPS数据读取的实现 关于J2ME程序编写的教程,各大网站均有介绍.但是J2ME教程的学习与实际应用毕竟还有一段距离.笔者从事J2ME一年多, 已经成功地开发出基于无线互联网palm ...

最新文章

  1. php 数组格式的字符串转为数组_php将字符串转换为数组实例讲解
  2. CocoaPods was not found 解决
  3. 2016年大学计算机期末试题及答案,2016年大学计算机基础试题题库及答案
  4. Sencha Touch2中数据的获取
  5. Linux下最快速共享目录的方法
  6. 网安入门须知:注释的危害居然这么大?——注释漏洞导致的信息泄露
  7. mysql sql语句for循环语句怎么写_mysql循环语句for循环
  8. 在HTML中什么表示水平线,HTML中加入水平线的标签是( )
  9. 1每天Python小例-12306爬虫#WinError 2
  10. 给你们申请的优惠购开发板,购书活动
  11. 电脑耳机拔出后,再插入没声音
  12. 图像分割常见Loss
  13. 对Android apk 签名 --apksigner
  14. 迷糊到清楚,清楚又到迷糊
  15. e-icon-picker
  16. 金蝶在虚拟机安装服务器端,金蝶KIS旗舰版V6.0安装运行环境
  17. 重写confirm,alert
  18. TC358840XBG HDMI 转 CSI 中文手册
  19. Python——unfold()函数
  20. 第二阶段 筑基期(4-6 周,每周 8-10 小时)- 1

热门文章

  1. 群晖存储服务器虚拟机,安装黑群晖DSM6.2.1完整教程(虚拟机VMWARE15)
  2. 【参赛作品101】充实openGauss每日一练21天学习完成大总结
  3. 实数系与实数定理(下)
  4. 个人免签支付接口二维码扫码支付
  5. ceph存储 PG的状态机和peering过程
  6. Java程序编写 • 【第4章 程序:随机本周菜品;简易计算器】
  7. iphone计算机照片大小,如何把iphone照片导入电脑 四种方法分享【图文】
  8. V神站台--黑马BZZ究竟如何?和FIL 有什么区别?
  9. tableau实战系列(十二)-使用盒须图查看你的数据分布
  10. 很多网友问那个磁力搜索站好用,就由本君说说吧!