AP_OpticalFlow: save and restore SPI bus speed to remove conflict with dataflash that runs at 8Mhz

This commit is contained in:
rmackay9 2012-09-28 17:29:45 +09:00
parent 04c92240c4
commit d0177688b4

View File

@ -128,12 +128,12 @@ void
AP_OpticalFlow_ADNS3080::backup_spi_settings() AP_OpticalFlow_ADNS3080::backup_spi_settings()
{ {
if( _spi_bus == ADNS3080_SPIBUS_1 ) { if( _spi_bus == ADNS3080_SPIBUS_1 ) {
// store current spi mode // store current spi mode and data rate
orig_spi_settings_spcr = SPCR & (CPOL | CPHA); orig_spi_settings_spcr = SPCR & (CPOL | CPHA | SPR1 | SPR0);
// set to our required values // set to our required values
SPI.setDataMode(SPI_MODE3); SPI.setDataMode(SPI_MODE3);
// we do not set speed to 2Mhz because we assume it is that already no more than 2Mhz SPI.setClockDivider(SPI_CLOCK_DIV8); // 2MHZ SPI rate
}else if( _spi_bus == ADNS3080_SPIBUS_3 ) { }else if( _spi_bus == ADNS3080_SPIBUS_3 ) {
/* Wait for empty transmit buffer */ /* Wait for empty transmit buffer */
@ -157,7 +157,7 @@ AP_OpticalFlow_ADNS3080::restore_spi_settings()
if( _spi_bus == ADNS3080_SPIBUS_1 ) { if( _spi_bus == ADNS3080_SPIBUS_1 ) {
// split off the two bits we need to write // split off the two bits we need to write
temp = SPCR & ~(CPOL | CPHA); temp = SPCR & ~(CPOL | CPHA | SPR1 | SPR0);
temp |= orig_spi_settings_spcr; temp |= orig_spi_settings_spcr;
// write back the bits // write back the bits