Beispiel #1
0
/**
  * @brief  Initializes the SD_SPI and CS pins.
  * @param  None
  * @retval None
  */
void SD_LowLevel_Init(void)
{
  /* Enable SPI clock */
  CLK_PeripheralClockConfig(SD_SPI_CLK, ENABLE);

  /* Set the MOSI,MISO and SCK at high level */
  GPIO_ExternalPullUpConfig(SD_SPI_SCK_GPIO_PORT, SD_SPI_MISO_PIN | SD_SPI_MOSI_PIN | \
                            SD_SPI_SCK_PIN, ENABLE);

  /* SPI2 pin remap on Port I*/
  SYSCFG_REMAPPinConfig(REMAP_Pin_SPI2Full, ENABLE);

  /* SD_SPI Config */
  SPI_Init(SD_SPI, SPI_FirstBit_MSB, SPI_BaudRatePrescaler_4, SPI_Mode_Master,
           SPI_CPOL_High, SPI_CPHA_2Edge, SPI_Direction_2Lines_FullDuplex,
           SPI_NSS_Soft, 0x07);


  /* SD_SPI enable */
  SPI_Cmd(SD_SPI, ENABLE);

  /* Configure the SD_Detect pin */
  GPIO_Init(SD_DETECT_GPIO_PORT, SD_DETECT_PIN, GPIO_Mode_In_PU_No_IT);

  /* Set MSD ChipSelect pin in Output push-pull high level */
  GPIO_Init(SD_CS_GPIO_PORT, SD_CS_PIN, GPIO_Mode_Out_PP_High_Slow);
}
void _Device_Uart_Enable(void){

    GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_In_FL_No_IT);  // Input floating, no external interrupt

    USART_DeInit(USART1);
    USART_ClearITPendingBit(USART1, USART_IT_TC);
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);

#if defined(_USE_UART_PORT_MAPPING_)
    SYSCFG_REMAPPinConfig((REMAP_Pin_TypeDef)REMAP_Pin_USART1TxRxPortA, ENABLE);  /*!< USART1 Tx- Rx (PC3- PC2) remapping to PA2- PA3 */
#elif defined(_USE_UART_PORT_WITHOUT_MAPPING_)
#else
    #error "Please select Use Usart_Port_Mapping 0(disable)/1(enable)"
#endif

    GPIO_Init(USART_TX_PORT, USART_TX_PIN, GPIO_Mode_Out_PP_High_Fast); // USART1 TX
    GPIO_ExternalPullUpConfig(USART_TX_PORT, USART_TX_PIN, ENABLE);

    GPIO_Init(USART_RX_PORT, USART_RX_PIN, GPIO_Mode_In_PU_No_IT);  // USART1 RX
    GPIO_ExternalPullUpConfig(USART_RX_PORT, USART_RX_PIN, ENABLE);

    /* Enable USART1 clock */
    CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);

    /* USART configured as follow:
        - BaudRate = 115200 baud
        - Word Length = 8 Bits
        - One Stop Bit
        - Odd parity
        - Receive and transmit enabled
        - USART Clock disabled
    */
    USART_Init(USART1, UratBaudRates, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));
    //USART_Init(USART1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)USART_Mode_Tx );
    USART_ClearITPendingBit(USART1, USART_IT_TC);
    USART_ClearITPendingBit(USART1, USART_IT_RXNE);

    /* Enable the USART Receive interrupt: this interrupt is generated when the USART
    receive data register is not empty */
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    /* Enable the USART Transmit complete interrupt: this interrupt is generated when the USART
    transmit Shift Register is empty */
    //USART_ITConfig(USART1, USART_IT_TC, ENABLE);


    SendingWhileTimeOutCount = 0;
    Interrupt_USART1_ReceiveData_ptr_fuc = Empty_USART1_fun;
    Usart_Peripheral_Flag = 0;
    Usart_Peripheral_Flag |= fUart_Enable;

    /* Enable USART */
    USART_Cmd(USART1, ENABLE);
}
Beispiel #3
0
/**
  * @brief  Initializes the peripherals used by the SPI FLASH driver.
  * @param  None
  * @retval None
  */
void sFLASH_LowLevel_Init(void)
{

  /* sFLASH_SPI Periph clock enable */
  CLK_PeripheralClockConfig(sFLASH_SPI_CLK, ENABLE);

  /* Set the MOSI,MISO and SCK at high level */
  GPIO_ExternalPullUpConfig(sFLASH_SPI_SCK_GPIO_PORT, sFLASH_SPI_SCK_PIN | \
                            sFLASH_SPI_MISO_PIN | sFLASH_SPI_MOSI_PIN, ENABLE);

  /* SPI2 pin remap on Port I*/
  SYSCFG_REMAPPinConfig(REMAP_Pin_SPI2Full, ENABLE);

  /* Configure FLASH_CS as Output push-pull, used as Flash Chip select */
  GPIO_Init(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN, GPIO_Mode_Out_PP_High_Slow);
}
Beispiel #4
0
/**
  * @brief  Initialize the LCD
  * @param  None
  * @retval None
  */
void STM8_EVAL_LCD_Init(void)
{
  /* Enable SPI clock */
  CLK_PeripheralClockConfig(LCD_SPI_CLK, ENABLE);

  /* Configure SPI pins: SCK and MOSI */
  GPIO_Init(LCD_SPI_GPIO_PORT, LCD_SPI_SCK_PIN | LCD_SPI_MOSI_PIN, GPIO_Mode_Out_PP_Low_Fast);

#ifdef USE_STM8L1528_EVAL
  /* SPI2 pin remap on Port I*/
  SYSCFG_REMAPPinConfig(REMAP_Pin_SPI2Full, ENABLE);
#endif /* USE_STM8L1528_EVAL */

  /* Initialize SPI */
  SPI_Init(LCD_SPI, SPI_FirstBit_MSB, SPI_BaudRatePrescaler_64, SPI_Mode_Master,
           SPI_CPOL_High, SPI_CPHA_2Edge,  SPI_Direction_1Line_Tx, SPI_NSS_Soft, 0x07);
  SPI_Cmd(LCD_SPI, ENABLE);

  /* Required to ensure proper LCD display when the board is powered-on ... */
  _delay_(0x4000); /* 1ms _delay_ using Fcpu = 16Mhz*/

  /* Configure LCD ChipSelect pin (NCS) in Output push-pull mode */
  GPIO_Init(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, GPIO_Mode_Out_PP_Low_Fast);


  /* Set the LCD in TEXT mode */
  LCD_SendByte(COMMAND_TYPE, SET_TEXT_MODE);

  /* Enable the display */
  LCD_SendByte(COMMAND_TYPE, DISPLAY_ON);

  /* Clear the LCD */
  LCD_SendByte(COMMAND_TYPE, DISPLAY_CLR);

  /* Delay required to complete LCD clear command */
  _delay_(0x4000); /* 1ms _delay_ using Fcpu = 16Mhz*/

  /* Select the entry mode type */
  LCD_SendByte(COMMAND_TYPE, ENTRY_MODE_SET_INC);
}
Beispiel #5
0
PROCESS_THREAD(zigbee_comunication, ev, data)
{
  static struct etimer et;
  unsigned char sum = 0;
  struct st_UartRcv *pdata = NULL;
  int i = 0;
  PROCESS_BEGIN();
  
  GPIO_DeInit(GPIOB);
  GPIO_Init(GPIOC, GPIO_Pin_5, GPIO_Mode_Out_PP_High_Fast);  //TXD
  GPIO_Init(GPIOC, GPIO_Pin_6, GPIO_Mode_In_PU_No_IT);      //RXD
  //GPIO_Init(GPIOB,GPIO_Pin_6,GPIO_Mode_In_FL_IT);       // ACK
  GPIO_Init(GPIOB,GPIO_Pin_5,GPIO_Mode_Out_PP_High_Fast);       // RESET
  //GPIO_Init(GPIOB,GPIO_Pin_4,GPIO_Mode_In_FL_IT);       // STATE
  GPIO_Init(GPIOB,GPIO_Pin_3,GPIO_Mode_Out_PP_High_Fast);       // WAKEUP
  GPIO_Init(GPIOB,GPIO_Pin_2,GPIO_Mode_Out_PP_High_Fast);       // SLEEP
  GPIO_Init(GPIOB,GPIO_Pin_1,GPIO_Mode_Out_PP_High_Fast);       // DEF
  GPIO_Init(GPIOD,GPIO_Pin_0,GPIO_Mode_Out_PP_Low_Fast);       // DIR
#if 0 
  GPIO_WriteBit(GPIOB, GPIO_Pin_1, RESET);
  GPIO_WriteBit(GPIOB, GPIO_Pin_5, RESET);
  
  etimer_set(&et, CLOCK_SECOND / 10);
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  
  GPIO_WriteBit(GPIOB, GPIO_Pin_5, SET);
  
  etimer_set(&et, CLOCK_SECOND / 10);
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  
  GPIO_WriteBit(GPIOB, GPIO_Pin_1, SET);
#endif
  SYSCFG_REMAPPinConfig(REMAP_Pin_USART1TxRxPortC,ENABLE);
  CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
  /* USART configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - Odd parity
        - Receive and transmit enabled
        - USART Clock disabled
  */
  USART_Init(USART1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1,
                   USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));

  /* Enable the USART Receive interrupt: this interrupt is generated when the USART
    receive data register is not empty */
  //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  /* Enable the USART Transmit complete interrupt: this interrupt is generated when the USART
    transmit Shift Register is empty */
  //USART_ITConfig(USART1, USART_IT_TC, ENABLE);
  
  /* Enable USART */
  //USART_Cmd(USART1, ENABLE);
    
  USART_Cmd(USART1, ENABLE);
  //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
#if 0 
  PUTSTRING("Now config ZM516X\r\n");

readLocalInfo:
  memcpy(usart_buf,read_local_cfg,sizeof(read_local_cfg));
  usart_buf[4] = usart_buf[0] + usart_buf[1] + usart_buf[2] + usart_buf[3];

  uart_send_byte(5,usart_buf);
   
  PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_MSG);
  pdata = (struct st_UartRcv *)data;
 
  if((pdata->buf[0] == 0xAB) && (pdata->buf[1] == 0xBC) && (pdata->buf[2] == 0xCD) && (pdata->buf[3] == 0xD1))
  {
  }
  else
  {
    goto readLocalInfo;
  }
  memcpy(&stDevInfo,&pdata->buf[4],65);

  usart_buf[0] = 0xab;
  usart_buf[1] = 0xbc;
  usart_buf[2] = 0xcd;
  usart_buf[3] = enModifyCfg;
  usart_buf[4] = stDevInfo.devLoacalNetAddr[0];
  usart_buf[5] = stDevInfo.devLoacalNetAddr[1];
  stDevInfo.devLoacalNetAddr[0] = 0x00;
  stDevInfo.devLoacalNetAddr[1] = 0x03;
  //memset(stDevInfo.devLoacalNetAddr,0,2);
  stDevInfo.devDestNetAddr[0] = 0x00;
  stDevInfo.devDestNetAddr[1] = 0x00;
  stDevInfo.devChannel = 0x19;
  stDevInfo.devPanid[0] = 0x10;
  stDevInfo.devPanid[1] = 0x01;
  memcpy(&usart_buf[6],&stDevInfo,65);

  for(i = 0;i < (6 + 65);i++)
  {
      sum += usart_buf[i];
  }
  usart_buf[6 + 65] = sum;
  
  uart_send_byte(6 + 65 + 1,usart_buf);
  
  etimer_set(&et, CLOCK_SECOND);
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  GPIO_WriteBit(GPIOB,GPIO_Pin_5,RESET);
  etimer_set(&et, CLOCK_SECOND / CLOCK_SECOND);
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
  GPIO_WriteBit(GPIOB,GPIO_Pin_5,SET);
#endif
  //uart_send_byte(5,"hello");
  process_start(&hmc5983_work, NULL);
  while(1)
  {
    //etimer_set(&et, CLOCK_SECOND);
    //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_MSG);
    //pdata = (struct st_UartRcv *)data;
    //if(memcmp(pdata->buf,"get",3) == 0)
    if(flg)
    {
      usart_buf[0] = 0xAA;
      usart_buf[1] = 0xBB;
      usart_buf[2] = 0xCC;
      *(int*)&usart_buf[3] = x;
      *(int*)&usart_buf[5] = y;
      *(int*)&usart_buf[7] = z;
      usart_buf[9] = 0;
      for(i = 0;i < 9;i ++)
      {
        usart_buf[9] += usart_buf[i];
      }
      
      usart_buf[9] = 0xff - usart_buf[9];
      GPIO_WriteBit(GPIOD, GPIO_Pin_0, SET);
      etimer_set(&et, CLOCK_SECOND / 20);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
      uart_send_byte(10,usart_buf);
      etimer_set(&et, CLOCK_SECOND / 20);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
      GPIO_WriteBit(GPIOD, GPIO_Pin_0, RESET);
    }
    //etimer_set(&et, CLOCK_SECOND / 10);
    //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    //memcpy(usart_buf,"hello!\r\n",8);
    
    //uart_send_byte(8,usart_buf);
  }
  PROCESS_EXIT();
  PROCESS_END();
}