The STM32 SPI and FPGA communication

STM32 spi bus communication

SPI bus in the study, the protocol and hardware description is not to say that the four-wire, including clock, chip select, receive, send

SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; / / full-duplex
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; / / master mode
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; / / 16bit width
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; / / - 18MHz; - 9MHz; - .5MHz
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; / / high byte first
SPI_InitStructure.SPI_CRCPolynomial = ;
SPI_Init (SPIx, & SPI_InitStructure);
SPI_Cmd (SPIx, ENABLE);

SPI has no hardware control CS, can only be controlled by the software is by NSS the external GPIO to control.

Like my projects STM32 communication with the FPGA, the FPGA SPI In this state as a master of the STM32,

CS transmission data is low after the transmission must be pulled so that the FPGA can be judged SPI Transfer start and end state.

FPGA data transfer format is 16bit address +16 bit data for read 16bit

uint16_t spi_read (SPI_TypeDef * SPIx, uint32_t addr)
{
uint16_t value;
The uint16_t spi_nss;
uint16_t add;
uint32_t level; if (SPI1 == SPIx)
spi_nss = SPI1_PIN_NSS;
else if (SPI2 == SPIx)
spi_nss = SPI2_PIN_NSS; while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_TXE) == RESET);
GPIO_ResetBits (GPIOA, spi_nss);
SPI_I2S_SendData (SPIx, addr); / / 0xf014 >> while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData (SPIx 0x0); while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_RXNE) == RESET);
SPI_I2S_ReceiveData (SPIx); while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_TXE) == RESET);
GPIO_SetBits (GPIOA, spi_nss); while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_RXNE) == RESET);
the value = SPI_I2S_ReceiveData (SPIx); return value;
} Write function void spi_write (SPI_TypeDef * SPIx, uint32_t addr, uint16_t value)
{ The uint16_t spi_nss; uint32_t level; if (SPI1 == SPIx)
spi_nss = SPI1_PIN_NSS;
else if (SPI2 == SPIx)
spi_nss = SPI2_PIN_NSS; while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_TXE) == RESET);
GPIO_ResetBits (GPIOA, spi_nss);
SPI_I2S_SendData (SPIx, addr); while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData (SPIx, value); while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_RXNE) == RESET);
SPI_I2S_ReceiveData (SPIx); while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_TXE) == RESET);
GPIO_SetBits (GPIOA, spi_nss); while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_RXNE) == RESET);
SPI_I2S_ReceiveData (SPIx);
}

Take the write function example only so many design

because if it is the beginning of the function will be the NSS pin is pulled low, and then go Send as follows

GPIO_ResetBits (GPIOA, spi_nss); 
while (SPI_I2S_GetFlagStatus (SPIx, SPI_I2S_FLAG_TXE) == RESET); 
SPI_I2S_SendData (SPIx, addr);

This CS low after a period of time (the time there are about 16 clock cycles),

only CLK, this delay will reduce the transmission efficiency of the SPI

That way before CS Euphrates will soon have clk clock out

The reason why I wrote twice read it twice instead of reading a written also taking into account the efficiency problem

If you write once read it again to see a relatively large gap between each data of the waveform is not clk,

that will have to wait a period of time, then transmit a data require a relatively high speed The device is not allowed

It is worth noting that:

If the SPI master mode, the GPIO is set to 
NSS is GPIO_Mode_Out_PP 
CLK is GPIO_Mode_AF_PP 
MOSI is GPIO_Mode_AF_PP 
MISO is GPIO_Mode_IN_FLOATING

If the SPI Slave mode, the GPIO is set to 
NSS is GPIO_Mode_Out_PP 
CLK is GPIO_Mode_IN_FLOATING 
MOSI is GPIO_Mode_IN_FLOATING 
MISO is GPIO_Mode_AF_PP

The STM32 SPI and FPGA communication的更多相关文章

  1. HOWTO: Use STM32 SPI half duplex mode

    HOWTO: Use STM32 SPI half duplex mode I’ve got my hands onto some STM32F030F4P6 ARM-Cortex M0 proces ...

  2. 关于STM32 SPI NSS的讨论

    NSS分为内部引脚和外部引脚. NSS外部引脚可以作为输入信号或者输出信号, 输入信号一般用作硬件方式从机的片选, 而输出信号一般用于主SPI去片选与之相连的从SPI. NSS从设备选择有两种模式: ...

  3. stm32 SPI介绍和配置

    SPI是一种高速的,全双工同步的通信总线,在芯片管脚上占用了四根线,节约了芯片的管脚,同时为PCB的布局节省了空间,提供了方便,因此越来越多的芯片集成了这种通信协议,STM32也就有了SPI接口. 有 ...

  4. STM32 SPI 发送第一个数据不成功问题

    STM32的标准库,跟HAL库都是很实用的, 在使用SPI库的过程中一定要注意时序的问题. 我在调试SPI过程中,调试了两个IC,都是用HAL库, 第一个IC没出问题,第二个IC出现了第一次发送数据不 ...

  5. STM32—SPI读写FLASH

    目录 FLASH简介 W25Q64 W25Q64简介 FLASH控制指令 FLASH内部存储结构 代码讲解 读取芯片ID 发送写使能信号 等待FLASH不忙 擦除扇区 写入数据 读取数据 注 FLAS ...

  6. STM32—SPI详解

    目录 一.什么是SPI 二.SPI协议 物理层 协议层 1.通讯时序图 2.起始和停止信号 3.数据有效性 4.通讯模式 三.STM32中的SPI 简介 功能框图 1.通讯引脚 2.时钟控制逻辑 3. ...

  7. STM32 SPI DMA 的使用

    一是想总结一下SPI总线的特点与注意点,二是总结一下SPI DMA的使用 一.SPI信号线说明 通常SPI通过4个引脚与外部器件相连: MISO:主设备输入/从设备输出引脚.该引脚在从模式下发送数据, ...

  8. STM32.SPI(25Q16)

    1.首先认识下W25Q16DVSIG, SOP8 SPI FLASH 16MBIT  2MB(4096个字节) (里面可以放字库,图片,也可以程序掉电不丢失数据放里面) 例程讲解: ① 1.用到SPI ...

  9. 2.2寸(14PIN)TFT液晶屏STM32 SPI 控制

    屏幕如图所示,共14个IO口(也可能只有13个),控制屏幕的有9个IO口 详细版介绍见:http://www.ciast.net/post/20151112.html 反面IO口图: 连接通过SPI方 ...

随机推荐

  1. 20145234黄斐《Java程序设计》第八周

    教材学习内容总结 第十四章-NIO与NIO2 NIO与IO的区别 NIO Channel继承框架 想要取得Channel的操作对象,可以使用Channels类,它定义了静态方法newChannel() ...

  2. Linux - ssh 连接慢解决

    解决 ssh 链接慢 sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config sed -i ...

  3. python的一个小原理

    在许多语言当中,类似于a.b()这样的调用方法是一个整体,但在Python中,它其实是两部分:获取属性a.b,调用().所以也可以写成: c = a.b c() 2.关于继承 class a: num ...

  4. (A - 整数划分 HYSBZ - 1263)(数组模拟大数乘法)

    题目链接:https://cn.vjudge.net/problem/HYSBZ-1263 题目大意:中文题目 具体思路:先进了能的拆成3,如果当前剩下的是4,就先不减去3,直接乘4,如果还剩2的话, ...

  5. lucene查询索引之QueryParser解析查询——(八)

    0.语法介绍:

  6. mysql+mycat压力测试一例【转】

    前言 有很多人担心生产系统上新东西的程序怕压力跟不上和稳定性不行,是的,大家都怕,所以领导要求做一次压力测试,我个人也觉得是有必要的. 如果按原理来说,mycat如果不做分片,纯粹只是代理的话,他所做 ...

  7. JavaScript中对象与函数的某些事[JavaScript语言精粹-N1]

    今天在读<JavaScript语言精粹>的时候,关于函数的一个部分,始终觉得有点难以理解,代码如下: 1: var obj = (function(){ 2: var value = 0; ...

  8. 关于spring中Assert的应用(方法入参检测工具类)

    关于spring中Assert的应用(方法入参检测工具类) Web 应用在接受表单提交的数据后都需要对其进行合法性检查,如果表单数据不合法,请求将被驳回.类似的,当我们在编写类的方法时,也常常需要对方 ...

  9. ZJOI2019爆蛋记

    Day-2 玩了一个下午,逛了填海校园,晚上吃肯德基 Day-1 上午听lyx巨佬讲课,讲到一半发现,越听越听不懂... 于是打开电脑开始刷知乎 下午听kcz孔爷讲课,emmmm电脑被我玩没电了... ...

  10. dataframe 差集

    >>>data_a={'state':[1,1,2],'pop':['a','b','c']}>>>data_b={'state':[1,2,3],'pop':[' ...