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. 20155212 2016-2017-2 《Java程序设计》第8周学习总结

    20155212 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 Chapter14 1. Channel架构与操作 想要取得Channel的实作对象,可以使 ...

  2. 20155210潘滢昊 2016-2017-2 《Java程序设计》第6周学习总结

    20155210 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 流(Stream)是对「输入输出」的抽象,注意「输入输出」是相对程序而言的 InputStr ...

  3. 【ORACLE】创建表空间

    CREATE TABLESPACE dna36 DATAFILE 'D:\oracle\oradata\orcl\dna36.dbf' SIZE 100M AUTOEXTEND ON NEXT 10M ...

  4. os_cpu_a.asm

    在OS_CPU_A.ASM中,定义了开.关中断的方法,在uC/OS-II系统中有三种方法可以实现中断开关,而ARM只适用于模式三,即使用一个局部变量,在中断进入之间保存CPU状态,退出时候再恢复状态. ...

  5. LEARN HOW TO HACK

    出处:https://www.hackerone.com/hacker101 什么是HACKER101? https://hacker101.com/Hacker101是一个视频,资源和实践活动的集合 ...

  6. va_start(),va_end()函数应用【转】

    转自:http://www.cnblogs.com/gogly/articles/2416833.html 原理解释: VA_LIST 是在C语言中解决变参问题的一组宏,在<stdarg.h&g ...

  7. 【译】EntityFramework6与EntityFrameworkCore的区别

    EntityFramework6 EF6 是一个久经考验的数据库访问技术,发展多年,拥有许多特性,并且成熟稳定.2008年EF作为 .Net 3.5 Sp1 和Visual Studio 2008 S ...

  8. [转]mysql性能优化-慢查询分析、优化索引和配置

    一. 优化概述 MySQL数据库是常见的两个瓶颈是CPU和I/O的瓶颈,CPU在饱和的时候一般发生在数据装入内存或从磁盘上读取数据时候.磁盘I/O瓶颈发生在装入数据远大于内存容量的时候,如果应用分布在 ...

  9. C# 各版本新特性

    C# 2.0 泛型(Generics) 泛型是CLR 2.0中引入的最重要的新特性,使得可以在类.方法中对使用的类型进行参数化. 例如,这里定义了一个泛型类: class MyCollection&l ...

  10. C#, CLR, and .NET Framework versions