Skip to content

Instantly share code, notes, and snippets.

@firebull

firebull/modbus_it.c Secret

Created Dec 21, 2017
Embed
What would you like to do?
// где-то в теле
RS485_ENABLE_RX();
huart2.ErrorCode = HAL_UART_ERROR_NONE;
huart2.RxState = HAL_UART_STATE_BUSY_RX;
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
/******************************/
void modbusMasterGotByte() {
request.state = MODBUS_STATE_RX;
request.buffer[bufferPos] = (uint8_t)(modbusUart.Instance->DR & (uint8_t)0x00FF);
bufferPos++;
HAL_TIM_Base_Stop_IT(&modbusIntervalTimer);
TIM1->CNT = 0;
HAL_TIM_Base_Start_IT(&modbusIntervalTimer);
}
void modbusMasterEndOfFrame(void) {
HAL_TIM_Base_Stop_IT(&modbusIntervalTimer);
__HAL_UART_DISABLE_IT(&modbusUart, UART_IT_RXNE);
modbusUart.RxState = HAL_UART_STATE_READY;
request.state = MODBUS_STATE_GOT_FRAME;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment