BV HiZ: add CAN pns test

This commit is contained in:
King Kévin 2018-02-14 15:08:23 +01:00
parent 5dda9a5fc8
commit e20d1fbf4d
1 changed files with 81 additions and 0 deletions

View File

@ -687,6 +687,46 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
// test CAN output L
// 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)
// test recessive output
gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
sleep_us(100); // let voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage<0.5) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
printf("CAN L output is low while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
if (voltage>3.0) { // normally the upper limit is 3V
printf("CAN L output is high while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test dominant output
gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
sleep_us(100); // let voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage>2.5) {
printf("CAN L output is high while it should at dominant <2.25V\n");
#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
// test RS-485 port pin B
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
@ -713,6 +753,47 @@ static bool busvoodoo_hiz_test_pins(void)
gpio_clear(GPIO(BUSVOODOO_RS485_DE_PORT), GPIO(BUSVOODOO_RS485_DE_PIN)); // set low to disable transmitter
gpio_set_mode(GPIO(BUSVOODOO_RS485_TX_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(BUSVOODOO_RS485_TX_PIN)); // set pin to floating
// test CAN output H
// 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)
// test recessive output
gpio_set(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX high
sleep_us(100); // let voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage<0.5) { // normally the lower limit is 2V, put pin 4 pulls it down because it is not strongly driven
printf("CAN H output is low while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
if (voltage>3.0) { // normally the upper limit is 3V
printf("CAN H output is high while it should be at recessive 2.5V\n");
#if DEBUG
while (true);
#else
goto error;
#endif
}
// test dominant output
gpio_clear(GPIO(BUSVOODOO_CAN_TX_PORT), GPIO(BUSVOODOO_CAN_TX_PIN)); // set TX low
sleep_us(100); // let voltage settle
voltage = busvoodoo_vreg_get(BUSVOODOO_LV_CHANNEL); // get output voltage
if (voltage<2.5) {
printf("CAN H output is low while it dominant >2.75V\n");
printf("%.02f\n", voltage);
#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
// test RS-232 port (with itself)
rcc_periph_clock_enable(RCC_GPIO(BUSVOODOO_RS232_EN_PORT)); // enable clock for GPIO domain
gpio_clear(GPIO(BUSVOODOO_RS232_EN_PORT), GPIO(BUSVOODOO_RS232_EN_PIN)); // set low to enable receiver