Пример #1
0
/**
  * @brief  Initializes the SD Card and put it into StandBy State (Ready for 
  *         data transfer).
  * @retval None
  */
void SD_IO_Init(void)
{
  GPIO_InitTypeDef  gpioinitstruct = {0};
  uint8_t counter = 0;

  /* SD_CS_GPIO Periph clock enable */
  SD_CS_GPIO_CLK_ENABLE();

  /* Configure SD_CS_PIN pin: SD Card CS pin */
  gpioinitstruct.Pin    = SD_CS_PIN;
  gpioinitstruct.Mode   = GPIO_MODE_OUTPUT_PP;
  gpioinitstruct.Pull   = GPIO_PULLUP;
  gpioinitstruct.Speed  = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(SD_CS_GPIO_PORT, &gpioinitstruct);

  /*------------Put SD in SPI mode--------------*/
  /* SD SPI Config */
  SPIx_Init();

  /* SD chip select high */
  SD_CS_HIGH();
  
  /* Send dummy byte 0xFF, 10 times with CS high */
  /* Rise CS and MOSI for 80 clocks cycles */
  for (counter = 0; counter <= 9; counter++)
  {
    /* Send dummy byte 0xFF */
    SD_IO_WriteByte(SD_DUMMY_BYTE);
  }
}
/**
  * @brief  Initialize the LCD
  * @retval None
  */
void LCD_IO_Init(void)
{
  GPIO_InitTypeDef  gpioinitstruct = {0};

  /* LCD_CS_GPIO and LCD_DC_GPIO Periph clock enable */
  LCD_CS_GPIO_CLK_ENABLE();
  LCD_DC_GPIO_CLK_ENABLE();
  
  /* Configure LCD_CS_PIN pin: LCD Card CS pin */
  gpioinitstruct.Pin    = LCD_CS_PIN;
  gpioinitstruct.Mode   = GPIO_MODE_OUTPUT_PP;
  gpioinitstruct.Pull   = GPIO_NOPULL;
  gpioinitstruct.Speed  = GPIO_SPEED_FREQ_VERY_HIGH;
  HAL_GPIO_Init(SD_CS_GPIO_PORT, &gpioinitstruct);
      
  /* Configure LCD_DC_PIN pin: LCD Card DC pin */
  gpioinitstruct.Pin    = LCD_DC_PIN;
  HAL_GPIO_Init(LCD_DC_GPIO_PORT, &gpioinitstruct);

  /* LCD chip select high */
  LCD_CS_HIGH();
  
  /* LCD SPI Config */
  SPIx_Init();
}
Пример #3
0
//初始化24L01的IO口
void NRF24L01_Init(void)
	{
	GPIO_InitTypeDef GPIO_InitStructure;
 
	RCC_APB2PeriphClockCmd(	RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC, ENABLE );	

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;   //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOA, &GPIO_InitStructure);

	GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;   //推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure); 
	GPIO_SetBits(GPIOC,GPIO_Pin_4);

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU  ;   //上拉输入
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	SPIx_Init();    //初始化SPI
	
	Clr_NRF24L01_CE;	 //使能24L01  NRF24L01_CE
	Set_NRF24L01_CSN;    //SPI片选取消 NRF24L01_CSN	 		  
	}
Пример #4
0
/**
  * @brief  Configures the GYRO SPI interface.
  * @param  None
  * @retval None
  */
void GYRO_IO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure the Gyroscope Control pins ------------------------------------*/
  /* Enable CS GPIO clock and  Configure GPIO PIN for Gyroscope Chip select */
  GYRO_CS_GPIO_CLK_ENABLE();
  GPIO_InitStructure.Pin = GYRO_CS_PIN;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull  = GPIO_NOPULL;
  GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
  HAL_GPIO_Init(GYRO_CS_GPIO_PORT, &GPIO_InitStructure);

  /* Deselect : Chip Select high */
  GYRO_CS_HIGH();

//  /* Enable INT1, INT2 GPIO clock and Configure GPIO PINs to detect Interrupts */
//  GYRO_INT_GPIO_CLK_ENABLE();
//  GPIO_InitStructure.Pin = GYRO_INT1_PIN | GYRO_INT2_PIN;
//  GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
//  GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
//  GPIO_InitStructure.Pull= GPIO_NOPULL;
//  HAL_GPIO_Init(GYRO_INT_GPIO_PORT, &GPIO_InitStructure);

  SPIx_Init();
}
Пример #5
0
int main(void)
{
//	uint32_t pre = 0 ;
	uint8_t* p = 0;
	timer_config();
	SPIx_Init();
	Led_Init();

	Key_Init();
	Usart2_Init(9600);
//	enc28j60_init(mac);
	install_uart_dev();
	stack_init();
//	test_hardhandler(2,(int*)1);
	my_tftp_init();
	telnet_service_init();
//	web_server_init();
//	*p = 1 ;
	#if 0
	while(1)
	{
		stack_process();
		Led_Process();
		shell();
		
	}
	#endif
	bootstart();

 return 0 ;
}
Пример #6
0
//初始化SPI FLASH的IO口
void SPI_Flash_Init(void)
{
	RCC->APB2ENR|=1<<2;       //PORTA时钟使能 
	GPIOA->CRL&=0XFFF000FF; 
	GPIOA->CRL|=0X00033300;//PA2.3.4 推挽 	    
	GPIOA->ODR|=0X7<<2;    //PA2.3.4上拉
	SPIx_Init();		   //初始化SPI
}  
Пример #7
0
/**
  * @brief  SPIx error treatment function.
  * @param  None
  * @retval None
  */
static void SPIx_Error(void)
{
  /* De-initialize the SPI comunication bus */
  HAL_SPI_DeInit(&SpiHandle);
  
  /* Re-Initiaize the SPI comunication bus */
  SPIx_Init();
}
Пример #8
0
/**
  * @brief SPI error treatment function
  * @param None
  * @retval None
  */
static void SPIx_Error (void)
{
  /* De-initialize the SPI communication BUS */
  HAL_SPI_DeInit(&heval_Spi);
  
  /* Re- Initiaize the SPI communication BUS */
  SPIx_Init();
}
Пример #9
0
int main(void)
{
	DelayInit();
	lcd16x2_init(LCD16X2_DISPLAY_ON_CURSOR_OFF_BLINK_OFF);
	
	SPIx_Init();
	
	while (1)
	{
		// Enable slave
		SPIx_EnableSlave();
		// Write command to slave to turn on LED blinking
		SPIx_Transfer((uint8_t) '1');
		DelayUs(10);
		// Write command to slave for asking LED blinking status
		SPIx_Transfer((uint8_t) '?');
		DelayUs(10);
		// Read LED blinking status (off/on) from slave by transmitting dummy byte
		receivedByte = SPIx_Transfer(0);
		// Disable slave
		SPIx_DisableSlave();
		// Display LED blinking status
		lcd16x2_clrscr();
		if (receivedByte == 0)
		{
			lcd16x2_puts("LED Blinking Off");
		}
		else if (receivedByte == 1)
		{
			lcd16x2_puts("LED Blinking On");
		}
		DelayMs(2500);
		
		// Enable slave
		SPIx_EnableSlave();
		// Write command to slave to turn off LED blinking
		SPIx_Transfer((uint8_t) '0');
		DelayUs(10);
		// Write command to slave for asking LED blinking status
		SPIx_Transfer((uint8_t) '?');
		DelayUs(10);
		// Read LED blinking status (off/on) from slave by transmitting dummy byte
		receivedByte = SPIx_Transfer(0);
		// Disable slave
		SPIx_DisableSlave();
		// Display LED blinking status
		lcd16x2_clrscr();
		if (receivedByte == 0)
		{
			lcd16x2_puts("LED Blinking Off");
		}
		else if (receivedByte == 1)
		{
			lcd16x2_puts("LED Blinking On");
		}
		DelayMs(2500);
	}
}
Пример #10
0
//初始化SPI FLASH的IO口
void SPI_Flash_Init(void)
{
 
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;  //SPI CS
 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //复用推挽输出
 	GPIO_Init(GPIOA, &GPIO_InitStructure);
 	GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4);
	SPIx_Init();		   //初始化SPI
}  
Пример #11
0
void nRF_Init() {

	nRFSPIConf.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
	nRFSPIConf.SPI_Mode = SPI_Mode_Master;
	nRFSPIConf.SPI_DataSize = SPI_DataSize_8b;
	nRFSPIConf.SPI_CPOL = SPI_CPOL_Low;
	nRFSPIConf.SPI_CPHA = SPI_CPHA_1Edge;
	nRFSPIConf.SPI_NSS = SPI_NSS_Soft;
	nRFSPIConf.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
	nRFSPIConf.SPI_FirstBit = SPI_FirstBit_MSB;
	nRFSPIConf.SPI_CRCPolynomial = 7;
	
	SPIx_Init(SPI1);

}
Пример #12
0
//初始化SPI FLASH的IO口
void SPI_Flash_Init(void)
{
	//RCC->APB2ENR|=1<<2;       //PORTA时钟使能 	    
	//这里 
	//GPIOA->CRL&=0XFFF000FF; 
	//GPIOA->CRL|=0X00033300;//PA2.3.4 推挽 	    
	//GPIOA->ODR|=0X7<<2;    //PA2.3.4上拉
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;  //SPI CS
 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;  //复用推挽输出
 	GPIO_Init(GPIOA, &GPIO_InitStructure);
 	GPIO_SetBits(GPIOA,GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4);


	SPIx_Init();		   //初始化SPI
}  
Пример #13
0
//初始化24L01的IO口
void NRF24L01_Init(void)
{
	RCC->APB2ENR|=1<<2;    //使能PORTA口时钟 
	RCC->APB2ENR|=1<<4;    //使能PORTC口时钟 
	GPIOA->CRL&=0XFFF000FF;//PA4输出
	GPIOA->CRL|=0X00033300; 
	GPIOA->ODR|=7<<2;	   //PA2.3.4 输出1		 
	GPIOC->CRL&=0XFF00FFFF;//PC4输出 PC5输出
	GPIOC->CRL|=0X00830000; 
	GPIOC->ODR|=3<<4;	   //上拉
	//这里要修改SPI初始化函数
	//设置:CPHA=0 CPOL=0 	 
	SPIx_Init();    //初始化SPI
	NRF24L01_CE=0; 	//使能24L01
	NRF24L01_CSN=1;	//SPI片选取消		  		 		  
}
/**
  * @brief  Initializes the SD Card and put it into StandBy State (Ready for 
  *         data transfer).
  * @param  None
  * @retval None
  */
void SD_IO_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct;
  uint8_t counter;

  /* SD_CS_GPIO Periph clock enable */
  SD_CS_GPIO_CLK_ENABLE();

  /* Configure SD_CS_PIN pin: SD Card CS pin */
  GPIO_InitStruct.Pin = SD_CS_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStruct);


  /*  LCD chip select line perturbs SD also when the LCD is not used */
  /*  this is a workaround to avoid sporadic failures during r/w operations */ 
  LCD_CS_GPIO_CLK_ENABLE();
  GPIO_InitStruct.Pin = LCD_CS_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(LCD_CS_GPIO_PORT, &GPIO_InitStruct);
  LCD_CS_HIGH();


  /*------------Put SD in SPI mode--------------*/
  /* SD SPI Config */
  SPIx_Init();
  
  /* SD chip select high */
  SD_CS_HIGH();
  
  /* Send dummy byte 0xFF, 10 times with CS high */
  /* Rise CS and MOSI for 80 clocks cycles */
  for (counter = 0; counter <= 9; counter++)
  {
    /* Send dummy byte 0xFF */
    SD_IO_WriteByte(SD_DUMMY_BYTE);
  }
}
Пример #15
0
/**
  * @brief  Configures the LCD_SPI interface.
  * @param  None
  * @retval None
  */
void LCD_IO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct;

  /* Configure the LCD Control pins ------------------------------------------*/
  LCD_NCS_GPIO_CLK_ENABLE();
    
  /* Configure NCS in Output Push-Pull mode */
  GPIO_InitStruct.Pin     = LCD_NCS_PIN;
  GPIO_InitStruct.Mode    = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull    = GPIO_PULLUP;
  GPIO_InitStruct.Speed   = GPIO_SPEED_FREQ_LOW     ;
  HAL_GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStruct);
    
  /* Set or Reset the control line */
  LCD_CS_LOW();
  LCD_CS_HIGH();

  SPIx_Init();
}
Пример #16
0
/**
  * @brief  Configures the Accelerometer SPI interface.
  * @param  None
  * @retval None
  */
void ACCELERO_IO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  /* Configure the Accelerometer Control pins --------------------------------*/
  /* Enable CS GPIO clock and configure GPIO pin for Accelerometer Chip select */  
  ACCELERO_CS_GPIO_CLK_ENABLE();
  
  /* Configure GPIO PIN for LIS Chip select */
  GPIO_InitStructure.Pin = ACCELERO_CS_PIN;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull  = GPIO_NOPULL;
  GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
  HAL_GPIO_Init(ACCELERO_CS_GPIO_PORT, &GPIO_InitStructure);
  
  /* Deselect: Chip Select high */
  ACCELERO_CS_HIGH();
  
  SPIx_Init();
}
Пример #17
0
/**
  * @brief  Initializes the SD Card and put it into StandBy State (Ready for 
  *         data transfer).
  * @param  None
  * @retval None
  */
void SD_IO_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructureure;
  uint8_t counter;

  /* SD_CS_GPIO and SD_DETECT_GPIO Periph clock enable */
  SD_CS_GPIO_CLK_ENABLE();
  SD_DETECT_GPIO_CLK_ENABLE();

  /* Configure SD_CS_PIN pin: SD Card CS pin */
  GPIO_InitStructureure.Pin = SD_CS_PIN;
  GPIO_InitStructureure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructureure.Pull = GPIO_PULLUP;
  GPIO_InitStructureure.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStructureure);

  /* Configure SD_DETECT_PIN pin: SD Card detect pin */
  GPIO_InitStructureure.Pin = SD_DETECT_PIN;
  GPIO_InitStructureure.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStructureure.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructureure);

  /* Enable and set SD EXTI Interrupt to the lowest priority */
  HAL_NVIC_SetPriority(SD_DETECT_EXTI_IRQn, 0x0F, 0);
  HAL_NVIC_EnableIRQ(SD_DETECT_EXTI_IRQn);

  /*------------Put SD in SPI mode--------------*/
  /* SD SPI Config */
  SPIx_Init();
  
  /* SD chip select high */
  SD_CS_HIGH();
  
  /* Send dummy byte 0xFF, 10 times with CS high */
  /* Rise CS and MOSI for 80 clocks cycles */
  for (counter = 0; counter <= 9; counter++)
  {
    /* Send dummy byte 0xFF */
    SD_IO_WriteByte(SD_DUMMY_BYTE);
  }
}
Пример #18
0
/**
  * @brief  Initializes the EEPROM SPI and put it into StandBy State (Ready for 
  *         data transfer).
  * @param  None
  * @retval None
  */
void EEPROM_SPI_IO_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  /* EEPROM_CS_GPIO Periph clock enable */
  EEPROM_CS_GPIO_CLK_ENABLE();

  /* Configure EEPROM_CS_PIN pin: EEPROM SPI CS pin */
  GPIO_InitStructure.Pin = EEPROM_CS_PIN;
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Pull = GPIO_PULLUP;
  GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(EEPROM_CS_GPIO_PORT, &GPIO_InitStructure);

  /*------------Put EEPROM in SPI mode--------------*/
  /* EEPROM SPI Config */
  SPIx_Init();
  
  /* EEPROM chip select high */
  EEPROM_CS_HIGH();
}
/**
  * @brief  Configures the LCD_SPI interface.
  */
void LCD_IO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  
  if(Is_LCD_IO_Initialized == 0)
  {
    Is_LCD_IO_Initialized = 1; 
    
    /* Configure NCS in Output Push-Pull mode */
    LCD_WRX_GPIO_CLK_ENABLE();
    GPIO_InitStructure.Pin     = LCD_WRX_PIN;
    GPIO_InitStructure.Mode    = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.Pull    = GPIO_NOPULL;
    GPIO_InitStructure.Speed   = GPIO_SPEED_FAST;
    HAL_GPIO_Init(LCD_WRX_GPIO_PORT, &GPIO_InitStructure);
    
    LCD_RDX_GPIO_CLK_ENABLE();
    GPIO_InitStructure.Pin     = LCD_RDX_PIN;
    GPIO_InitStructure.Mode    = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.Pull    = GPIO_NOPULL;
    GPIO_InitStructure.Speed   = GPIO_SPEED_FAST;
    HAL_GPIO_Init(LCD_RDX_GPIO_PORT, &GPIO_InitStructure);
    
    /* Configure the LCD Control pins ----------------------------------------*/
    LCD_NCS_GPIO_CLK_ENABLE();
    
    /* Configure NCS in Output Push-Pull mode */
    GPIO_InitStructure.Pin     = LCD_NCS_PIN;
    GPIO_InitStructure.Mode    = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.Pull    = GPIO_NOPULL;
    GPIO_InitStructure.Speed   = GPIO_SPEED_FAST;
    HAL_GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
    
    /* Set or Reset the control line */
    LCD_CS_LOW();
    LCD_CS_HIGH();
    
    SPIx_Init();
  }
}
Пример #20
0
void NRF_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	SPIx_Init(SPI3);

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOG,ENABLE);	
	
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;	//打开引进脚为:B0->IRQ
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;	//上拉输入
	GPIO_Init(GPIOB,&GPIO_InitStructure);

		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;	//打开引进脚为:A15->CSN
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;	//推挽输出
		GPIO_Init(GPIOA,&GPIO_InitStructure);
		
		GPIO_InitStructure.GPIO_Pin = 0x0001;	//打开引进脚为:G0->CE
		GPIO_Init(GPIOG,&GPIO_InitStructure);

		NRF_CE = 0;
		NRF_CSN = 1;
}
Пример #21
0
/**
  * @brief  Initializes the SD Card and put it into StandBy State (Ready for 
  *         data transfer).
  * @param  None
  * @retval None
  */
void SD_IO_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct;
  uint8_t counter;

  /* SD_CS_GPIO and SD_DETECT_GPIO Periph clock enable */
  SD_CS_GPIO_CLK_ENABLE();
 
  /* Configure SD_CS_PIN pin: SD Card CS pin */
  GPIO_InitStruct.Pin = SD_CS_PIN;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM     ;
  HAL_GPIO_Init(SD_CS_GPIO_PORT, &GPIO_InitStruct);

  /* Configure SD_DETECT_PIN pin: SD Card detect pin (Via MFX) */
  if (BSP_IO_Init() == IO_OK)
  {
    BSP_IO_ConfigPin(SD_DETECT_PIN, IO_MODE_INPUT_PU);
  }

  /*------------Put SD in SPI mode--------------*/
  /* SD SPI Config */
  SPIx_Init();

  /* SD chip select high */
  SD_CS_HIGH();
  
  /* Send dummy byte 0xFF, 10 times with CS high */
  /* Rise CS and MOSI for 80 clocks cycles */
  for (counter = 0; counter <= 9; counter++)
  {
    /* Send dummy byte 0xFF */
    SD_IO_WriteByte(SD_DUMMY_BYTE);
  }
}
Пример #22
0
/*******************************************************************************
* Function Name  : MSD_Init
* Description    : Initializes the MSD/SD communication.
* Input          : None
* Output         : None
* Return         : The MSD Response: - MSD_RESPONSE_FAILURE: Sequence failed
*                                    - MSD_RESPONSE_NO_ERROR: Sequence succeed
*******************************************************************************/
u8 MSD_Init(void)
{
  u32 i = 0;

	RCC->APB2ENR|=1<<2;       //PORTA时钟使能 
	GPIOA->CRL&=0XFFF000FF; 
	GPIOA->CRL|=0X00033300;//PA2.3.4 推挽 	    
	GPIOA->ODR|=0X7<<2;    //PA2.3.4上拉 
	SPIx_Init();
 	SPIx_SetSpeed(SPI_SPEED_256);//设置到低速模式

  /* MSD chip select high */
  Set_SD_CS;
  /* Send dummy byte 0xFF, 10 times with CS high*/
  /* rise CS and MOSI for 80 clocks cycles */
  for (i = 0; i <= 9; i++)
  {
    /* Send dummy byte 0xFF */
    MSD_WriteByte(DUMMY);
  }
  /*------------Put MSD in SPI mode--------------*/
  /* MSD initialized and set to SPI mode properly */
  return (MSD_GoIdleState());
}
Пример #23
0
//初始化SD卡
//如果成功返回,则会自动设置SPI速度为18Mhz
//返回值:0:NO_ERR
//       1:TIME_OUT
//      99:NO_CARD
u8 SD_Init(void)
{
    u8 r1;      // 存放SD卡的返回值
    u16 retry;  // 用来进行超时计数
    u8 buff[6];
    //设置硬件上与SD卡相关联的控制引脚输出
    //避免NRF24L01/W25X16等的影响
    RCC->APB2ENR|=1<<2;       //PORTA时钟使能
    GPIOA->CRL&=0XFFF000FF;
    GPIOA->CRL|=0X00033300;//PA2.3.4 推挽
    GPIOA->ODR|=0X7<<2;    //PA2.3.4上拉
    SPIx_Init();
    SPIx_SetSpeed(SPI_SPEED_256);//设置到低速模式
    SD_CS=1;
    if(SD_Idle_Sta()) return 1;//超时返回1 设置到idle 模式失败
    //-----------------SD卡复位到idle结束-----------------
    //获取卡片的SD版本信息
    SD_CS=0;
    r1 = SD_SendCommand_NoDeassert(8, 0x1aa,0x87);
    //如果卡片版本信息是v1.0版本的,即r1=0x05,则进行以下初始化
    if(r1 == 0x05)
    {
        //设置卡类型为SDV1.0,如果后面检测到为MMC卡,再修改为MMC
        SD_Type = SD_TYPE_V1;
        //如果是V1.0卡,CMD8指令后没有后续数据
        //片选置高,结束本次命令
        SD_CS=1;
        //多发8个CLK,让SD结束后续操作
        SPIx_ReadWriteByte(0xFF);
        //-----------------SD卡、MMC卡初始化开始-----------------
        //发卡初始化指令CMD55+ACMD41
        // 如果有应答,说明是SD卡,且初始化完成
        // 没有回应,说明是MMC卡,额外进行相应初始化
        retry = 0;
        do
        {
            //先发CMD55,应返回0x01;否则出错
            r1 = SD_SendCommand(CMD55, 0, 0);
            if(r1 == 0XFF)return r1;//只要不是0xff,就接着发送
            //得到正确响应后,发ACMD41,应得到返回值0x00,否则重试200次
            r1 = SD_SendCommand(ACMD41, 0, 0);
            retry++;
        } while((r1!=0x00) && (retry<400));
        // 判断是超时还是得到正确回应
        // 若有回应:是SD卡;没有回应:是MMC卡
        //----------MMC卡额外初始化操作开始------------
        if(retry==400)
        {
            retry = 0;
            //发送MMC卡初始化命令(没有测试)
            do
            {
                r1 = SD_SendCommand(1,0,0);
                retry++;
            } while((r1!=0x00)&& (retry<400));
            if(retry==400)return 1;   //MMC卡初始化超时
            //写入卡类型
            SD_Type = SD_TYPE_MMC;
        }
        //----------MMC卡额外初始化操作结束------------
        //设置SPI为高速模式
        SPIx_SetSpeed(SPI_SPEED_4);
        SPIx_ReadWriteByte(0xFF);
        //禁止CRC校验
        r1 = SD_SendCommand(CMD59, 0, 0x95);
        if(r1 != 0x00)return r1;  //命令错误,返回r1
        //设置Sector Size
        r1 = SD_SendCommand(CMD16, 512, 0x95);
        if(r1 != 0x00)return r1;//命令错误,返回r1
        //-----------------SD卡、MMC卡初始化结束-----------------

    }//SD卡为V1.0版本的初始化结束
    //下面是V2.0卡的初始化
    //其中需要读取OCR数据,判断是SD2.0还是SD2.0HC卡
    else if(r1 == 0x01)
    {
        //V2.0的卡,CMD8命令后会传回4字节的数据,要跳过再结束本命令
        buff[0] = SPIx_ReadWriteByte(0xFF);  //should be 0x00
        buff[1] = SPIx_ReadWriteByte(0xFF);  //should be 0x00
        buff[2] = SPIx_ReadWriteByte(0xFF);  //should be 0x01
        buff[3] = SPIx_ReadWriteByte(0xFF);  //should be 0xAA
        SD_CS=1;
        SPIx_ReadWriteByte(0xFF);//the next 8 clocks
        //判断该卡是否支持2.7V-3.6V的电压范围
        //if(buff[2]==0x01 && buff[3]==0xAA) //不判断,让其支持的卡更多
        {
            retry = 0;
            //发卡初始化指令CMD55+ACMD41
            do
            {
                r1 = SD_SendCommand(CMD55, 0, 0);
                if(r1!=0x01)return r1;
                r1 = SD_SendCommand(ACMD41, 0x40000000, 0);
                if(retry>200)return r1;  //超时则返回r1状态
            } while(r1!=0);
            //初始化指令发送完成,接下来获取OCR信息
            //-----------鉴别SD2.0卡版本开始-----------
            r1 = SD_SendCommand_NoDeassert(CMD58, 0, 0);
            if(r1!=0x00)
            {
                SD_CS=1;//释放SD片选信号
                return r1;  //如果命令没有返回正确应答,直接退出,返回应答
            }//读OCR指令发出后,紧接着是4字节的OCR信息
            buff[0] = SPIx_ReadWriteByte(0xFF);
            buff[1] = SPIx_ReadWriteByte(0xFF);
            buff[2] = SPIx_ReadWriteByte(0xFF);
            buff[3] = SPIx_ReadWriteByte(0xFF);
            //OCR接收完成,片选置高
            SD_CS=1;
            SPIx_ReadWriteByte(0xFF);
            //检查接收到的OCR中的bit30位(CCS),确定其为SD2.0还是SDHC
            //如果CCS=1:SDHC   CCS=0:SD2.0
            if(buff[0]&0x40)SD_Type = SD_TYPE_V2HC;    //检查CCS
            else SD_Type = SD_TYPE_V2;
            //-----------鉴别SD2.0卡版本结束-----------
            //设置SPI为高速模式
            SPIx_SetSpeed(SPI_SPEED_4);
        }
    }
    return r1;
}
Пример #24
0
//触摸画板功能演示函数   
void Wireless_Play(void)
{				  	
	u8 err=0,i;		 
	u8 key;	 
	u8 mode;//24L01的模式设置
	u8 tmp_buf[5];//低4个字节,传递坐标值,最高一个字节:0,正常画图,1清除;2,退出;  
	  
	mode=Wireless_Mode_Set();
	if(mode==0)
	{
		SPIx_Init();//设置回原来的				 
		SPIx_SetSpeed(SPI_SPEED_4);//18Mhz 
		return;//24L01检测失败,直接退出
	}	 			
	if(mode==2)
	{			    
		Load_Gui_Show("清除","发送","返回");//加载界面 
		TX_Mode();//发送模式
	}else
	{
		Load_Gui_Show("清除","接收","返回");//加载界面 
		RX_Mode();//接收模式
	}
	LCD_Fill(0,0,240,296,LGRAY);//填充灰色 
	POINT_COLOR=BLUE;//设置字体为蓝色  	 
	while(1)
	{	  		   				 
		key=AI_Read_TP(20);//得到触点的状态
		if(mode==1)//接收模式
		{
			if(NRF24L01_RxPacket(tmp_buf)==0)//一旦接收到信息,则显示出来.
			{
				Pen_Point.X=tmp_buf[0];
				Pen_Point.X=(Pen_Point.X<<8)+tmp_buf[1];
 				Pen_Point.Y=tmp_buf[2];
				Pen_Point.Y=(Pen_Point.Y<<8)+tmp_buf[3];
				switch(tmp_buf[4])
				{
					case 0://正常画点
						Draw_Big_Point(Pen_Point.X,Pen_Point.Y);//画点
						break;
					case 1://清除
						LCD_Fill(0,0,240,296,LGRAY);//填充灰色
						break;
					case 2://退出
						Pen_Point.Key_Reg=0;//清除笔状态
						SPIx_Init();//设置回原来的				 
						SPIx_SetSpeed(SPI_SPEED_4);//18Mhz 
						return; 
				}	  
			}
		}
		if(key)//触摸屏被按下						  
		{	
			Pen_Point.Key_Reg|=0x80;//标记按下了按键    
			if(Pen_Point.Y<296&&mode==2)//在画图区域内,且为发送模式
			{
				tmp_buf[0]=Pen_Point.X>>8;
				tmp_buf[1]=Pen_Point.X&0xFF;
				tmp_buf[2]=Pen_Point.Y>>8;	 
				tmp_buf[3]=Pen_Point.Y&0xFF; 
				tmp_buf[4]=0;//功能为0,正常画图  
				Draw_Big_Point(Pen_Point.X,Pen_Point.Y);//画点
				err=0;	      
				while(NRF24L01_TxPacket(tmp_buf)!=TX_OK)//等待发送完成
				{
					err++;
					if(err>10)return;//连续超过10次错误,则返回
				}
			}      
		}else if(Pen_Point.Key_Reg&0X80)//按键松开了 
Пример #25
0
//初始化SPI FLASH的IO口
void SPI_Flash_Init(void)
{
	SPIx_Init();		   //初始化SPI
}  
Пример #26
0
//////////////////////////////////////////////////////////////////////////
//init
void MPU9250_Init(void)
{
	SPIx_Init(pMPU9250);
}
Пример #27
0
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
        system_stm32f2xx.c file
     */
	
	u8 ID[4];
	volatile u8 tmp,k;

	


    //SystemInit();
  	//SystemCoreClockUpdate();

	Open207_LEDInit();	
	USART_Configuration();
	USART_NVIC_Config();
	printf("\r\n SPI Rom Copy SPI1 to SPI2\r\n");

	SPIx_Init(1);
	SPIx_Init(2);
	Read_Status_Register(1);
	Read_Status_Register(2);

	


	SPIx_Read_ID(1,ID);
	printf("SPI1 Flash Rom ID is");
	printf(" 0x%x  0x%x \r\n",ID[0],ID[1]);

	SPIx_Read_ID(2,ID);
	printf("SPI2 Flash Rom ID is");
	printf(" 0x%x  0x%x \r\n",ID[0],ID[1]);




/*
	for (i=0 ; i<255; i++)
	{
		 tmp = read_buffer(2,i);
		 printf("intel[%3d] ::",tmp);
		 write_buffer(1,i,tmp);
		 tmp = read_buffer(1,i);
		 printf("[%3d] copy\r\n",tmp);


	}
*/


printf("========Flash Rom Copy========\r\n");
printf("[C]SPI CH Select (Default : 2)\r\n");
printf("[S]Read Status Register\r\n");
printf("[W]Write Protect Disable\r\n");
printf("[R]Read ID\r\n");
printf("[E]Eraser Flash Memory\r\n");
printf("[L]Read Address 0 to 99\r\n");
printf("[-]Copy Start SPI1 to SPI2 \r\n");
printf("[M]Compare Match SPI1 Vs SPI2\r\n");
printf("========Press Key========\r\n");




















	
	while (1)
	{

		GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2);
		GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3);
		GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4);
		Delay(0x5fffff);

		GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2);
		GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3);
		GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4);
		Delay(0x5fffff);

		if (UART_DATA == COPY_START)
		{
			UART_DATA = 0;
			MemCopy();
		}

		else if (UART_DATA == DATA_All_VERIFY)
		{
			UART_DATA = 0;
			Compair_Match(START_ADDRESS,END_ADDRESS);
		}
	
	}

	
}