BV HiZ: add CAN self-test
This commit is contained in:
parent
ebd78bc898
commit
5dda9a5fc8
|
@ -430,7 +430,7 @@ static bool busvoodoo_hiz_test_self(void)
|
|||
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
|
||||
gpio_clear(GPIO(BUSVOODOO_RS485_RE_PORT), GPIO(BUSVOODOO_RS485_RE_PIN)); // enable receiver
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_RX_PIN)); // set RX as input with pull up/down
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_RS485_RX_PIN)); // set RX as input with pull up/down
|
||||
// test low signal
|
||||
gpio_set(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO(BUSVOODOO_RS485_RX_PIN)); // pull RX up
|
||||
gpio_clear(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX low
|
||||
|
@ -462,6 +462,52 @@ static bool busvoodoo_hiz_test_self(void)
|
|||
gpio_set_mode(GPIO(BUSVOODOO_RS485_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_RX_PIN)); // set pin to floating
|
||||
}
|
||||
|
||||
// test CAN transceiver
|
||||
if (busvoodoo_full) {
|
||||
// configure transceiver
|
||||
gpio_clear(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // pull low to power transceiver
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX as output (there is a pull-up resistor to 5V)
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO(BUSVOODOO_CAN_RX_PIN)); // set RX as input with pull up/down
|
||||
// test high signal
|
||||
gpio_clear(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN)); // pull RX down
|
||||
gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
|
||||
sleep_us(100); // let voltage settle
|
||||
if (0==gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is still low
|
||||
printf("CAN RX is low while TX is set high\n"); // warn user about the error
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
// test low signal
|
||||
gpio_set(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN)); // pull RX up
|
||||
gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
|
||||
sleep_us(100); // let voltage settle
|
||||
if (gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is still high
|
||||
printf("CAN RX is high while TX is set low\n"); // warn user about the error
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
// test dominant timeout
|
||||
sleep_ms(10); // after 5 ms the output should be switched back from dominant to recessive respite TX being low
|
||||
if (!gpio_get(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO(BUSVOODOO_CAN_RX_PIN))) { // test if RX is now low
|
||||
printf("CAN RX is low while the output should be back to recessive\n"); // warn user about the error
|
||||
#if DEBUG
|
||||
while (true);
|
||||
#else
|
||||
goto error;
|
||||
#endif
|
||||
}
|
||||
// release transceiver
|
||||
gpio_set(GPIO(BUSVOODOO_CAN_EN_PORT), GPIO(BUSVOODOO_CAN_EN_PIN)); // set high to power off transceiver
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_TX_PIN)); // set pin to floating
|
||||
gpio_set_mode(GPIO(BUSVOODOO_CAN_RX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_CAN_RX_PIN)); // set pin to floating
|
||||
}
|
||||
|
||||
to_return = true; // all tests are successful
|
||||
#if DEBUG
|
||||
#else
|
||||
|
@ -615,7 +661,7 @@ static bool busvoodoo_hiz_test_pins(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
// test RS-485 port pin A
|
||||
// test RS-485 output A
|
||||
gpio_set(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // enable transmitter
|
||||
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX as output
|
||||
gpio_set(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO(BUSVOODOO_RS485_TX_PIN)); // set TX high -> A will be high
|
||||
|
|
Loading…
Reference in New Issue