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方 ...
随机推荐
- iOS8 自定义navigationItem.titleView
navigationBar其实有三个子视图,leftBarButtonItem,rightBarButtonItem,以及titleView.前两种的自定义请参考http://www.cnblogs. ...
- header()跳转
if ($toNews == 1) { header('Location:/ucenter/pageMailBox/2'); exit; } PHP跳转页面,用 header() 函数 定义和用法 h ...
- MongoDB 之 "$" 的奇妙用法 MongoDB - 5
在MongoDB中有一个非常神奇的符号 "$" "$" 在 update 中 加上关键字 就 变成了 修改器 其实 "$" 字符 独立出现 ...
- CTEX windedt 打开中文tex乱码问题
% !TEX encoding = System % !TEX program = pdflatex % !TEX encoding = System% !TEX program = pdflatex ...
- Ubuntu GNOME单击任务栏图标最小化设置
在Ubuntu GNOME的发行版中,桌面使用的是GNOME,GNOME可以像Windows那样有一个底部任务栏,在Ubuntu GNOME中它称为 dash to dock,如下图: Windows ...
- Windows::Docker::Ubuntu 做 SLAM
如题,这是一件很蛋疼的事情. 为了完成这一件事情,需要达成目标: Ubuntu GUI 必须要能够显示. Ubuntu 可以链接 USB Camera. 目标一 目标1很容易达成. 在 Win10 中 ...
- gcc __attribute__关键字举例之visibility【转】
转自:https://blog.csdn.net/starstarstone/article/details/7493144?utm_source=tuicool&utm_medium=ref ...
- usb_control_msg函数用法和说明
usb_control_msg是没有用到urb的在USB中简单进行发送和接收的一种机制,用于少量的数据通信.原型为: 程序代码 linux+v2.6.35/drivers/usb/core/mess ...
- dblinks
一.Oracle数据库链Database links的作用 当用户要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本 ...
- 二、vue中组件的使用
1.组件拆分 1.组件实质上也是一个vue实例,因此组件中也可以使用vue的对象属性,反过来每一个vue实例也是一个vue组件(注:1.唯一不同的是el是根实例的特有选项,2.组件中的data必须是一 ...