Fixed delay for I2C and SPI
authorBjoernSch <mail@bjoern-schrader.de>
Sat, 6 Aug 2016 10:53:23 +0000 (12:53 +0200)
committerBjoernSch <mail@bjoern-schrader.de>
Sat, 6 Aug 2016 10:53:23 +0000 (12:53 +0200)
Fixed delay for I2C - gone wrong in c91dbb5
Fixed delay for SPI, limited Software-SPI Speed to 250kbps, more is
possible but jitter makes the pulses too short without additional delay.

pigpio.c
pigpio.h

index 3ae2a5235d54fa593556288254e5c7933b1c7d43..9a370539ccc53687297f700643ab29ba5ce9f729 100644 (file)
--- a/pigpio.c
+++ b/pigpio.c
@@ -10044,7 +10044,7 @@ int bbI2COpen(unsigned SDA, unsigned SCL, unsigned baud)
    wfRx[SDA].I.started = 0;
    wfRx[SDA].I.SDA = SDA;
    wfRx[SDA].I.SCL = SCL;
-   wfRx[SDA].I.delay = (500000 / baud) - 1;
+   wfRx[SDA].I.delay = 500000 / baud;
    wfRx[SDA].I.SDAMode = gpioGetMode(SDA);
    wfRx[SDA].I.SCLMode = gpioGetMode(SCL);
 
@@ -10109,7 +10109,7 @@ int bbSPIOpen(unsigned CS, unsigned MISO, unsigned MOSI, unsigned SCLK, unsigned
    wfRx[CS].S.MOSI = MOSI;
    wfRx[CS].S.CS = CS;
    wfRx[CS].S.SCLK = SCLK;
-   wfRx[CS].S.delay = 500000 / baud;
+   wfRx[CS].S.delay = (500000 / baud) - 1;
    wfRx[CS].S.spiFlags = spiFlags;
    wfRx[CS].S.MISOMode = gpioGetMode(MISO);
    wfRx[CS].S.MOSIMode = gpioGetMode(MOSI);
index bdc3a9ac39104f0e9842177dc10746871b44216c..b82932e6f2c354a51b6de11bd1a228ee0ca01ace 100644 (file)
--- a/pigpio.h
+++ b/pigpio.h
@@ -597,7 +597,7 @@ typedef void *(gpioThreadFunc_t) (void *);
 #define PI_BB_I2C_MAX_BAUD 500000
 
 #define PI_BB_SPI_MIN_BAUD     50
-#define PI_BB_SPI_MAX_BAUD 500000
+#define PI_BB_SPI_MAX_BAUD 250000
 
 #define PI_BB_SER_MIN_BAUD     50
 #define PI_BB_SER_MAX_BAUD 250000
@@ -2640,7 +2640,7 @@ for the hardware SPI ports.
  MISO: 0-31
  MOSI: 0-31
  SCLK: 0-31
-baud: 50-500000
+baud: 50-250000
 spiFlags: see below
 . .
 spiFlags consists of the least significant 22 bits.
@@ -2662,6 +2662,12 @@ Mode POL PHA
 
 p0 is 0 if CEx is active low (default) and 1 for active high.
 
+T is 1 if the least significant bit is transmitted on MOSI first, the
+default (0) shifts the most significant bit out first.
+
+R is 1 if the least significant bit is received on MISO first, the
+default (0) receives the most significant bit first.
+
 The other bits in flags should be set to zero.
 
 Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_SPI_BAUD, or