Skip to content

Commit

Permalink
SPI bus speed divider to 4, suggested by Greg Copeland. Also removed …
Browse files Browse the repository at this point in the history
…duplicated spi setup out of begin(), as it's all in csn()
  • Loading branch information
maniacbug committed Sep 13, 2011
1 parent a4cabc6 commit a28e236
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@

void RF24::csn(int mode)
{
// Minimum ideal SPI bus speed is 2x data rate
// If we assume 2Mbs data rate and 16Mhz clock, a
// divider of 4 is the minimum we want.
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setClockDivider(SPI_CLOCK_DIV4);
digitalWrite(csn_pin,mode);
}

Expand Down Expand Up @@ -315,17 +319,7 @@ void RF24::begin(void)
pinMode(csn_pin,OUTPUT);

// Initialize SPI bus
// Minimum ideal SPI bus speed is 2x data rate
// If we assume 2Mbs data rate and 16Mhz clock, a
// divider of 4 is the minimum we want.
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
// We'll use a divider of 2 which will work up to
// MCU speeds of 20Mhz.
// CLK:BUS 8Mhz:4Mhz, 16Mhz:8Mhz, or 20Mhz:10Mhz (max)
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);

ce(LOW);
csn(HIGH);
Expand Down

0 comments on commit a28e236

Please sign in to comment.