#include "modbus.h" #include "All_define.h" volatile eMBSndState eSndState; volatile eMBRcvState eRcvState; void BSP_modbus(u16 band) { u16 bandvalue = 0; if(band == 0x01e0) { bandvalue = 4800; } else if (band == 0x03c0) { bandvalue = 9600; } else if (band == 0x05a0) { bandvalue = 14400; } else if(band == 0x0780) { bandvalue = 19200; } else if (band == 0x0f00) { bandvalue = 38400; } else if (band == 0x15e0) { bandvalue = 56000; } else { return; } BSP_UART2_Init(bandvalue); uint32_t T35_50us = 0; if(bandvalue > 9600) bandvalue = 9600; //T35_50us = (7UL * 220000UL )/(2UL * bandvalue); T35_50us =5* (10UL *1000000UL)/(bandvalue); BSP_TIM2_Init(T35_50us); eMBRTUStart_Rx(); } void vMBPortSerialEnable( uint8_t xRxEnable, uint8_t xTxEnable ) { if (xRxEnable) { for (uint32_t i = 0; i < 20000; i++) ; gpio_bit_reset(GPIOC, GPIO_PIN_14); //printf("wwwww\r\n"); } else { gpio_bit_set(GPIOC, GPIO_PIN_14); for (uint32_t i = 0; i < 20000; i++) ; //printf("ssddds\r\n"); } if (xTxEnable) { //USART_ITConfig(USART2, USART_IT_TXE, ENABLE); usart_interrupt_enable(USART1,USART_INT_TBE); } else { //USART_ITConfig(USART2, USART_IT_TXE, DISABLE); usart_interrupt_disable(USART1,USART_INT_TBE); } } void eMBRTUStart_Rx( void ) { eRcvState = STATE_RX_IDLE; vMBPortSerialEnable( TRUE, FALSE ); } void eMBRTUStart_Tx( void ) { vMBPortSerialEnable( FALSE, TRUE ); } void eMBRTUStop( void ) { vMBPortSerialEnable( FALSE, FALSE ); } #define Broadcast_addr 0xFF u8 Slave_Addr_check(u8 addr) { if(addr == dis_page_param.face_plate_param.Device_Slave_addr) { return 1; } else { return 0; } }