From b94da82e17586acac40304618824749aeb6323e9 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 9 Jan 2014 11:42:13 +0100 Subject: [PATCH] [9XR-PRO] i2c was not initialized --- radio/src/targets/sky9x/board_sky9x.cpp | 30 ++++++++++++++++++++--- radio/src/targets/sky9x/coproc_driver.cpp | 26 -------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/radio/src/targets/sky9x/board_sky9x.cpp b/radio/src/targets/sky9x/board_sky9x.cpp index a873bb40b..344b3f0b1 100644 --- a/radio/src/targets/sky9x/board_sky9x.cpp +++ b/radio/src/targets/sky9x/board_sky9x.cpp @@ -531,6 +531,32 @@ void configure_pins( uint32_t pins, uint16_t config ) void opentxBootloader(); +// Set up for volume control (TWI0) +// Need PA3 and PA4 set to peripheral A +void i2cInit() +{ + register Pio *pioptr ; + register uint32_t timing ; + + PMC->PMC_PCER0 |= 0x00080000L ; // Enable peripheral clock to TWI0 + + /* Configure PIO */ + pioptr = PIOA ; + pioptr->PIO_ABCDSR[0] &= ~0x00000018 ; // Peripheral A + pioptr->PIO_ABCDSR[1] &= ~0x00000018 ; // Peripheral A + pioptr->PIO_PDR = 0x00000018 ; // Assign to peripheral + + timing = Master_frequency * 5 / 1000000 ; // 5uS high and low + timing += 15 - 4 ; + timing /= 16 ; + timing |= timing << 8 ; + + TWI0->TWI_CWGR = 0x00040000 | timing ; // TWI clock set + TWI0->TWI_CR = TWI_CR_MSEN | TWI_CR_SVDIS ; // Master mode enable + TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing + NVIC_EnableIRQ(TWI0_IRQn) ; +} + void boardInit() { register Pio *pioptr ; @@ -614,9 +640,7 @@ void boardInit() audioInit(); -#if defined(COPROCESSOR) - coprocInit(); -#endif + i2cInit(); eepromInit(); diff --git a/radio/src/targets/sky9x/coproc_driver.cpp b/radio/src/targets/sky9x/coproc_driver.cpp index 941ed1d8a..af33f4099 100644 --- a/radio/src/targets/sky9x/coproc_driver.cpp +++ b/radio/src/targets/sky9x/coproc_driver.cpp @@ -141,32 +141,6 @@ void coprocWriteData(uint8_t *data, uint32_t size) __enable_irq(); } -// Set up for volume control (TWI0) -// Need PA3 and PA4 set to peripheral A -void coprocInit() -{ - register Pio *pioptr ; - register uint32_t timing ; - - PMC->PMC_PCER0 |= 0x00080000L ; // Enable peripheral clock to TWI0 - - /* Configure PIO */ - pioptr = PIOA ; - pioptr->PIO_ABCDSR[0] &= ~0x00000018 ; // Peripheral A - pioptr->PIO_ABCDSR[1] &= ~0x00000018 ; // Peripheral A - pioptr->PIO_PDR = 0x00000018 ; // Assign to peripheral - - timing = Master_frequency * 5 / 1000000 ; // 5uS high and low - timing += 15 - 4 ; - timing /= 16 ; - timing |= timing << 8 ; - - TWI0->TWI_CWGR = 0x00040000 | timing ; // TWI clock set - TWI0->TWI_CR = TWI_CR_MSEN | TWI_CR_SVDIS ; // Master mode enable - TWI0->TWI_MMR = 0x002F0000 ; // Device 5E (>>1) and master is writing - NVIC_EnableIRQ(TWI0_IRQn) ; -} - #if !defined(SIMU) extern "C" void TWI0_IRQHandler() {