public void mcp2515_execute_reset_command() { // Reset chip to get initial condition and wait for operation mode state bit for (int i = 0; i < 3; i++) { if (globalDataSet.DebugMode) { Debug.Write("Reset chip receiver " + i + "\n"); } byte[] returnMessage = new byte[1]; globalDataSet.writeSimpleCommandSpi(mcp2515.SPI_INSTRUCTION_RESET, globalDataSet.do_mcp2515_cs_rec); // Read the register value byte actualMode = globalDataSet.mcp2515_execute_read_command(mcp2515.CONTROL_REGISTER_CANSTAT, globalDataSet.do_mcp2515_cs_rec); timeStopper.Reset(); timeStopper.Start(); while (((actualMode & mcp2515.CONTROL_REGISTER_CANSTAT_VALUE.CONFIGURATION_MODE) != mcp2515.CONTROL_REGISTER_CANSTAT_VALUE.CONFIGURATION_MODE) && (timeStopper.ElapsedMilliseconds <= globalDataSet.MAX_WAIT_TIME)) { actualMode = globalDataSet.mcp2515_execute_read_command(mcp2515.CONTROL_REGISTER_CANSTAT, globalDataSet.do_mcp2515_cs_rec); } if (timeStopper.ElapsedMilliseconds > globalDataSet.MAX_WAIT_TIME) { if (globalDataSet.DebugMode) { Debug.Write("Abort waiting for mode switch. Max. waiting time reached. Try again." + "\n"); } // TODO Add to global error handling thread } else { if (globalDataSet.DebugMode) { Debug.Write("Switch receiver to mode " + actualMode.ToString() + " successfully" + "\n"); } break; } } }
public void mcp2515_execute_reset_command() { // Reset chip to get initial condition and wait for operation mode state bit if (globalDataSet.DebugMode) { Debug.Write("Reset chip sender" + "\n"); } byte[] returnMessage = new byte[1]; globalDataSet.writeSimpleCommandSpi(mcp2515.SPI_INSTRUCTION_RESET, globalDataSet.do_mcp2515_cs_sen); // Read the register value byte actualMode = globalDataSet.mcp2515_execute_read_command(mcp2515.CONTROL_REGISTER_CANSTAT, globalDataSet.do_mcp2515_cs_sen); while (mcp2515.CONTROL_REGISTER_CANSTAT_VALUE.CONFIGURATION_MODE != (mcp2515.CONTROL_REGISTER_CANSTAT_VALUE.CONFIGURATION_MODE & actualMode)) { actualMode = globalDataSet.mcp2515_execute_read_command(mcp2515.CONTROL_REGISTER_CANSTAT, globalDataSet.do_mcp2515_cs_sen); } if (globalDataSet.DebugMode) { Debug.Write("Switch sender to mode " + actualMode.ToString() + " successfully" + "\n"); } }