打印
[AT32F413]

PB3可以设置为输入吗?需要外置上拉电阻吗?怎么试都不行,用过的大神指点下。

[复制链接]
1097|16
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
p8s|  楼主 | 2023-11-3 15:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
PB3可以设置为输入吗?需要外置上拉电阻吗?怎么试都不行,用过的大神指点下。
gpio_init_type gpio_init_struct;

  /* enable the led clock */
        crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
        crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
       
  /* configure the led gpio */
  gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
  gpio_init_struct.gpio_out_type  = GPIO_OUTPUT_PUSH_PULL;
  gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
  gpio_init_struct.gpio_pins = 0xf078;//1111000001111000;//15,14,13,12,,,,6,5,4,3
  gpio_init_struct.gpio_pull = GPIO_PULL_UP;
  gpio_init(GPIOB, &gpio_init_struct);
        gpio_pin_remap_config(SWJTAG_GMUX_010,TRUE);

使用特权

评论回复
沙发
p8s|  楼主 | 2023-11-3 15:52 | 只看该作者
原厂程序,改了测试也不行,PB4正常跳变,PB3持续低电平。
#include "at32f413_board.h"
#include "at32f413_clock.h"


/** @addtogroup AT32F413_periph_examples
  * @{
  */

/** @addtogroup 413_GPIO_swjtag_remap GPIO_swjtag_remap
  * @{
  */

void swj_dp_config(void);
void gpio_pins_toggle(gpio_type* gpio_x, uint16_t gpio_pin);

/**
  * @brief  configure the gpio of swj-dp.
  * @param  none
  * @retval none
  */
void swj_dp_config(void)
{
  gpio_init_type gpio_init_struct;

  /* configure pa13 (jtms/swdat), pa14 (jtck/swclk) and pa15 (jtdi) as output push-pull */
//  gpio_init_struct.gpio_pins = GPIO_PINS_13 | GPIO_PINS_14 | GPIO_PINS_15;
  gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
  gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
  gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
  gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
//  gpio_init(GPIOA, &gpio_init_struct);

  /* configure pb3 (jtdo) and pb4 (jtrst) as output push-pull */
  gpio_init_struct.gpio_pins = GPIO_PINS_1|GPIO_PINS_3 | GPIO_PINS_4;
  gpio_init(GPIOB, &gpio_init_struct);
}

/**
  * @brief  toggles the specified gpio pin
  * @param  gpiox: where x can be (a..g depending on device used) to select the gpio peripheral
  * @param  gpio_pin: specifies the pins to be toggled.
  * @retval none
  */
void gpio_pins_toggle(gpio_type* gpio_x, uint16_t gpio_pin)
{
  gpio_x->odt ^= gpio_pin;
}

/**
  * @brief  main function.
  * @param  none
  * @retval none
  */
int main(void)
{
  system_clock_config();

  at32_board_init();

  crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
  crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
  crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);

  swj_dp_config();
        gpio_pin_remap_config(SWJTAG_CONF_010, TRUE);
  while(1)
  {
//    if(USER_BUTTON == at32_button_press())
//    {
      /* disable the serial wire jtag debug port swj-dp */
//      gpio_pin_remap_config(SWJTAG_CONF_100, TRUE);

      /* turn on led3 */
//      at32_led_off(LED3);
//    }

//    /* toggle jtms/swdat pin */
//    gpio_pins_toggle(GPIOA, GPIO_PINS_13);
//    delay_us(200);

//    /* toggle jtck/swclk pin */
//    gpio_pins_toggle(GPIOA, GPIO_PINS_14);
//    delay_us(200);

    /* toggle jtdi pin */
    gpio_pins_toggle(GPIOB, GPIO_PINS_0);
    delay_us(200);

    /* toggle jtdo pin */
    gpio_pins_toggle(GPIOB, GPIO_PINS_3);
    delay_us(200);

    /* toggle jtrst pin */
    gpio_pins_toggle(GPIOB, GPIO_PINS_4);
    delay_us(200);
  }
}

使用特权

评论回复
板凳
回忆酱| | 2023-11-4 15:13 | 只看该作者
试试一次全部禁用jtag的 PA的也是.正常复用完就可以了

使用特权

评论回复
地板
albertaabbot| | 2023-11-6 22:11 | 只看该作者
使用的是官网的开发板吗?这个口是复用的。

使用特权

评论回复
5
mickit| | 2023-11-6 22:25 | 只看该作者
是led的口吗?
              

使用特权

评论回复
6
lzbf| | 2023-11-7 17:12 | 只看该作者
关闭jtag的功能。              

使用特权

评论回复
7
dspmana| | 2023-11-7 18:15 | 只看该作者
需要上拉电阻的。              

使用特权

评论回复
8
classroom| | 2023-12-8 11:11 | 只看该作者
可能是由于在使用SWD调试的时候要取消trace跟踪调试,Pb3端口还是没法正常读取到数据。

使用特权

评论回复
9
earlmax| | 2023-12-8 15:56 | 只看该作者
一般建议选择10kΩ至100kΩ之间的电阻值。

使用特权

评论回复
10
chenjun89| | 2023-12-8 20:01 | 只看该作者
看一下芯片数据手册这个IO是不是固定某个功能使用的

使用特权

评论回复
11
beacherblack| | 2023-12-8 21:00 | 只看该作者
在配置PB3为输入模式时,需要设置GPIO的引脚功能寄存器(如GPIOx_AFRL或GPIOx_AFRH,其中x为对应的GPIO端口,如GPIOB),将PB3引脚映射到内部上拉电阻(PUPDD=0)和浮空(PDD=0)模式。

使用特权

评论回复
12
beacherblack| | 2023-12-8 22:01 | 只看该作者
关闭PB3的输出功能,然后将其设置为输入模式。

使用特权

评论回复
13
mollylawrence| | 2023-12-9 09:57 | 只看该作者
建议检查PB3端口的连接是否正确

使用特权

评论回复
14
iyoum| | 2023-12-9 15:42 | 只看该作者
在SWD调试模式              

使用特权

评论回复
15
youtome| | 2023-12-9 21:14 | 只看该作者
是否需要外置上拉电阻,这取决于你的具体应用。

使用特权

评论回复
16
xiaoyaodz| | 2023-12-9 21:50 | 只看该作者
其他代码或硬件配置错误影响了PB3

使用特权

评论回复
17
pattywu| | 2023-12-9 22:30 | 只看该作者
我记得与I2C引脚相同的, 上拉电阻好像是没有的.

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

p8s

16

主题

58

帖子

1

粉丝