微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > s5pv210与stm32 spi通信

s5pv210与stm32 spi通信

时间:11-19 来源:互联网 点击:

STM32主函数代码:

#include "stm32f10x.h"#include "uart.h"#include "spi.h"void SPItest(void);void UARTtest(USART_TypeDef *port);extern void Uart_SendStringn(USART_TypeDef *port,char *pt,int n);extern  void Delay_ARMJISHU(__IO uint32_t nCount);void SPIsend_Init(void){GPIO_InitTypeDef  GPIO_InitStructure;//spi send interrupt controlRCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOC, ENABLE);//	使能PC,AFIOGPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  //推挽输出 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //GPIO_Init(GPIOC, &GPIO_InitStructure); //end}void send_onoff(int onoff){if(onoff)GPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_RESET);elseGPIO_WriteBit(GPIOC, GPIO_Pin_7, Bit_SET);}int main(void){//int i;NVIC_Configuration();//配置  NVIC 和 Vector Table Uart1_COMInit(115200); //串口1连接v210或PC机SPI1_Init();SPIsend_Init();  send_onoff(Bit_RESET);Uart_SendString(USART1,"串口1开始:\r\n") ;	//串口1接PC机while (1){SPItest();}}void send_data(int mode){int i;send_onoff(Bit_SET);switch(mode){case 0x01:for(i=0;i<38;i++){SPI_I2S_SendData(SPI1,i + 1);}break;case 0x02:for(i=0;i<38;i++){SPI_I2S_SendData(SPI1,i + 2);}break;case 0x03:for(i=0;i<38;i++){SPI_I2S_SendData(SPI1,i + 3);}break;default:break;}send_onoff(Bit_RESET);cmd = 0;return;}void SPItest(void){int i;//static int	x=0;if(RxIdx==SPI_BufferSize) //中断方式接收{cmd = SPI1_Buffer_Rx[0];for(i=0;i< RxIdx;i++){Uart_SendByte(USART1,SPI1_Buffer_Rx[i]);//向PC机发送// SPI_I2S_SendData(SPI1,0xff); SPI1_Buffer_Rx[i]=0;}//while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);//SPI_I2S_SendData(SPI1,x++);//send_onoff(1);//SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);//Delay_ARMJISHU(10000000);RxIdx=0;SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);}if(cmd)send_data(cmd);//查询方式接收:/*while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET);SPI3_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI3);if(RxIdx==SPI_BufferSize){for(i=0;i< RxIdx;i++){Uart_SendByte(USART1,SPI3_Buffer_Rx[i]);//向PC机发送}RxIdx=0;}*/}void UARTtest(USART_TypeDef *port){int i;for(i=0;i<10;i++)Uart_SendByte(port,0+i);Delay_ARMJISHU(10000000);}
具体代码我就不作说明了

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top