p8s 发表于 2023-11-3 15:48

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

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);

/**
* @briefconfigure the gpio of swj-dp.
* @paramnone
* @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);
}

/**
* @brieftoggles the specified gpio pin
* @paramgpiox: where x can be (a..g depending on device used) to select the gpio peripheral
* @paramgpio_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;
}

/**
* @briefmain function.
* @paramnone
* @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

使用的是官网的开发板吗?这个口是复用的。

mickit 发表于 2023-11-6 22:25

是led的口吗?
            

lzbf 发表于 2023-11-7 17:12

关闭jtag的功能。            

dspmana 发表于 2023-11-7 18:15

需要上拉电阻的。            

classroom 发表于 2023-12-8 11:11

可能是由于在使用SWD调试的时候要取消trace跟踪调试,Pb3端口还是没法正常读取到数据。

earlmax 发表于 2023-12-8 15:56

一般建议选择10kΩ至100kΩ之间的电阻值。

chenjun89 发表于 2023-12-8 20:01

看一下芯片数据手册这个IO是不是固定某个功能使用的

beacherblack 发表于 2023-12-8 21:00

在配置PB3为输入模式时,需要设置GPIO的引脚功能寄存器(如GPIOx_AFRL或GPIOx_AFRH,其中x为对应的GPIO端口,如GPIOB),将PB3引脚映射到内部上拉电阻(PUPDD=0)和浮空(PDD=0)模式。

beacherblack 发表于 2023-12-8 22:01

关闭PB3的输出功能,然后将其设置为输入模式。

mollylawrence 发表于 2023-12-9 09:57

建议检查PB3端口的连接是否正确

iyoum 发表于 2023-12-9 15:42

在SWD调试模式            

youtome 发表于 2023-12-9 21:14

是否需要外置上拉电阻,这取决于你的具体应用。

xiaoyaodz 发表于 2023-12-9 21:50

其他代码或硬件配置错误影响了PB3

pattywu 发表于 2023-12-9 22:30

我记得与I2C引脚相同的, 上拉电阻好像是没有的.
页: [1]
查看完整版本: PB3可以设置为输入吗?需要外置上拉电阻吗?怎么试都不行,用过的大神指点下。