CN104331381B - Spi芯片抗干扰输出方法 - Google Patents

Spi芯片抗干扰输出方法 Download PDF

Info

Publication number
CN104331381B
CN104331381B CN201410668585.4A CN201410668585A CN104331381B CN 104331381 B CN104331381 B CN 104331381B CN 201410668585 A CN201410668585 A CN 201410668585A CN 104331381 B CN104331381 B CN 104331381B
Authority
CN
China
Prior art keywords
data
output
spi
chips
spi chips
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201410668585.4A
Other languages
English (en)
Other versions
CN104331381A (zh
Inventor
周晓峰
胡炎良
陆坚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hunan Super Information Co Ltd
Original Assignee
Hunan Super Information Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hunan Super Information Co Ltd filed Critical Hunan Super Information Co Ltd
Priority to CN201410668585.4A priority Critical patent/CN104331381B/zh
Publication of CN104331381A publication Critical patent/CN104331381A/zh
Application granted granted Critical
Publication of CN104331381B publication Critical patent/CN104331381B/zh
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/14Handling requests for interconnection or transfer
    • G06F13/20Handling requests for interconnection or transfer for access to input/output bus
    • G06F13/28Handling requests for interconnection or transfer for access to input/output bus using burst mode transfer, e.g. direct memory access DMA, cycle steal
    • G06F13/282Cycle stealing DMA
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2213/00Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F2213/28DMA
    • G06F2213/2804Systems and methods for controlling the DMA frequency on an access bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)

Abstract

本发明公开了SPI芯片抗干扰输出方法,SPI芯片抗干扰输出方法,包括以下步骤:步骤一:在设计硬件时,通过SPI芯片最后一个菊花链输出接口连接到CPU的输入接口,保证SPI芯片输出的数据可以再次回读到CPU;步骤二:在软件设计时,通过SPI芯片最后一个菊花链的Dout引脚回读输出的数据,把相同的数据输进同一个SPI芯片的菊花链网络,在最后一个SPI芯片的输出Dout引脚可以得到前一次的输进的数据;每次把得到的数据进行比较,数据相等则表示当前数据正确,可以输出。

Description

SPI芯片抗干扰输出方法
技术领域
本发明涉及工业自动控制领域,特别是SPI芯片抗干扰输出方法。
背景技术
SPI是一种高速的、全双工、同步的通信总线,并且在芯片的管脚上只占用四根线,节约了芯片的管脚,同时为PCB的布局上节省空间,提供方便,正是出于这种简单易用的特性,如今越来越多的芯片集成了这种通信协议;SPI的通信原理很简单,它以主从方式工作,这种模式通常有一个主设备和一个或多个从设备,需要至少4根线,事实上3根也可以(单向传输时),也是所有基于SPI的设备共有的,它们是Din(数据输入)、Dout(数据输出)、CLK(时钟)、CS(片选);不管那种SPI数据通信方式,由于采用的是串行通讯,从SPI芯片一般没有CPU功能,仅仅有数据接收功耗,而SPI串行数据在传输过程中,由于时间跨度很长,导致数据容易受到干扰,任何一个小的干扰错误会引起SPI类型的输出芯片的输出不确定性,可能会导致灾难性结果,甚至人身安全都受到很到的威胁。
目前,常规的现场总线型的控制器的模拟量输出AO和数字量输出DO都是采用SPI类型的芯片作为输出,在介质上传输的都是数字信号,由于干扰噪音的原因,使得“1”变成了“0”,“0”变成了“1”,从而影响到SPI芯片的性能,甚至于SPI芯片不能正常工作。由于我公司的控制器的安装环境复杂,多在火力发电厂、冶炼冶金行业,现场不确定因素多,容易受到干扰,不管从理论分析,还是从经验获得,SPI芯片的抗干扰能力没有校验功能,研究并解决SPI芯片的抗干扰问题非常重要。
发明内容
本发明的目的是提供一种SPI芯片抗干扰输出方法。
本发明是通过以下技术方案予以实现的:
SPI芯片抗干扰输出方法,包括以下步骤:
步骤一:在设计硬件时,通过SPI芯片最后一个菊花链输出接口连接到CPU的输入接口,保证SPI芯片输出的数据可以再次回读到CPU;
步骤二:在软件设计时,通过SPI芯片最后一个菊花链的Dout引脚回读输出的数据,把相同的数据输进同一个SPI芯片的菊花链网络,在最后一个SPI芯片的输出Dout引脚可以得到前一次的输进的数据;每次把得到的数据进行比较,数据相等则表示当前数据正确,可以输出;软件的具体步骤如下:
步骤①:CPU上电后第一次输出到SPI芯片的移位寄存器数据时保存在m_DATA_OUT_CUR,通过SPI_DOUT引脚回读移位寄存器的数据m_DATA_OUT_BACK确认与m_DATA_OUT_CUR相等后,保存在变量中m_DATA_OUT_PRE,然后使能移位寄存器的内容输出到输出控制寄存器,完成一次正确输出;
步骤②:第二次及其以后的输出,比较m_DATA_OUT_CUR是否与m_DATA_OUT_PRE相等,在这里有两种情况:
A.相等:则SPI芯片的输出行为与前一次输出行为保持一致,所以不必要输出数据,减少CPU的负担的同时大大降低了干扰的可能性;
B.不相等:通过SPI_DIN口输出数据m_DATA_OUT_CUR同时在SPI_DOUT回读的数据保存在m_DATA_OUT_BACK,则 m_DATA_OUT_BACK 保存的应该是m_DATA_OUT_PRE相等的数据,比较m_DATA_OUT_CUR是否与m_DATA_OUT_PRE相等;不相等则表示受到干扰,这时可以再次输出数据进入SPI芯片直到m_DATA_OUT_CUR与m_DATA_OUT_BACK相等;
步骤③:通过SPI芯片使能输出引脚输出移位寄存器的内容到输出控制寄存器,完成一次正确的输出。
附图说明
图1是本发明的软件设计流程图;
图2是本发明的硬件接口示意图
具体实施方式
下面结合附图对本发明的实施例做进一步描述:
如图1所示,在设计硬件时,通过SPI芯片最后一个菊花链输出接口连接到CPU的输入接口,保证SPI芯片输出的数据可以再次回读到CPU;
如图2所示,SPI芯片通信的结构如下:
struct spi_device {
struct spi_master *master; //设备使用的master结构
u32 max_speed_hz; //通讯时钟
u8 chip_select; //片选号,每个master支持多个spi_device
u8 mode; //设备支持的模式,如片选是高or低
#define SPI_CPHA 0x01 /* clock phase */
#define SPI_CPOL 0x02 /* clock polarity */
#define SPI_MODE_0 (0|0) /* (original MicroWire) */
#define SPI_MODE_1 (0|SPI_CPHA)
#define SPI_MODE_2 (SPI_CPOL|0)
#define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
#define SPI_CS_HIGH 0x04 /* chipselect active high */
#define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */
#define SPI_3WIRE 0x10 /* SI/SO signals shared */
#define SPI_LOOP 0x20 /* loopback mode */
#define SPI_NO_CS 0x40 /* 1 dev/bus, no chipselect */
#define SPI_READY 0x80 /* slave pulls low to pause */
u8 bits_per_word; //每个字长的比特数
int irq; //中断号
void *controller_state; //控制器寄存器状态
void *controller_data;
char modalias[SPI_NAME_SIZE]; //设备名称
};
struct spi_master {
struct device dev; //设备模型使用
s16 bus_num; //master编号
u16 num_chipselect; //支持的片选的数量,从设备的片选号不能大于这个数量
u16 dma_alignment;
/* spi_device.mode flags understood by this controller driver */
u16 mode_bits; //master支持的设备模式
/* other constraints relevant to this driver */
u16 flags; //一些额外的标志
#define SPI_MASTER_HALF_DUPLEX BIT(0) /* can't do full duplex*/
#define SPI_MASTER_NO_RX BIT(1) /* can't do buffer read */
#define SPI_MASTER_NO_TX BIT(2) /* can't do buffer write */
Int (*setup)(struct spi_device *spi); //设置模式、时钟等
int (*transfer)(struct spi_device *spi, //数据发送函数
struct spi_message *mesg);
/* called on release() to free memory provided by spi_master */
Void (*cleanup)(struct spi_device *spi);
};
struct spi_transfer {
const void *tx_buf; //发送缓冲区
void *rx_buf; //接收缓冲区
unsigned len; //缓冲区长度
dma_addr_t tx_dma;
dma_addr_t rx_dma;
unsigned cs_change:1; //当前spi_transfer发送完成之后重新片选
u8 bits_per_word; //每个字长的比特数,0代表使用Spi_device中的默认值
u16 delay_usecs; //发送完成一个spi_transfer后延时时间
u32 speed_hz; //速率
struct list_head transfer_list; //用于链接到spi_message
};

Claims (1)

1.SPI芯片抗干扰输出方法,包括以下步骤:
步骤一:在设计硬件时,通过SPI芯片最后一个菊花链输出接口连接到CPU的输入接口,保证SPI芯片输出的数据可以再次回读到CPU;
步骤二:在软件设计时,通过SPI芯片最后一个菊花链的Dout引脚回读输出的数据,把相同的数据输进同一个SPI芯片的菊花链网络,在SPI芯片最后一个菊花链的Dout引脚可以得到前一次的输进的数据;每次把得到的数据进行比较,数据相等则表示当前数据正确,可以输出;软件的具体步骤如下:
步骤①:CPU上电后第一次输出到SPI芯片的移位寄存器数据时保存在m_DATA_OUT_CUR,通过最后一个菊花链的Dout引脚回读移位寄存器的数据m_DATA_OUT_BACK确认与m_DATA_OUT_CUR相等后,保存在变量m_DATA_OUT_PRE中,然后使能移位寄存器的内容输出到输出控制寄存器,完成一次正确输出;
步骤②:第二次及其以后的输出,比较m_DATA_OUT_CUR是否与m_DATA_OUT_PRE相等,在这里有两种情况:
A.相等:则SPI芯片的输出行为与前一次输出行为保持一致,所以不必要输出数据,减少CPU的负担的同时大大降低了干扰的可能性;
B.不相等:通过最后一个菊花链的Dout引脚输出数据m_DATA_OUT_CUR同时在最后一个菊花链的Dout引脚回读的数据保存在m_DATA_OUT_BACK,则m_DATA_OUT_BACK保存的应该是与m_DATA_OUT_CUR相等的数据,比较m_DATA_OUT_CUR是否与m_DATA_OUT_BACK相等;不相等则表示受到干扰,这时可以再次输出数据进入SPI芯片直到m_DATA_OUT_CUR与m_DATA_OUT_BACK相等;
步骤③:通过SPI芯片使能输出引脚输出移位寄存器的内容到输出控制寄存器,完成一次正确的输出。
CN201410668585.4A 2014-11-21 2014-11-21 Spi芯片抗干扰输出方法 Active CN104331381B (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410668585.4A CN104331381B (zh) 2014-11-21 2014-11-21 Spi芯片抗干扰输出方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410668585.4A CN104331381B (zh) 2014-11-21 2014-11-21 Spi芯片抗干扰输出方法

Publications (2)

Publication Number Publication Date
CN104331381A CN104331381A (zh) 2015-02-04
CN104331381B true CN104331381B (zh) 2017-07-28

Family

ID=52406112

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410668585.4A Active CN104331381B (zh) 2014-11-21 2014-11-21 Spi芯片抗干扰输出方法

Country Status (1)

Country Link
CN (1) CN104331381B (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113312294B (zh) * 2020-02-27 2024-06-18 瑞昱半导体股份有限公司 电子装置以及通讯方法
CN114756498A (zh) * 2020-12-29 2022-07-15 Tcl科技集团股份有限公司 芯片、主控芯片、芯片通信方法、芯片阵列及相关设备

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN201769766U (zh) * 2010-08-06 2011-03-23 浙江吉利汽车研究院有限公司 一种新能源汽车can总线控制***

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9274997B2 (en) * 2012-05-02 2016-03-01 Smsc Holdings S.A.R.L. Point-to-point serial peripheral interface for data communication between devices configured in a daisy-chain
US8943250B2 (en) * 2012-08-20 2015-01-27 General Electric Systems and methods for concatenating multiple devices

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN201769766U (zh) * 2010-08-06 2011-03-23 浙江吉利汽车研究院有限公司 一种新能源汽车can总线控制***

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
AVR单片机SPI通信的一种抗干扰方法;郝立忠;《单片机与嵌入式***应用》;20010201(第2期);第75-84页 *

Also Published As

Publication number Publication date
CN104331381A (zh) 2015-02-04

Similar Documents

Publication Publication Date Title
CN108052473B (zh) 串行通信装置
EP2587385A1 (en) Usb key device and method for realizing intelligent card communication using usb interface
CN108255776B (zh) 一种兼容apb总线的i3c主设备、主从***及通信方法
CN105824777A (zh) 一种spi总线在ipran设备中的实现方法
CN103399830B (zh) 通过PCI Express总线读取计算机物理内存的设备及方法
Liu et al. IP design of universal multiple devices SPI interface
WO2009031737A1 (en) Universal high-speed real-time monitoring device for embedded systems
CN105786741B (zh) 一种soc高速低功耗总线及转换方法
JP2008234222A (ja) Usbコントローラ及びusbコントローラ試験方法
CN114564427A (zh) 一种ahb总线到i2c总线的总线桥、***及方法
CN104331381B (zh) Spi芯片抗干扰输出方法
CN106294228B (zh) 输入输出扩展芯片以及其验证方法
CN103873031A (zh) 非时钟触发寄存器
CN101188488A (zh) 半双工通讯收发控制方法及装置
Wan et al. Application and implementation of CAN bus technology in industry real-time data communication
CN208314763U (zh) 一种用于PCIe信号机箱外部传输的Retimer板卡
CN201378316Y (zh) 通用输入/输出接口扩展电路和具有该电路的移动终端
CN105550146B (zh) 一种opb总线和ips总线之间的桥装置
CN103645689B (zh) 一种基于差分信号的单总线传输装置
CN207676338U (zh) 一种单个usb转rs485,rs422,rs232和ttl电平的电路
CN208190652U (zh) 一种全双工通用同步异步串行收发器的主板
CN203455834U (zh) 一种应用于pxi测试平台的菊花链型触发背板
JP5926583B2 (ja) 情報処理装置、シリアル通信システムおよびそれらの通信初期化の方法、並びにシリアル通信装置
CN207319229U (zh) 简易rs232多功能串口扩展装置
CN207976877U (zh) 数据传输***

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: Anti-interference output method for SPI (serial peripheral interface) chips

Effective date of registration: 20190522

Granted publication date: 20170728

Pledgee: Bank of Communications Co.,Ltd. Hunan Branch

Pledgor: HUNAN SUPER INFORMATION Co.,Ltd.

Registration number: 2019430000045

PE01 Entry into force of the registration of the contract for pledge of patent right
PC01 Cancellation of the registration of the contract for pledge of patent right

Date of cancellation: 20201214

Granted publication date: 20170728

Pledgee: Bank of Communications Co.,Ltd. Hunan Branch

Pledgor: HUNAN SUPER INFORMATION Co.,Ltd.

Registration number: 2019430000045

PC01 Cancellation of the registration of the contract for pledge of patent right
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: Anti interference Output Method of SPI Chip

Effective date of registration: 20221101

Granted publication date: 20170728

Pledgee: Huarong Bank of Xiangjiang Limited by Share Ltd. Changsha branch

Pledgor: HUNAN SUPER INFORMATION Co.,Ltd.

Registration number: Y2022430000095

PE01 Entry into force of the registration of the contract for pledge of patent right
PM01 Change of the registration of the contract for pledge of patent right

Change date: 20240726

Registration number: Y2022430000095

Pledgee after: Bank of Hunan Co.,Ltd. Changsha Branch

Pledgee before: Huarong Bank of Xiangjiang Limited by Share Ltd. Changsha branch