static void handle_twi_command(void) { uint8_t command; // Get the command from the receive buffer. command = twi_receive_byte(); switch (command) { case TWI_CMD_RESET: // Reset the servo. watchdog_hard_reset(); break; case TWI_CMD_PWM_ENABLE: // Enable PWM to the servo motor. pwm_enable(); break; case TWI_CMD_PWM_DISABLE: // Disable PWM to the servo motor. pwm_disable(); break; case TWI_CMD_WRITE_ENABLE: // Enable write to read/write protected registers. registers_write_enable(); break; case TWI_CMD_WRITE_DISABLE: // Disable write to read/write protected registers. registers_write_disable(); break; case TWI_CMD_REGISTERS_SAVE: // Save register values into EEPROM. eeprom_save_registers(); break; case TWI_CMD_REGISTERS_RESTORE: // Restore register values into EEPROM. eeprom_restore_registers(); break; case TWI_CMD_REGISTERS_DEFAULT: // Restore register values to factory defaults. registers_defaults(); break; case TWI_CMD_EEPROM_ERASE: // Erase the EEPROM. eeprom_erase(); break; case TWI_CMD_VOLTAGE_READ: // Request a voltage reading. adc_read_voltage(); break; #if CURVE_MOTION_ENABLED case TWI_CMD_CURVE_MOTION_ENABLE: // Enable curve motion handling. motion_enable(); break; case TWI_CMD_CURVE_MOTION_DISABLE: // Disable curve motion handling. motion_disable(); break; case TWI_CMD_CURVE_MOTION_RESET: // Reset the motion to the current position. motion_reset(adc_get_position_value()); break; case TWI_CMD_CURVE_MOTION_APPEND: // Append motion curve data stored in the registers. motion_append(); break; #endif default: // Ignore unknown command. break; } }
void user_init(void) { int i; uint8_t buffer[16]; loop_size = rand(); // Data to write uint8_t msg1[] = "Test Message #1"; uint8_t msg2[] = "Test Message #2"; uint8_t msg3[] = "Hello world!"; //Init uart uart_init(BIT_RATE_115200, BIT_RATE_115200); sleepms(1); console_printf("Booting...\r\n"); console_printf("-----------------------------------------------\r\n"); console_printf("AT24C512 Library Benchmark\r\n"); console_printf("-----------------------------------------------\r\n"); // i2c init i2c_init(); // Erase memory eeprom_erase(DEVICEADDRESS, 0, 224); console_printf("-----------------------------------------------\r\n"); // Write some stuff to EEPROM if(!eeprom_writePage(DEVICEADDRESS, 0x00, msg1, sizeof(msg1))) console_printf("Failed write, address: %d, data: %s\r\n", 0x00, msg1); else console_printf("Message 1 stored in the memory.\r\n"); if(!eeprom_writePage(DEVICEADDRESS, 0x40, msg2, sizeof(msg2))) console_printf("Failed write, address: %d, data: %s\r\n", 0x40, msg2); else console_printf("Message 2 stored in the memory.\r\n"); if(!eeprom_writePage(DEVICEADDRESS, 0x80, msg3, sizeof(msg3))) console_printf("Failed write, address: %d, data: %s\r\n", 0x80, msg3); else console_printf("Message 3 stored in the memory.\r\n"); console_printf("-----------------------------------------------\r\n"); // Read the first page in EEPROM memory, a byte at a time console_printf("EEPROM read byte, starting at 0x000:\r\n"); for (i = 0; i < sizeof(msg1)-1; i++) { uint8_t b = eeprom_readByte(DEVICEADDRESS, i); console_printf("0x%02x ", b); } console_printf("\r\n"); for (i = 0; i < sizeof(msg1)-1; i++) { uint8_t b = eeprom_readByte(DEVICEADDRESS, i); console_printf("%c ", isprint(b) ? b : '.'); } console_printf("\r\n"); console_printf("-----------------------------------------------\r\n"); console_printf("EEPROM read buffer, starting at 0x000:\r\n"); os_sprintf(buffer, "%s", eeprom_readPage(DEVICEADDRESS, 0, sizeof(buffer)), sizeof(buffer)); //First print the hex bytes on this row for (i = 0; i < sizeof(buffer)-1; i++) { char outbuf[6]; console_printf("0x%02x ", buffer[i]); } console_printf("\r\n"); for (i = 0; i < sizeof(buffer)-1; i++) { char outbuf[6]; console_printf("%c ", isprint(buffer[i]) ? buffer[i] : '.'); } console_printf("\r\n"); console_printf("-----------------------------------------------\r\n"); // Now dump 224 bytes console_printf("EEPROM dump:\r\n"); eeprom_dump(DEVICEADDRESS, 0, 224); // Start write benchmark test writeByByteTest(); // Start read benchmark test readByByteTest(); system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen); }
static void handle_twi_command(void) { uint8_t command; // Get the command from the receive buffer. command = twi_receive_byte(); switch (command) { case TWI_CMD_RESET: // Reset the servo. watchdog_hard_reset(); break; case TWI_CMD_PWM_ENABLE: #if PWM_STD_ENABLED || PWM_ENH_ENABLED // Enable PWM to the servo motor. pwm_enable(); #endif #if STEP_ENABLED // Enable Stepper motor control. step_enable(); #endif break; case TWI_CMD_PWM_DISABLE: #if PWM_STD_ENABLED || PWM_ENH_ENABLED // Disable PWM to the servo motor. pwm_disable(); #endif #if STEP_ENABLED // Enable Stepper motor control. step_disable(); #endif break; case TWI_CMD_WRITE_ENABLE: // Enable write to read/write protected registers. registers_write_enable(); break; case TWI_CMD_WRITE_DISABLE: // Disable write to read/write protected registers. registers_write_disable(); break; case TWI_CMD_REGISTERS_SAVE: // Save register values into EEPROM. eeprom_save_registers(); break; case TWI_CMD_REGISTERS_RESTORE: // Restore register values into EEPROM. eeprom_restore_registers(); break; case TWI_CMD_REGISTERS_DEFAULT: // Restore register values to factory defaults. registers_defaults(); break; case TWI_CMD_EEPROM_ERASE: // Erase the EEPROM. eeprom_erase(); break; #if CURVE_MOTION_ENABLED case TWI_CMD_CURVE_MOTION_ENABLE: // Enable curve motion handling. motion_enable(); break; case TWI_CMD_CURVE_MOTION_DISABLE: // Disable curve motion handling. motion_disable(); break; case TWI_CMD_CURVE_MOTION_RESET: // Reset the motion to the current position. motion_reset(adc_get_position_value()); break; case TWI_CMD_CURVE_MOTION_APPEND: // Append motion curve data stored in the registers. motion_append(); break; #endif case TWI_CMD_GCALL_ENABLE: // Enable the general call functionality general_call_enable(); break; case TWI_CMD_GCALL_DISABLE: // Disable General call functionaility general_call_disable(); break; case TWI_CMD_GCALL_START_MOVE: // start the general call movement general_call_start_move(); break; case TWI_CMD_GCALL_START_WAIT: // dont move unless we get the start command or the group command general_call_start_wait(); break; case TWI_CMD_PWM_BRAKE_ENABLE: #if PWM_ENH_ENABLED pwm_brake_enable(); #endif break; case TWI_CMD_PWM_BRAKE_DISABLE: #if PWM_ENH_ENABLED pwm_brake_disable(); #endif break; default: // Ignore unknown command. break; } }