当前位置:   article > 正文

FPGA-STM32-SPI通信_stm32与fpga的spi通讯

stm32与fpga的spi通讯

SPI

SPI,是英语Serial Peripheral Interface的缩写,顾名思义就是串行外围设备接口。SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用四根线,节约了芯片的管脚,同时为PCB的布局上节省空间,提供方便,正是出于这种简单易用的特性,现在越来越多的芯片集成了这种通信协议
在这里插入图片描述
在这里插入图片描述

Step1、检验管脚连接是否正确

由单片机传送数据到FPGA,在signaltap上验证
单片机部分代码

//main函数部分


#include "stm32f4xx.h"
#include "delay.h"
#include "test.h"
#include "SPI.h"

 void gpio_led_tick_loop(int n){
   
  int count = n;
  while(count) 
  {
   
    GPIO_SetBits(GPIOA,GPIO_Pin_15);
    delay_ms(2000); 
    GPIO_ResetBits(GPIOA,GPIO_Pin_15);
    delay_ms(2000); 
		break;
  }
}
 void gpio_clk_loop(){
   
  while(1) {
   
    GPIO_SetBits  (GPIOC,GPIO_Pin_4);          
    GPIO_ResetBits(GPIOC,GPIO_Pin_4);          
    GPIO_SetBits  (GPIOA,GPIO_Pin_7);          
    GPIO_ResetBits(GPIOA,GPIO_Pin_7);          
    GPIO_SetBits  (GPIOC,GPIO_Pin_5);          
    GPIO_ResetBits(GPIOC,GPIO_Pin_5);          
  }
}
int main(void) 
{
      
	delay_init(168);
	ALLGPIO_Init();
  gpio_led_tick_loop(1);
//  spi_wr_test_loop();
//  spi_wr_data_loop();
	gpio_clk_loop();
}



//管脚初始化设置


#include "test.h"

void ALLGPIO_Init(void)
{
       	 
  GPIO_InitTypeDef  GPIO_InitStructure;
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//±ØÐëʹÄÜGPIOAʱÖÓ
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);//±ØÐëʹÄÜGPIOCʱÖÓ
	
	//³õʼ»¯LED
  GPIOA->MODER=0x01;
  //GPIOA15³õʼ»¯ÉèÖÃ
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;//LED1¶ÔÓ¦IO¿ÚPA15
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//ÆÕͨÊä³öģʽ
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//ÍÆÍìÊä³ö
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//50MHz,ËÙ¶ÈÑ¡ÔñûÓдóÓ°Ïì
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//ÏÂÀ­£¬³õʼ״̬ʱÊä³öµÍµçƽ£¬µÆÃð
  GPIO_Init(GPIOA, 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/905889
推荐阅读
相关标签
  

闽ICP备14008679号