X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fmodbus.c;h=6ab5b88d20b64d3ec7c88b3cac14cee4618f5181;hb=HEAD;hp=e45f5f0f7ba9064472ba9ff6510ac5e4fdc5df3b;hpb=63da2000b15179f9c6c42965f9cc0115ed95c5f7;p=openparking.git diff --git a/firmware/modbus.c b/firmware/modbus.c index e45f5f0..6ab5b88 100644 --- a/firmware/modbus.c +++ b/firmware/modbus.c @@ -14,7 +14,7 @@ #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) @@ -28,7 +28,7 @@ typedef uint8_t bufptr_t; #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; @@ -47,10 +47,12 @@ uint16_t hold_regs[MB_N_HOLD_REGS]; #if MB_N_HOLD_REGS_EEPROM > 0 static uint16_t hold_regs_ee[MB_N_HOLD_REGS_EEPROM] EEMEM = { - 42, - 0, 0, 0, 30, 30, 30, 30, 0, 0, 0, 0, 30, - (1 << 4) | (1 << 11), // LED 1 - 0, // LED 2 + 99, + //0 1 2 3 4 5 6 7 8 9 10 11 + //1 2 3 4 5 6 7 8 9 10 11 12 + 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 0, 0, + 0x3E0, // LED 1 + 0x01F, // LED 2 }; #endif @@ -199,14 +201,14 @@ uint8_t modbus_poll() 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) @@ -267,7 +269,8 @@ ISR(USART_TX_vect) 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 {