The STM32 SPI and FPGA communication
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的更多相关文章
- 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 ...
- 关于STM32 SPI NSS的讨论
NSS分为内部引脚和外部引脚. NSS外部引脚可以作为输入信号或者输出信号, 输入信号一般用作硬件方式从机的片选, 而输出信号一般用于主SPI去片选与之相连的从SPI. NSS从设备选择有两种模式: ...
- stm32 SPI介绍和配置
SPI是一种高速的,全双工同步的通信总线,在芯片管脚上占用了四根线,节约了芯片的管脚,同时为PCB的布局节省了空间,提供了方便,因此越来越多的芯片集成了这种通信协议,STM32也就有了SPI接口. 有 ...
- STM32 SPI 发送第一个数据不成功问题
STM32的标准库,跟HAL库都是很实用的, 在使用SPI库的过程中一定要注意时序的问题. 我在调试SPI过程中,调试了两个IC,都是用HAL库, 第一个IC没出问题,第二个IC出现了第一次发送数据不 ...
- STM32—SPI读写FLASH
目录 FLASH简介 W25Q64 W25Q64简介 FLASH控制指令 FLASH内部存储结构 代码讲解 读取芯片ID 发送写使能信号 等待FLASH不忙 擦除扇区 写入数据 读取数据 注 FLAS ...
- STM32—SPI详解
目录 一.什么是SPI 二.SPI协议 物理层 协议层 1.通讯时序图 2.起始和停止信号 3.数据有效性 4.通讯模式 三.STM32中的SPI 简介 功能框图 1.通讯引脚 2.时钟控制逻辑 3. ...
- STM32 SPI DMA 的使用
一是想总结一下SPI总线的特点与注意点,二是总结一下SPI DMA的使用 一.SPI信号线说明 通常SPI通过4个引脚与外部器件相连: MISO:主设备输入/从设备输出引脚.该引脚在从模式下发送数据, ...
- STM32.SPI(25Q16)
1.首先认识下W25Q16DVSIG, SOP8 SPI FLASH 16MBIT 2MB(4096个字节) (里面可以放字库,图片,也可以程序掉电不丢失数据放里面) 例程讲解: ① 1.用到SPI ...
- 2.2寸(14PIN)TFT液晶屏STM32 SPI 控制
屏幕如图所示,共14个IO口(也可能只有13个),控制屏幕的有9个IO口 详细版介绍见:http://www.ciast.net/post/20151112.html 反面IO口图: 连接通过SPI方 ...
随机推荐
- HDU 2086 A=? 数学题
题目描述:有一个公式,Ai = (Ai-1 + Ai+1)/2 - Ci (i = 1, 2, 3, .... n).,如果给出A0, An+1, 和 C1, C2, .....Cn要你计算出A1是多 ...
- 第11月第18天 RACSequence
1. RACSequence的内部存储结构就像一个单链表,有两个指针head和tail,head指针指向了当前链表的第一个元素,tail指向head指针下一个元素:根据RACSequence是否还有内 ...
- golang的sort研究
年前没钱,等发工资.就这么在公司耗着不敢回家,无聊看了下golang的sort源码 type Interface interface { // Len is the number of element ...
- react-native 报错
报错信息: java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sur ...
- Java工具库:
1. 重试框架: https://docs.spring.io/spring-batch/trunk/reference/html/retry.html <dependency> < ...
- .gitkeep
看一个开源项目中有个.gitkeep文件,不知道是干嘛用的查询知道 git是不允许提交一个空的目录到版本库上的,可以在空的文件夹里面建立一个.gitkeep文件,然后提交去即可. 其实在git中 .g ...
- android 调用系统照相机拍照后保存到系统相册,在系统图库中能看到
需求: 调用系统照相机进行拍照,并且保存到系统相册,调用系统相册的时候能看到 系统相册的路径:String cameraPath= Environment.getExternalStorageD ...
- yolov2在CUDA8.0+cudnn8.0下安装、训练、检测经历
这次用yolov2做检测时遇到个大坑,折腾了我好几天,特以此文记录之. 一.安装cuda+cudnn 它们的版本必须要匹配,否则训练后检测不出目标! 1.下载cuda8.0.61_375.26_lin ...
- Laravel中服务提供者和门面模式
在laravel中,我们可能需要用到自己添加的类时,可以建立一个文件夹专门存放类文件,也可以使用laravel的服务提供者的方式来使用. 这两者其实区别不大,主要是前者使用的话,会跟业务代码产生依赖, ...
- 一个浏览器Fuzzing框架的学习
一个浏览器Fuzzing框架的学习 关于框架 之前是LCatro师傅在小密圈分享的他写的这个Fuzzing框架(不过我以前翻github时好像就看到过),但是之前一直没啥时间搞这方面,这两天研究学习了 ...