SPI-Brigde (capseld), for polling interrupt, it is neccessary to adapt the constructor and the function getInt()
Diff: SC18IS602.cpp
- Revision:
- 3:9cf83f16c17d
- Parent:
- 2:cb90c271c412
diff -r cb90c271c412 -r 9cf83f16c17d SC18IS602.cpp --- a/SC18IS602.cpp Mon Feb 18 16:03:44 2019 +0000 +++ b/SC18IS602.cpp Thu Apr 23 22:55:50 2020 +0000 @@ -219,14 +219,20 @@ //******************************************************************************// // //******************************************************************************// -bool SC18IS602::sendViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum) +bool SC18IS602::sendViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum) { if((int)uiNum >= BUFFER_SIZE - 1) // If number of sending Bytes greather than BUFFER_SIZE - 1 (Register-Adress-Byte) return NACK; // returns NACK (failure) + + + if( uiCS != CMD_RW.CS0 and uiCS != CMD_RW.CS1 + and uiCS != CMD_RW.CS2 and uiCS != CMD_RW.CS3){ // If uiCS not element of CMD_RW, than return NACK (faiure) + return NACK; + } uiNumByte = 0; - cCmd[uiNumByte] = CMD_RW.CS0; // send via SPI and CS0 (SS0) + cCmd[uiNumByte] = uiCS; // send via SPI and CS0 (SS0) cCmd[++uiNumByte] = cAdrByte; for(int n = uiNum - 1 ; n >= 0; n--) { cCmd[++uiNumByte] = cDataBytes[n]; @@ -235,7 +241,7 @@ uiNumByte++; // char cCmd counts from 0, so the number is +1 bAck = sendViaI2C(cCmd, uiNumByte, "TX via SPI"); // send via SPI - waitFor(INTERRUPT); // If there was an interrupt, wait until it is cleared + waitFor(INTERRUPT); // If there was an interrupt, wait until it is cleared clearInt(); waitFor(not INTERRUPT); // If there was an interrupt, wait until it is cleared @@ -247,15 +253,21 @@ //******************************************************************************// // returns reading data. The first byte is the status byte //******************************************************************************// -bool SC18IS602::readViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum) +bool SC18IS602::readViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum) { if((int)uiNum >= BUFFER_SIZE - 1) // If number of sending Bytes greather than BUFFER_SIZE - 1 (Register-Adress-Byte) return NACK; // returns NACK (failure) + + + if( uiCS != CMD_RW.CS0 and uiCS != CMD_RW.CS1 + and uiCS != CMD_RW.CS2 and uiCS != CMD_RW.CS3){ // If uiCS not element of CMD_RW, than return NACK (faiure) + return NACK; + } // send first time Read comand uiNumByte = 0; - cCmd[uiNumByte++] = CMD_RW.CS0; // send via SPI and CS0 (SS0) + cCmd[uiNumByte++] = uiCS; // send via SPI and CS0 (SS0) cCmd[uiNumByte++] = cAdrByte; for(int n = uiNum - 1 ; n >= 0; n--) {