Skip to content

Commit

Permalink
Fixed boot timing issues
Browse files Browse the repository at this point in the history
Reenabled WDT
  • Loading branch information
lmartorella committed Jan 4, 2020
1 parent ab892e1 commit 3535bd2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
8 changes: 3 additions & 5 deletions lm7001_si470_bridge.X/hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
#define MCU_STEREO_PORT PORTBbits.RB3

typedef enum {
DEBUG_INTF = 1,

DEBUG_VALID_CODE = 3,
DEBUG_INVALID_CODE = 4,
DEBUG_RESET = 5
DEBUG_VALID_CODE = 1,
DEBUG_INVALID_CODE = 2,
DEBUG_RESET = 3
}
DEBUG_CODES;
void debug(DEBUG_CODES debugCode);
12 changes: 8 additions & 4 deletions lm7001_si470_bridge.X/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF // *** 3.3V! Brown-out Detect Enable bit (BOD enabled)
Expand Down Expand Up @@ -40,6 +40,7 @@ void debug(DEBUG_CODES debugCode) {
}
}

/*
static void debug8(uint8_t data) {
for (uint8_t i = 0; i < 8; i++) {
DEBUG_TX_PORT = 1;
Expand All @@ -54,6 +55,7 @@ static void debug8(uint8_t data) {
data <<= 1;
}
}
*/

// Decode data received from Pioneer MCU. Not time critical, Pioneer
// waits > 100ms between an update to the next
Expand Down Expand Up @@ -99,11 +101,13 @@ static void __interrupt interruptVector() {
}

void main(void) {
// Assign prescaler to TMR0. 1:256
OPTION_REGbits.PSA = 0;
CLRWDT();
// Assign prescaler to WDT. 1:256
OPTION_REGbits.PSA = 1;
OPTION_REGbits.PS = 7;
// TMR0 internal
OPTION_REGbits.T0CS = 0;
CLRWDT();
// Wdt now up to 2.3s

// Disable comparators to use full porta
CMCON = 7;
Expand Down
11 changes: 4 additions & 7 deletions lm7001_si470_bridge.X/si_fm_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ void si_fm_init() {
SI_RES_PORT = 0;

// Reset with GPIO1 high = I2C
__delay_ms(1);
SI_RES_PORT = 1;

__delay_ms(100);
SI_RES_PORT = 1;
__delay_ms(1000);

si_powerCfg.data = 0; // muted and not ENABLED
si_channel.TUNE = 0;
Expand All @@ -75,16 +74,14 @@ void si_fm_init() {
i2c_write_16(si_powerCfg.data);
i2c_write_16(si_channel.data); // channel, tune disabled
i2c_write_16(0x0080); // System configuration 1: AGC ON, deemphasis Europe, interrupt disabled, RDS disabled
i2c_write_16(0x002F); // System configuration 2: 0db volume, fine band (50 kHz), min RSSI
i2c_write_16(0x7F2F); // System configuration 2: 0db volume, fine band (50 kHz), max RSSI threshold
i2c_write_16(0x0000); // System configuration 3: most stops in seeks, standard volume
//i2c_write_16(0x3c04 | 0x8000, I2C_ACK_STOP); // see datahseet
i2c_write_16(0x8100); // the above doesn't work!
i2c_stop();

// Wait before initializing other registries
CLRWDT();
__delay_ms(150);
CLRWDT();
__delay_ms(300);

// Start muted and ENABLED now
si_powerCfg.ENABLE = 1;
Expand Down

0 comments on commit 3535bd2

Please sign in to comment.