kopia lustrzana https://github.com/SP8EBC/ParaTNC
few bugfixes in mobus rtu and serial driver
rodzic
6b0fbcdf31
commit
4756d9c341
|
@ -352,6 +352,8 @@ int main(int argc, char* argv[]){
|
|||
|
||||
main_modbus_rtu_master_enabled = 1;
|
||||
|
||||
rtu_serial_start();
|
||||
|
||||
#else
|
||||
// initializing UART drvier
|
||||
srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1);
|
||||
|
|
|
@ -417,7 +417,7 @@ uint8_t srl_receive_data_with_callback(srl_context_t *ctx, srl_rx_termination_ca
|
|||
|
||||
ctx->srl_rx_bytes_counter = 0;
|
||||
|
||||
ctx->srl_rx_lenght_param_addres = 0;
|
||||
ctx->srl_rx_lenght_param_addres = ctx->srl_rx_buf_ln - 1;
|
||||
ctx->srl_rx_lenght_param_modifier = 0;
|
||||
|
||||
ctx->srl_triggered_start = 0;
|
||||
|
@ -426,6 +426,10 @@ uint8_t srl_receive_data_with_callback(srl_context_t *ctx, srl_rx_termination_ca
|
|||
|
||||
ctx->srl_rx_timeout_calc_started = 0;
|
||||
|
||||
ctx->srl_rx_state = SRL_RXING;
|
||||
ctx->port->CR1 |= USART_CR1_RE; // uruchamianie odbiornika
|
||||
ctx->port->CR1 |= USART_CR1_RXNEIE;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,10 @@ int32_t rtu_request_03_04_registers(int8_t input_or_holding, uint8_t* output, ui
|
|||
crc = rtu_crc_buffer(output, 6);
|
||||
|
||||
// append the crc value
|
||||
*(output + 6) = (crc & 0xFF00) >> 8;
|
||||
*(output + 7) = crc & 0xFF;
|
||||
*(output + 7) = (crc & 0xFF00) >> 8;
|
||||
*(output + 6) = crc & 0xFF;
|
||||
|
||||
*output_ln_used = 8;
|
||||
|
||||
retval = MODBUS_RET_OK;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ uint32_t rtu_time_of_last_receive = 0;
|
|||
/**
|
||||
* CRC value after the last call to rtu_serial_callback
|
||||
*/
|
||||
uint16_t rtu_serial_previous_crc = 0;
|
||||
uint16_t rtu_serial_previous_crc = 0xFFFF;
|
||||
|
||||
/**
|
||||
* A callback for stream CRC calculation
|
||||
|
@ -142,7 +142,7 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
|
||||
// generate request content
|
||||
result = rtu_request_03_04_registers(
|
||||
0,
|
||||
1,
|
||||
serial_context->srl_tx_buf_pointer,
|
||||
serial_context->srl_tx_buf_ln,
|
||||
&output_data_lenght,
|
||||
|
@ -177,6 +177,8 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
// trigger the transmission itself
|
||||
result = srl_start_tx(serial_context, output_data_lenght);
|
||||
|
||||
rtu_serial_previous_crc = 0xFFFF;
|
||||
|
||||
// if serial transmission has been starter
|
||||
if (result == SRL_OK) {
|
||||
// proceed to the next state (transmitting)
|
||||
|
@ -218,7 +220,7 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
case RTU_POOL_RECEIVING: {
|
||||
|
||||
// if data reception still took place
|
||||
if (serial_context->srl_rx_state == SRL_WAITING_TO_RX || serial_context->srl_rx_state == SRL_RXING) {
|
||||
if (serial_context->srl_rx_state == SRL_WAITING_TO_RX || serial_context->srl_rx_state == SRL_RXING || serial_context->srl_rx_state == SRL_RX_IDLE) {
|
||||
// wait
|
||||
;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue