From a2cccbde7126112cb89d1a9a8a6ae2fa83d5e263 Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Mon, 25 Jan 2021 20:58:15 +0100 Subject: [PATCH] Init power outputs to zero on startup --- poweriface/firmware/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/poweriface/firmware/main.c b/poweriface/firmware/main.c index 8022922..611a080 100644 --- a/poweriface/firmware/main.c +++ b/poweriface/firmware/main.c @@ -8,11 +8,21 @@ static bool report_change = false; +uint16_t bang(uint16_t data); +void strobe(); +void uart_bang(uint8_t data); + static void init() { // Enable GPIO: PB2, PB3, PB4 output, low; PB5 input, pull-up on - PORTB = (PORTB & ~(_BV(PB2) | _BV(PB3) | _BV(PB4))) | _BV(PB5); + PORTB = (PORTB & ~(_BV(PB2) | _BV(PB3) | _BV(PB4))) | _BV(PB5); DDRB = (DDRB & ~_BV(PB5)) | (_BV(PB2) | _BV(PB3) | _BV(PB4)); - + + // Important: Before we do anything else, reset all outputs + // The shift registers have an undefined state at startup, + // and there are no pull-downs on the outputs. + bang(0x0000); + strobe(); + // Initialize CAN interface can_init(BITRATE_125_KBPS); // Regular receive/transmit mode