static void RS485_Init(void)
{
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
/*enable GPIO AF CLOCK*/
rcu_periph_clock_enable(RCU_AF);
/* enable USART clock */
rcu_periph_clock_enable(RCU_UART3);
gpio_pin_remap1_config(GPIO_PCF5,GPIO_PCF5_UART3_REMAP,ENABLE);
gpio_init(GPIOA, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
/* connect port to USART0 Tx */
gpio_init(GPIOA, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
/* connect port to USART0 Rx */
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
/* USART configure */
usart_deinit(UART3);
usart_baudrate_set(UART3, 115200U);
usart_word_length_set(UART3, USART_WL_8BIT);
usart_stop_bit_set(UART3, USART_STB_1BIT);
usart_parity_config(UART3, USART_PM_NONE);
usart_hardware_flow_rts_config(UART3, USART_RTS_DISABLE);
usart_hardware_flow_cts_config(UART3, USART_CTS_DISABLE);
usart_receive_config(UART3, USART_RECEIVE_ENABLE);
usart_transmit_config(UART3, USART_TRANSMIT_ENABLE);
usart_enable(UART3);
}
void RS485_Send_Data(u8 *tx_buffer,u8 len)
{
u8 t,i;
RS485_TX_EN(); ;
for(i=0;i<len;i++)
{
while(RESET == usart_flag_get(UART3, USART_FLAG_TC)) {}
usart_data_transmit(UART3, tx_buffer[i]);
}
while(RESET == usart_flag_get(UART3, USART_FLAG_TC));
}
|