Skip to content
Snippets Groups Projects
Commit c4c3429b authored by Benjamin Koch's avatar Benjamin Koch
Browse files

some small changes

parent 5092a1fc
No related branches found
No related tags found
No related merge requests found
......@@ -248,7 +248,7 @@ impl RS485 {
// We have a long 1, i.e. UART is idle. Wait for start bit.
"have_long_high:",
"irq set 1", // notify MCU in case they want to know about this (start of Modbus frame)
"irq set 1", // notify MCU in case they want to know about this (end of Modbus frame)
"wait 0 pin 0",
"nop [4]",
"jmp pin wait_idle", // abort if zero was just a glitch
......@@ -324,8 +324,8 @@ impl RS485 {
let mut cfg = Config::default();
let loaded_program = common.load_program(&relocated);
cfg.use_program(&loaded_program, &[]);
const SM_FREQ: u32 = 125_000_000;
cfg.clock_divider = (U56F8!(125_000_000) / U56F8!(125_000_000 /* SM_FREQ */)).to_fixed();
const SM_FREQ: u32 = 25_000_000;
cfg.clock_divider = (U56F8!(125_000_000) / U56F8!(25_000_000 /* SM_FREQ */)).to_fixed();
cfg.shift_in = ShiftConfig {
auto_fill: true,
threshold: 32,
......@@ -343,9 +343,10 @@ impl RS485 {
sm.set_config(&cfg);
sm.set_enable(true);
// Timeout: Modbus wants 1.5 ms between frames so we make this a bit smaller. SM runs at 25 MHz
// but we need two clocks per loop.
let timeout_start_value = (SM_FREQ as f32 * 1.4e-3 / 2.) as u32;
// Timeout: Modbus wants 3.5 char times between frames but we should detect the end of a frame
// after 1.5 char times. This is 0.86 ms at 19200 baud (8e1, i.e. 11 baud times per char).
// We need two clocks for each loop.
let timeout_start_value = (SM_FREQ as f32 * 0.86e-3 / 2.) as u32;
sm.tx().push(timeout_start_value);
info!("timeout_start_value: {} = 0x{:08x}", timeout_start_value, timeout_start_value);
......@@ -395,7 +396,6 @@ impl RS485 {
let mut rxcrc = CRC.digest();
let mut rx_expected_bytes = ModbusFrameLength::NeedMoreData(3);
let mut rx_received_bytes = 0u16;
let mut rx_char_prev: u8 = 0;
const TX_BUF_LENGTH: usize = 32;
let mut txbuf = Vec::<u8, TX_BUF_LENGTH>::new();
......@@ -560,19 +560,19 @@ impl RS485 {
tx_data[i + 1] = x as u32 | (((parity as u32) & 1) << 8);
}
info!("Modbus reply: {:?}", txbuf);
tx_future = DontAbort::new(sm1.tx().dma_push(dma_tx_ref.reborrow(),
&tx_data[0..(txbuf.len()+1)]), HangIfReused);
}
}
rxbuf.clear();
rxcrc = CRC.digest();
//rxcrc = CRC.digest(); // re-init already done above, don't repeat to avoid warning
rx_expected_bytes = ModbusFrameLength::NeedMoreData(3);
rx_received_bytes = 0;
}
}
rx_char_prev = rx_char;
},
Result::Err(e) => {
info!("RX error {:?}", e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment