- void rs485_config(void) {
- rcu_periph_clock_enable(RS485_GPIO_RCU);
- rcu_periph_clock_enable(RS485_RCU);
- gpio_af_set(RS485_GPIO_PORT, GPIO_AF_1, RS485_TX_PIN | RS485_RX_PIN);
- /* configure USART Tx&Rx as alternate function push-pull */
- gpio_mode_set(RS485_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, RS485_TX_PIN | RS485_RX_PIN);
- gpio_output_options_set(RS485_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, RS485_TX_PIN | RS485_RX_PIN);
- /* configure RS485 EN Pin */
- gpio_mode_set(RS485_GPIO_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, RS485_EN_PIN);
- gpio_output_options_set(RS485_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
- gpio_bit_write(RS485_GPIO_PORT, RS485_EN_PIN, RESET);
- /* USART configure */
- usart_deinit(RS485_PHY);
- usart_baudrate_set(RS485_PHY, RS485_BAUDRATE);
- usart_parity_config(RS485_PHY, USART_PM_NONE);
- usart_word_length_set(RS485_PHY, USART_WL_8BIT);
- usart_stop_bit_set(RS485_PHY, USART_STB_1BIT);
- usart_receive_config(RS485_PHY, USART_RECEIVE_ENABLE);
- usart_transmit_config(RS485_PHY, USART_TRANSMIT_ENABLE);
- // usart_driver_assertime_config(RS485_PHY, 0x01);
- // usart_driver_deassertime_config(RS485_PHY, 0x01);
- // usart_depolarity_config(USART0, USART_DEP_HIGH);
- // usart_depolarity_config(USART0, USART_DEP_LOW);
- usart_enable(RS485_PHY);
- // usart_rs485_driver_enable(RS485_PHY);
- nvic_irq_enable(USART0_IRQn, 0);
- usart_interrupt_enable(RS485_PHY, USART_INT_RBNE);
- usart_interrupt_enable(RS485_PHY, USART_INT_IDLE);
- }
然后尝试了使用usart_rs485_driver_enable(RS485_PHY);来使能rs485 driver,具体代码如下
- void rs485_config(void) {
- rcu_periph_clock_enable(RS485_GPIO_RCU);
- rcu_periph_clock_enable(RS485_RCU);
- gpio_af_set(RS485_GPIO_PORT, GPIO_AF_1, RS485_TX_PIN | RS485_RX_PIN | RS485_EN_PIN);
- /* configure USART Tx&Rx as alternate function push-pull */
- gpio_mode_set(RS485_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, RS485_TX_PIN | RS485_RX_PIN);
- gpio_output_options_set(RS485_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, RS485_TX_PIN | RS485_RX_PIN);
- /* configure RS485 EN Pin */
- gpio_mode_set(RS485_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, RS485_EN_PIN);
- gpio_output_options_set(RS485_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
- // gpio_bit_write(RS485_GPIO_PORT, RS485_EN_PIN, RESET);
- /* USART configure */
- usart_deinit(RS485_PHY);
- usart_baudrate_set(RS485_PHY, RS485_BAUDRATE);
- usart_parity_config(RS485_PHY, USART_PM_NONE);
- usart_word_length_set(RS485_PHY, USART_WL_8BIT);
- usart_stop_bit_set(RS485_PHY, USART_STB_1BIT);
- usart_receive_config(RS485_PHY, USART_RECEIVE_ENABLE);
- usart_transmit_config(RS485_PHY, USART_TRANSMIT_ENABLE);
- usart_driver_assertime_config(RS485_PHY, 0x01);
- usart_driver_deassertime_config(RS485_PHY, 0x01);
- usart_depolarity_config(USART0, USART_DEP_HIGH);
- // usart_depolarity_config(USART0, USART_DEP_LOW);
- // usart_enable(RS485_PHY);
- usart_rs485_driver_enable(RS485_PHY);
- nvic_irq_enable(USART0_IRQn, 0);
- usart_interrupt_enable(RS485_PHY, USART_INT_RBNE);
- usart_interrupt_enable(RS485_PHY, USART_INT_IDLE);
- }
让后串口没有一点输出,用示波器看了tx,什么都没有
还有,只要加入了usart_rs485_driver_enable(RS485_PHY);这一行就tx就没有输出,不管rs485 driver的配置相关的其他代码是否在,只要一开driver_enable就不行。
实在没理解哪里配置有问题,麻烦大佬们指点一二