在freertos中移植的freemodbus协议按照协议栈初始化了发送的串口,以及485控制引脚,但是通过modbus poll ping 不通,一直显示timeout, 检查并没有发现那里有明显的错误,**有移植过freemodbus协议栈的大佬能指点一下,万分感谢 BOOLxMBPortTimersInit( USHORT usTim1Timerout50us ){ uint16_t PrescalerValue = 0; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); PrescalerValue = (uint16_t)(SystemCoreClock / 20000) - 1; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_Period = usTim1Timerout50us; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); TIM_ARRPreloadConfig(TIM6, ENABLE); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; TIM_ClearITPendingBit(TIM6,TIM_IT_Update); TIM_ITConfig(TIM6, TIM_IT_Update, DISABLE); TIM_Cmd(TIM6,DISABLE); return TRUE;}voidvMBPortTimersEnable( ){ TIM_ClearITPendingBit(TIM6, TIM_IT_Update); TIM_ITConfig(TIM6, TIM_IT_Update, ENABLE); TIM_SetCounter(TIM6,0x0000); TIM_Cmd(TIM6, ENABLE);}voidvMBPortTimersDisable( ){ TIM_ClearITPendingBit(TIM6, TIM_IT_Update); TIM_ITConfig(TIM6, TIM_IT_Update, DISABLE); TIM_SetCounter(TIM6,0x0000); TIM_Cmd(TIM6, DISABLE);}void TIM6_IRQHandler(void){ if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM6, TIM_IT_Update); prvvTIMERExpiredISR( ); }}BOOLxMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity ){ (void)ucPORT; (void)ucDataBits; (void)eParity; GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = ulBaudRate; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_Init(USART2, &USART_InitStructure); USART_Cmd(USART2, ENABLE); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); return TRUE;}BOOLxMBPortSerialPutByte( CHAR ucByte ){ USART_SendData(USART2, ucByte); return TRUE;}BOOLxMBPortSerialGetByte( CHAR * pucByte ){ *pucByte = USART_ReceiveData( USART2 ); return TRUE;}voidvMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable ){ if( xRxEnable ) { USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); RS485_Rx; } else { USART_ITConfig(USART2, USART_IT_RXNE, DISABLE); RS485_Tx; } if( xTxEnable ) { USART_ITConfig(USART2, USART_IT_TC, ENABLE); } else { USART_ITConfig(USART2, USART_IT_TC, DISABLE); }}void USART2_IRQHandler(void){ if( USART_GetITStatus(USART2, USART_IT_RXNE) == SET ) { prvvUARTRxISR(); USART_ClearITPendingBit(USART2, USART_IT_RXNE); } if( USART_GetITStatus(USART2, USART_IT_TC) == SET ) { prvvUARTTxReadyISR(); USART_ClearITPendingBit(USART2, USART_IT_TC); }}
|
|
|