]> granicus.if.org Git - esp-idf/commitdiff
SPI: SPI master clock calculation: n has a minimum of 2 to allow for both a low and...
authorJeroen Domburg <jeroen@espressif.com>
Mon, 24 Apr 2017 08:13:22 +0000 (16:13 +0800)
committerJeroen Domburg <jeroen@espressif.com>
Thu, 27 Apr 2017 03:49:04 +0000 (11:49 +0800)
components/driver/spi_master.c

index 28e964787e767015585757e5919e2914e199b837..5b6b0b477fd10bcf382aaae29911dc763b0901d7 100644 (file)
@@ -300,7 +300,7 @@ static int spi_set_clock(spi_dev_t *hw, int fapb, int hz, int duty_cycle) {
         int bestpre=-1;
         int besterr=0;
         int errval;
-        for (n=1; n<=64; n++) {
+        for (n=2; n<=64; n++) { //Start at 2: we need to be able to set h/l so we have at least one high and one low pulse.
             //Effectively, this does pre=round((fapb/n)/hz).
             pre=((fapb/n)+(hz/2))/hz;
             if (pre<=0) pre=1;