#include "clock.h"
#include "modbus.h"
-#define BUFSIZE 128 // maximum request size
+#define BUFSIZE 180 // maximum request size
// configure the control pin
#define ctl_pin_setup() do { DDRD |= _BV(PD2); } while (0)
#endif
static volatile bufptr_t buf_len, tx_ptr;
-static volatile uint8_t buffer[BUFSIZE], transmitting;;
+static volatile uint8_t buffer[BUFSIZE], transmitting;
static volatile uint16_t last_rx;
#ifndef mb_unit_id
static uint8_t mb_unit_id;
switch (buffer[1]) { // function
case 3:
- if (packet_len == 5)
+ if (packet_len == 6)
rv = read_holding_regs(
get_word(buffer, 2),
get_word(buffer, 4)
);
break;
case 6:
- if (packet_len == 5)
+ if (packet_len == 6)
rv = write_single_reg(
get_word(buffer, 2),
get_word(buffer, 4)
ISR(USART_UDRE_vect)
{
- if (tx_ptr+1 >= buf_len) {
+ if (tx_ptr >= buf_len) {
+ UCSR0A |= _BV(TXC0); // clear the pending TXC flag
UCSR0B |= _BV(TXCIE0); // enable xmit complete irq
UCSR0B &= ~_BV(UDRIE0); // disable ourselves
} else {