]> defiant.homedns.org Git - ros_wild_thumper.git/blobdiff - avr/motor_ctrl/main.c
avr: test i2c fixes for status = TW_NO_INFO
[ros_wild_thumper.git] / avr / motor_ctrl / main.c
index b0d9cbfe00aba102cc72ce4f82173b5eefa30eac..f7c9f0ae73822057176994f8082b4660970988bc 100644 (file)
@@ -8,6 +8,7 @@
 #include <util/twi.h>
 #include <avr/eeprom.h>
 #include <avr/wdt.h>
 #include <util/twi.h>
 #include <avr/eeprom.h>
 #include <avr/wdt.h>
+#include <avr/pgmspace.h>
 #include "uart.h"
 
 /*
 #include "uart.h"
 
 /*
@@ -184,7 +185,8 @@ static volatile uint8_t count_test=0;
 static volatile uint8_t front_handicap=0;
 static volatile uint8_t aft_handicap=0;
 static volatile uint8_t error_state=0;
 static volatile uint8_t front_handicap=0;
 static volatile uint8_t aft_handicap=0;
 static volatile uint8_t error_state=0;
-static volatile uint8_t last_man_update_count=I2C_TIMEOUT_DISABLE;
+static volatile uint8_t last_man_update_count=0;
+static volatile uint8_t last_i2c_status = 0;
 
 ISR(TWI_vect)
 {
 
 ISR(TWI_vect)
 {
@@ -193,6 +195,7 @@ ISR(TWI_vect)
        static ufloat_t tmp_speed;
        static ufloat_t tmp_angle;
 
        static ufloat_t tmp_speed;
        static ufloat_t tmp_angle;
 
+       last_i2c_status = TW_STATUS;
        switch(TW_STATUS)
        {
                case TW_SR_SLA_ACK: // start write
        switch(TW_STATUS)
        {
                case TW_SR_SLA_ACK: // start write
@@ -625,6 +628,8 @@ ISR(TWI_vect)
                case TW_SR_STOP:
                        TWI_ACK;
                        break;
                case TW_SR_STOP:
                        TWI_ACK;
                        break;
+               case TW_NO_INFO:
+                       break;
                default:
                        TWI_RESET;
        }
                default:
                        TWI_RESET;
        }
@@ -1083,7 +1088,7 @@ int main(void) {
        TCCR0 = (1 << WGM01) | (1 << WGM00) | (1 << CS00);
        OCR0 = 0;
 
        TCCR0 = (1 << WGM01) | (1 << WGM00) | (1 << CS00);
        OCR0 = 0;
 
-       printf("\r\nStart\r\n");
+       printf_P(PSTR("\r\nStart\r\n"));
 
        set_sleep_mode(SLEEP_MODE_IDLE);
        // Enable Timer 1 Overflow Interrupt
 
        set_sleep_mode(SLEEP_MODE_IDLE);
        // Enable Timer 1 Overflow Interrupt
@@ -1149,11 +1154,14 @@ int main(void) {
                        count_test++;
                        if (last_man_update_count != I2C_TIMEOUT_DISABLE) last_man_update_count++;
 
                        count_test++;
                        if (last_man_update_count != I2C_TIMEOUT_DISABLE) last_man_update_count++;
 
-                       if (last_man_update_count > 100) {
+                       if (last_man_update_count >= 100) {
                                // ~1s without a new i2c command
                                cmd_vel.speed = 0;
                                cmd_vel.angle = 0;
                                cmd_vel.bUpdate = 1;
                                // ~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);
+                               }
                                last_man_update_count = I2C_TIMEOUT_DISABLE;
                        }
                }
                                last_man_update_count = I2C_TIMEOUT_DISABLE;
                        }
                }