嵌入式实操----基于RT1170 首板硬件之GPIO INPUT调试(十四)

本文主要是通过迁移的思维,记录本人初次使用NXP MCUXpresso SDK API进行BSP开发

前面调通了SDRAM Flash之后,接下来调试GPIO 输入功能,硬件设计如下所示

1. 首先阅读原理图

嵌入式实操----基于RT1170 首板硬件之GPIO INPUT调试(十四)_第1张图片

2. 调试过程

2. 1 引脚初始化

/**
 * @brief GPIO Input pin init
 *
 * @param [in] void  
 * @param [out] None
 * 
 * @return 
 * 
 * @history
 * 1.Date         : 2021-5-27 14:25:57
 *   Author       : panzidong
 *   Modification : Created function
 */
void bsp_input_init_config(void) {
  CLOCK_EnableClock(kCLOCK_Iomuxc);           /* LPCG on: LPCG is ON. */
  CLOCK_EnableClock(kCLOCK_Iomuxc_Lpsr);      /* LPCG on: LPCG is ON. */

  /* GPIO configuration of oIGN on GPIO_AD_03 (pin P15) */
  gpio_pin_config_t oIGN_config = {
      .direction = kGPIO_DigitalInput,
      .outputLogic = 0U,
      .interruptMode = kGPIO_NoIntmode
  };
  /* Initialize GPIO functionality on GPIO_AD_03 (pin P15) */
  GPIO_PinInit(GPIO9, 2U, &oIGN_config);

  /* GPIO configuration of BRAKE_DET_AD on GPIO_AD_15 (pin M14) */
  gpio_pin_config_t BRAKE_DET_AD_config = {
      .direction = kGPIO_DigitalInput,
      .outputLogic = 0U,
      .interruptMode = kGPIO_NoIntmode
  };
  /* Initialize GPIO functionality on GPIO_AD_15 (pin M14) */
  GPIO_PinInit(GPIO9, 14U, &BRAKE_DET_AD_config);

  /* GPIO configuration of CAN_ERR on IOMUXC_LPSR_SW_MUX_CTL_PAD_GPIO_LPSR_11 (pin T5) */
  gpio_pin_config_t CAN_ERR_config = {
      .direction = kGPIO_DigitalInput,
      .outputLogic = 0U,
      .interruptMode = kGPIO_NoIntmode
  };
  /* Initialize GPIO functionality on IOMUXC_LPSR_SW_MUX_CTL_PAD_GPIO_LPSR_11 (pin T5) */
  GPIO_PinInit(GPIO12, 11U, &CAN_ERR_config);

  IOMUXC_SetPinMux(
      IOMUXC_GPIO_AD_03_GPIO9_IO02,           /* GPIO_AD_03 is configured as GPIO9_IO02 */
      0U);                                    /* Software Input On Field: Input Path is determined by functionality */
  IOMUXC_SetPinMux(
      IOMUXC_GPIO_AD_15_GPIO9_IO14,           /* GPIO_AD_15 is configured as GPIO9_IO14 */
      0U);                                    /* Software Input On Field: Input Path is determined by functionality */
  IOMUXC_SetPinMux(
      IOMUXC_GPIO_LPSR_11_GPIO12_IO11,        /* GPIO_LPSR_11 is configured as GPIO12_IO11 */
      0U);                                    /* Software Input On Field: Input Path is determined by functionality */  	
	
	
	IOMUXC_SetPinConfig(
      IOMUXC_GPIO_AD_03_GPIO9_IO02,           
      IOMUXC_SW_PAD_CTL_PAD_PUE(0x0));          /*Forbidden Pull Down Pull Up*/
	
  IOMUXC_SetPinConfig(
      IOMUXC_GPIO_AD_15_GPIO9_IO14,           
      IOMUXC_SW_PAD_CTL_PAD_PUE(0x0));          /*Forbidden Pull Down Pull Up*/
			
  IOMUXC_SetPinConfig(
      IOMUXC_GPIO_LPSR_11_GPIO12_IO11,        
      IOMUXC_SW_PAD_CTL_PAD_PUE(0x0));          /*Forbidden Pull Down Pull Up*/
}

2. 2 获取电平

/**
 * @brief get oIGN input level
 *
 * @param [in] None
 * @param [out] None
 * 
 * @return 
 * 
 * @history
 * 1.Date         : 2021-5-27 9:48:47
 *   Author       : panzidong
 *   Modification : Created function
 */
int bsp_input_oIGN_level(){
     return GPIO_PinRead(INPUT_oIGN_GPIO, INPUT_oIGN_GPIO_PIN);
}

/**
 * @brief get BRAKE_DET_AD input  level
 *
 * @param [in] None
 * @param [out] None
 * 
 * @return 
 * 
 * @history
 * 1.Date         : 2021-5-27 9:49:21
 *   Author       : panzidong
 *   Modification : Created function
 */
int bsp_input_BRAKE_DET_AD_level(){
     return GPIO_PinRead(INPUT_BRAKE_DET_AD_GPIO, INPUT_BRAKE_DET_AD_GPIO_PIN);
}

/**
 * @brief get CAN_ERR input level
 *
 * @param [in] None
 * @param [out] None
 * 
 * @return 
 * 
 * @history
 * 1.Date         : 2021-5-27 9:50:21
 *   Author       : panzidong
 *   Modification : Created function
 */
int bsp_input_CAN_ERR_level(){
     return GPIO_PinRead(INPUT_CAN_ERR_GPIO, INPUT_CAN_ERR_GPIO_PIN);
}

3. 总结

在调试GPIO时,虽然可以正常获取到GPIO的高低电平,但是输入电平为高时,测量引脚电平只有1.7V。最后通过断开引脚的禁用引脚的上下拉解决。

	IOMUXC_SetPinConfig(
      IOMUXC_GPIO_AD_03_GPIO9_IO02,           
      IOMUXC_SW_PAD_CTL_PAD_PUE(0x0));          /*Forbidden Pull Down Pull Up*/
	
  IOMUXC_SetPinConfig(
      IOMUXC_GPIO_AD_15_GPIO9_IO14,           
      IOMUXC_SW_PAD_CTL_PAD_PUE(0x0));          /*Forbidden Pull Down Pull Up*/
			
  IOMUXC_SetPinConfig(
      IOMUXC_GPIO_LPSR_11_GPIO12_IO11,        
      IOMUXC_SW_PAD_CTL_PAD_PUE(0x0));          /*Forbidden Pull Down Pull Up*/

你可能感兴趣的:(05-RT1170,开发)