SkyeSweeney / Striker

AS3935 Lightning Detector Arduino code
7 stars 4 forks source link

io_read and io_write don't work for SPI #1

Open jetty840 opened 11 years ago

jetty840 commented 11 years ago

This solves it:

INT8U io_read(RegisterID_e reg, REG_u *val) {

ifdef USE_I2C

return(i2c_read(as3935_addr, reg, val));

endif

ifdef USE_SPI

INT8U c;

/* Enable chip select */ digitalWrite(SS_PIN, LOW);

/* Write register address */ c = SPI.transfer(((INT8U)reg&0x3f) | 0x40);

/* Read value */ c = SPI.transfer(0x00);

/* Disable chip select */ digitalWrite(SS_PIN, HIGH);

val->data = c;

return(0);

endif

}

INT8U io_write(RegisterID_e reg, REG_u val) {

ifdef USE_I2C

return(i2c_write(as3935_addr, reg, val));

endif

ifdef USE_SPI

/* Enable chip select */ digitalWrite(SS_PIN, LOW);

/* Write register address with read bit set */ SPI.transfer((INT8U)reg & 0x3f);

/* write value */ SPI.transfer(val.data);

/* Disable chip select */ digitalWrite(SS_PIN, HIGH);

return 0;

endif

}

SkyeSweeney commented 11 years ago

This does indeed fix the problem. What a stupid mistake. I will try to fold this change it tonight.

----- Original Message ----- From: jetty840 To: SkyeSweeney/Striker Sent: Friday, July 26, 2013 11:49 PM Subject: [Striker] io_read and io_write don't work for SPI (#1)

This solves it:

INT8U io_read(RegisterID_e reg, REG_u *val) {

ifdef USE_I2C

return(i2c_read(as3935_addr, reg, val));

endif

ifdef USE_SPI

INT8U c;

/* Enable chip select */ digitalWrite(SS_PIN, LOW);

/* Write register address */ c = SPI.transfer(((INT8U)reg&0x3f) | 0x40);

/* Read value */ c = SPI.transfer(0x00);

/* Disable chip select */ digitalWrite(SS_PIN, HIGH);

val->data = c;

return(0);

endif

}

INT8U io_write(RegisterID_e reg, REG_u val) {

ifdef USE_I2C

return(i2c_write(as3935_addr, reg, val));

endif

ifdef USE_SPI

/* Enable chip select */ digitalWrite(SS_PIN, LOW);

/* Write register address with read bit set */ SPI.transfer((INT8U)reg & 0x3f);

/* write value */ SPI.transfer(val.data);

/* Disable chip select */ digitalWrite(SS_PIN, HIGH);

return 0;

endif

}

— Reply to this email directly or view it on GitHub.