X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=avr%2Fmotor_ctrl%2Fmain.c;h=a4c984dfa4e7e2cbd0219bc29bc7e2017b045b58;hp=ec9965f68800c26812a9eadf04da5e67dd3cec81;hb=5d5f12eaf31287bcbaf01ff211b1366bd48c0658;hpb=540df9f5842bf55260f494c985fd75e4c54fb7cb diff --git a/avr/motor_ctrl/main.c b/avr/motor_ctrl/main.c index ec9965f..a4c984d 100644 --- a/avr/motor_ctrl/main.c +++ b/avr/motor_ctrl/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "uart.h" /* @@ -95,6 +96,8 @@ * 0xA0 Reset reason * 0xA1 Error status * 0xA2 count test + * 0xA3 last i2c status before boot + * 0xA4 Watchdog enable * free * 0xff Bootloader */ @@ -113,6 +116,7 @@ #define WHEEL_DIST 0.39912 // Measured: 0.252 #define PWM_BREAK INT16_MIN #define STALL_LIMIT 140000 +#define I2C_TIMEOUT_DISABLE 255 #define TWI_ACK TWCR = (1<= 100) { + // ~1s without a new i2c command + cmd_vel.speed = 0; + cmd_vel.angle = 0; + cmd_vel.bUpdate = 1; + if (last_man_update_count == 100) { + printf_P(PSTR("I2C State: 0x%x\r\n"), last_i2c_status); + eeprom_write_byte((uint8_t*)1, last_i2c_status); + eeprom_busy_wait(); + } + last_man_update_count = I2C_TIMEOUT_DISABLE; + } } sleep_mode();