SPI-Brigde (capseld), for polling interrupt, it is neccessary to adapt the constructor and the function getInt()
SC18IS602.cpp@1:2a7edc2be6df, 2019-02-01 (annotated)
- Committer:
- x1dmoesc
- Date:
- Fri Feb 01 15:46:53 2019 +0000
- Revision:
- 1:2a7edc2be6df
- Parent:
- 0:833cb2c6da5d
- Child:
- 2:cb90c271c412
- debug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
x1dmoesc | 0:833cb2c6da5d | 1 | #include "SC18IS602.h" |
x1dmoesc | 0:833cb2c6da5d | 2 | #include "mbed.h" |
x1dmoesc | 0:833cb2c6da5d | 3 | |
x1dmoesc | 0:833cb2c6da5d | 4 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 5 | // constructor |
x1dmoesc | 0:833cb2c6da5d | 6 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 7 | SC18IS602::SC18IS602(I2C *_i2c, uint8_t uiAdr) // |
x1dmoesc | 0:833cb2c6da5d | 8 | : SC18IS602_W(HARD_ADR | (uiAdr & USER_ADR_MASK) << 1), // Initialisation list: const WRITE |
x1dmoesc | 0:833cb2c6da5d | 9 | SC18IS602_R( SC18IS602_W | 0x01), // const READ |
x1dmoesc | 0:833cb2c6da5d | 10 | iINT(0){ |
x1dmoesc | 0:833cb2c6da5d | 11 | // |
x1dmoesc | 0:833cb2c6da5d | 12 | i2c = _i2c; // |
x1dmoesc | 0:833cb2c6da5d | 13 | bAck = NACK; // |
x1dmoesc | 0:833cb2c6da5d | 14 | for(int i = 0; i < BUFFER_SIZE; i++) // clear buffer |
x1dmoesc | 0:833cb2c6da5d | 15 | cCmd[i] = 0; |
x1dmoesc | 0:833cb2c6da5d | 16 | |
x1dmoesc | 0:833cb2c6da5d | 17 | if(getInt()) clearInt(); // |
x1dmoesc | 1:2a7edc2be6df | 18 | |
x1dmoesc | 1:2a7edc2be6df | 19 | |
x1dmoesc | 1:2a7edc2be6df | 20 | getInt_ptr = NULL; |
x1dmoesc | 0:833cb2c6da5d | 21 | |
x1dmoesc | 0:833cb2c6da5d | 22 | } |
x1dmoesc | 0:833cb2c6da5d | 23 | |
x1dmoesc | 0:833cb2c6da5d | 24 | |
x1dmoesc | 0:833cb2c6da5d | 25 | |
x1dmoesc | 0:833cb2c6da5d | 26 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 27 | // constructor |
x1dmoesc | 0:833cb2c6da5d | 28 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 29 | SC18IS602::SC18IS602(I2C *_i2c, PCA9555 *_pca , uint8_t uiAdr) // |
x1dmoesc | 0:833cb2c6da5d | 30 | : SC18IS602_W(HARD_ADR | (uiAdr & USER_ADR_MASK) << 1), // Initialisation list: const WRITE |
x1dmoesc | 0:833cb2c6da5d | 31 | SC18IS602_R( SC18IS602_W | 0x01), // const READ |
x1dmoesc | 0:833cb2c6da5d | 32 | iINT(1){ |
x1dmoesc | 0:833cb2c6da5d | 33 | // |
x1dmoesc | 0:833cb2c6da5d | 34 | i2c = _i2c; // |
x1dmoesc | 0:833cb2c6da5d | 35 | pca = _pca; // |
x1dmoesc | 0:833cb2c6da5d | 36 | bAck = NACK; // |
x1dmoesc | 0:833cb2c6da5d | 37 | for(int i = 0; i < BUFFER_SIZE; i++) // clear buffer |
x1dmoesc | 0:833cb2c6da5d | 38 | cCmd[i] = 0; |
x1dmoesc | 0:833cb2c6da5d | 39 | |
x1dmoesc | 0:833cb2c6da5d | 40 | if(getInt()) clearInt(); // |
x1dmoesc | 0:833cb2c6da5d | 41 | |
x1dmoesc | 0:833cb2c6da5d | 42 | } |
x1dmoesc | 0:833cb2c6da5d | 43 | |
x1dmoesc | 0:833cb2c6da5d | 44 | |
x1dmoesc | 0:833cb2c6da5d | 45 | |
x1dmoesc | 0:833cb2c6da5d | 46 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 47 | // constructor |
x1dmoesc | 0:833cb2c6da5d | 48 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 49 | SC18IS602::SC18IS602(I2C *_i2c, DigitalIn *_IntPin, uint8_t uiAdr)// |
x1dmoesc | 0:833cb2c6da5d | 50 | : SC18IS602_W(HARD_ADR | (uiAdr & USER_ADR_MASK) << 1), // Initialisation list: const WRITE |
x1dmoesc | 0:833cb2c6da5d | 51 | SC18IS602_R( SC18IS602_W | 0x01), // const READ |
x1dmoesc | 0:833cb2c6da5d | 52 | iINT(2){ |
x1dmoesc | 0:833cb2c6da5d | 53 | // |
x1dmoesc | 0:833cb2c6da5d | 54 | i2c = _i2c; // |
x1dmoesc | 0:833cb2c6da5d | 55 | IntPin = _IntPin; // |
x1dmoesc | 0:833cb2c6da5d | 56 | bAck = NACK; // |
x1dmoesc | 0:833cb2c6da5d | 57 | for(int i = 0; i < BUFFER_SIZE; i++) // clear buffer |
x1dmoesc | 0:833cb2c6da5d | 58 | cCmd[i] = 0; |
x1dmoesc | 0:833cb2c6da5d | 59 | |
x1dmoesc | 0:833cb2c6da5d | 60 | if(getInt()) clearInt(); // |
x1dmoesc | 0:833cb2c6da5d | 61 | |
x1dmoesc | 0:833cb2c6da5d | 62 | } |
x1dmoesc | 0:833cb2c6da5d | 63 | |
x1dmoesc | 0:833cb2c6da5d | 64 | |
x1dmoesc | 0:833cb2c6da5d | 65 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 66 | // |
x1dmoesc | 0:833cb2c6da5d | 67 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 68 | bool SC18IS602::configSPI(uint8_t uiConf){ // |
x1dmoesc | 0:833cb2c6da5d | 69 | // |
x1dmoesc | 0:833cb2c6da5d | 70 | cCmd[0] = ADR_SPI_CONF; // |
x1dmoesc | 0:833cb2c6da5d | 71 | cCmd[1] = uiConf & 0x2F; // clear reserved bits 0b0010'1111 |
x1dmoesc | 0:833cb2c6da5d | 72 | sprintf(cDebug, "Config SPI:%*s0x%02x", 5, " ", uiConf); |
x1dmoesc | 0:833cb2c6da5d | 73 | return sendViaI2C(cCmd, 2, cDebug); // |
x1dmoesc | 0:833cb2c6da5d | 74 | } |
x1dmoesc | 0:833cb2c6da5d | 75 | |
x1dmoesc | 0:833cb2c6da5d | 76 | |
x1dmoesc | 0:833cb2c6da5d | 77 | |
x1dmoesc | 0:833cb2c6da5d | 78 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 79 | // |
x1dmoesc | 0:833cb2c6da5d | 80 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 81 | bool SC18IS602::enableGPIO(uint8_t uiConf){ // |
x1dmoesc | 0:833cb2c6da5d | 82 | // |
x1dmoesc | 0:833cb2c6da5d | 83 | cCmd[0] = ADR_GPIO_EN; // |
x1dmoesc | 0:833cb2c6da5d | 84 | cCmd[1] = uiConf & 0x0F; // clear reserved bits 0b0000'1111 |
x1dmoesc | 0:833cb2c6da5d | 85 | return sendViaI2C(cCmd, 2, "Enable GPIO"); // |
x1dmoesc | 0:833cb2c6da5d | 86 | } |
x1dmoesc | 0:833cb2c6da5d | 87 | |
x1dmoesc | 0:833cb2c6da5d | 88 | |
x1dmoesc | 0:833cb2c6da5d | 89 | |
x1dmoesc | 0:833cb2c6da5d | 90 | |
x1dmoesc | 0:833cb2c6da5d | 91 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 92 | // |
x1dmoesc | 0:833cb2c6da5d | 93 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 94 | bool SC18IS602::configGPIO(uint8_t uiConf){ // |
x1dmoesc | 0:833cb2c6da5d | 95 | // |
x1dmoesc | 0:833cb2c6da5d | 96 | cCmd[0] = ADR_GPIO_CONF; // |
x1dmoesc | 0:833cb2c6da5d | 97 | cCmd[1] = uiConf; // clear reserved bits 0b0000'1111 |
x1dmoesc | 0:833cb2c6da5d | 98 | return sendViaI2C(cCmd, 2); // |
x1dmoesc | 0:833cb2c6da5d | 99 | } |
x1dmoesc | 0:833cb2c6da5d | 100 | |
x1dmoesc | 0:833cb2c6da5d | 101 | |
x1dmoesc | 0:833cb2c6da5d | 102 | |
x1dmoesc | 0:833cb2c6da5d | 103 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 104 | // sends via I2C and returns ACK or NACK |
x1dmoesc | 0:833cb2c6da5d | 105 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 106 | bool SC18IS602::sendViaI2C(const char *cData, int iLength, string sDebug) |
x1dmoesc | 0:833cb2c6da5d | 107 | { |
x1dmoesc | 0:833cb2c6da5d | 108 | bAck = (bool) i2c->write(SC18IS602_W, cData, iLength); |
x1dmoesc | 0:833cb2c6da5d | 109 | |
x1dmoesc | 0:833cb2c6da5d | 110 | if (bAck == ACK) { |
x1dmoesc | 0:833cb2c6da5d | 111 | return ACK; |
x1dmoesc | 0:833cb2c6da5d | 112 | |
x1dmoesc | 0:833cb2c6da5d | 113 | } else { |
x1dmoesc | 0:833cb2c6da5d | 114 | if(sizeof(sDebug) != NULL) printf("%s:%*s", sDebug.c_str(), 10, " "); |
x1dmoesc | 0:833cb2c6da5d | 115 | printf("NACK\n"); |
x1dmoesc | 0:833cb2c6da5d | 116 | return NACK; |
x1dmoesc | 0:833cb2c6da5d | 117 | } |
x1dmoesc | 0:833cb2c6da5d | 118 | } |
x1dmoesc | 0:833cb2c6da5d | 119 | |
x1dmoesc | 0:833cb2c6da5d | 120 | |
x1dmoesc | 0:833cb2c6da5d | 121 | |
x1dmoesc | 0:833cb2c6da5d | 122 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 123 | // sends via I2C and returns ACK or NACK |
x1dmoesc | 0:833cb2c6da5d | 124 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 125 | bool SC18IS602::readViaI2C(char *cData, int iLength, string sDebug){ |
x1dmoesc | 0:833cb2c6da5d | 126 | |
x1dmoesc | 0:833cb2c6da5d | 127 | bAck = (bool) i2c->read(SC18IS602_R, cData, iLength); |
x1dmoesc | 0:833cb2c6da5d | 128 | |
x1dmoesc | 0:833cb2c6da5d | 129 | if (bAck == ACK) { |
x1dmoesc | 0:833cb2c6da5d | 130 | return ACK; |
x1dmoesc | 0:833cb2c6da5d | 131 | |
x1dmoesc | 0:833cb2c6da5d | 132 | } else { |
x1dmoesc | 0:833cb2c6da5d | 133 | if(sizeof(sDebug) != NULL) printf("%s:%*s", sDebug.c_str(), 10, " "); |
x1dmoesc | 0:833cb2c6da5d | 134 | printf("NACK\n"); |
x1dmoesc | 0:833cb2c6da5d | 135 | return NACK; |
x1dmoesc | 0:833cb2c6da5d | 136 | } |
x1dmoesc | 0:833cb2c6da5d | 137 | } |
x1dmoesc | 0:833cb2c6da5d | 138 | |
x1dmoesc | 0:833cb2c6da5d | 139 | |
x1dmoesc | 0:833cb2c6da5d | 140 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 141 | // get interrupt status |
x1dmoesc | 0:833cb2c6da5d | 142 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 143 | bool SC18IS602::getInt(){ |
x1dmoesc | 0:833cb2c6da5d | 144 | //printf("Wait for Int...\n"); |
x1dmoesc | 0:833cb2c6da5d | 145 | //wait(0.1); |
x1dmoesc | 1:2a7edc2be6df | 146 | if(iINT == 0){ |
x1dmoesc | 1:2a7edc2be6df | 147 | return INTERRUPT; |
x1dmoesc | 1:2a7edc2be6df | 148 | //if(getInt_ptr != NULL) return (*getInt_ptr)();// musst be modified |
x1dmoesc | 1:2a7edc2be6df | 149 | } |
x1dmoesc | 0:833cb2c6da5d | 150 | if(iINT == 1) return pca->getGPIO1_B7(true); |
x1dmoesc | 0:833cb2c6da5d | 151 | if(iINT == 2) return IntPin->read(); |
x1dmoesc | 0:833cb2c6da5d | 152 | |
x1dmoesc | 0:833cb2c6da5d | 153 | return not INTERRUPT; |
x1dmoesc | 0:833cb2c6da5d | 154 | } |
x1dmoesc | 0:833cb2c6da5d | 155 | |
x1dmoesc | 0:833cb2c6da5d | 156 | |
x1dmoesc | 0:833cb2c6da5d | 157 | |
x1dmoesc | 0:833cb2c6da5d | 158 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 159 | // clears the interrupt pin |
x1dmoesc | 0:833cb2c6da5d | 160 | // returns 0(ACK) on success otherwise 1 (NACK) |
x1dmoesc | 0:833cb2c6da5d | 161 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 162 | bool SC18IS602::clearInt(){ |
x1dmoesc | 0:833cb2c6da5d | 163 | cCmd[0] = 0xF1; |
x1dmoesc | 0:833cb2c6da5d | 164 | return sendViaI2C(cCmd, 1, "clear interrupt"); |
x1dmoesc | 0:833cb2c6da5d | 165 | } |
x1dmoesc | 0:833cb2c6da5d | 166 | |
x1dmoesc | 0:833cb2c6da5d | 167 | |
x1dmoesc | 0:833cb2c6da5d | 168 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 169 | // toggle GPIO Pins // |
x1dmoesc | 0:833cb2c6da5d | 170 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 171 | bool SC18IS602::gpio_toggle(uint8_t uiPort){ // |
x1dmoesc | 0:833cb2c6da5d | 172 | |
x1dmoesc | 0:833cb2c6da5d | 173 | uiPort &= 0x0F; // clear reserved bits |
x1dmoesc | 0:833cb2c6da5d | 174 | |
x1dmoesc | 0:833cb2c6da5d | 175 | cCmd[0] = ADR_GPIO_READ; // Read from GPIO port |
x1dmoesc | 0:833cb2c6da5d | 176 | sendViaI2C(cCmd, 1, "Read GPIO"); |
x1dmoesc | 0:833cb2c6da5d | 177 | bAck = (bool) readViaI2C(&cCmd[1], 1); |
x1dmoesc | 0:833cb2c6da5d | 178 | |
x1dmoesc | 0:833cb2c6da5d | 179 | if(bAck == NACK) return bAck; // if NACK, return |
x1dmoesc | 0:833cb2c6da5d | 180 | |
x1dmoesc | 0:833cb2c6da5d | 181 | cCmd[0] = ADR_GPIO_WRITE; |
x1dmoesc | 0:833cb2c6da5d | 182 | cCmd[1] ^= uiPort; // toogle given pins (uiTogllePin) |
x1dmoesc | 0:833cb2c6da5d | 183 | return sendViaI2C(cCmd, 2, "GPIO tog"); |
x1dmoesc | 0:833cb2c6da5d | 184 | |
x1dmoesc | 0:833cb2c6da5d | 185 | } |
x1dmoesc | 0:833cb2c6da5d | 186 | |
x1dmoesc | 0:833cb2c6da5d | 187 | |
x1dmoesc | 0:833cb2c6da5d | 188 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 189 | // swith the GPIO Pin for debugging on |
x1dmoesc | 0:833cb2c6da5d | 190 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 191 | bool SC18IS602::GPIO_pin3_off() |
x1dmoesc | 0:833cb2c6da5d | 192 | { |
x1dmoesc | 0:833cb2c6da5d | 193 | cCmd[0] = ADR_GPIO_WRITE; |
x1dmoesc | 0:833cb2c6da5d | 194 | cCmd[1] = (1 << GPIO_CS3); |
x1dmoesc | 0:833cb2c6da5d | 195 | return sendViaI2C(cCmd, 2, "GPIO off"); |
x1dmoesc | 0:833cb2c6da5d | 196 | } |
x1dmoesc | 0:833cb2c6da5d | 197 | |
x1dmoesc | 0:833cb2c6da5d | 198 | |
x1dmoesc | 0:833cb2c6da5d | 199 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 200 | // swith the GPIO Pin for debugging off |
x1dmoesc | 0:833cb2c6da5d | 201 | /******************************************************************************/ |
x1dmoesc | 0:833cb2c6da5d | 202 | bool SC18IS602::GPIO_pin3_on() |
x1dmoesc | 0:833cb2c6da5d | 203 | { |
x1dmoesc | 0:833cb2c6da5d | 204 | cCmd[0] = ADR_GPIO_WRITE; |
x1dmoesc | 0:833cb2c6da5d | 205 | cCmd[1] = (0 << GPIO_CS3); |
x1dmoesc | 0:833cb2c6da5d | 206 | return sendViaI2C(cCmd, 2, "GPIO on"); |
x1dmoesc | 0:833cb2c6da5d | 207 | } |
x1dmoesc | 0:833cb2c6da5d | 208 | |
x1dmoesc | 0:833cb2c6da5d | 209 | |
x1dmoesc | 0:833cb2c6da5d | 210 | |
x1dmoesc | 0:833cb2c6da5d | 211 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 212 | // |
x1dmoesc | 0:833cb2c6da5d | 213 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 214 | bool SC18IS602::sendViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum) |
x1dmoesc | 0:833cb2c6da5d | 215 | { |
x1dmoesc | 0:833cb2c6da5d | 216 | if((int)uiNum >= BUFFER_SIZE - 1) // If number of sending Bytes greather than BUFFER_SIZE - 1 (Register-Adress-Byte) |
x1dmoesc | 0:833cb2c6da5d | 217 | return NACK; // returns NACK (failure) |
x1dmoesc | 0:833cb2c6da5d | 218 | |
x1dmoesc | 0:833cb2c6da5d | 219 | |
x1dmoesc | 0:833cb2c6da5d | 220 | uiNumByte = 0; |
x1dmoesc | 0:833cb2c6da5d | 221 | cCmd[uiNumByte] = CMD_RW_CS0; // send via SPI and CS0 (SS0) |
x1dmoesc | 0:833cb2c6da5d | 222 | cCmd[++uiNumByte] = cAdrByte; |
x1dmoesc | 0:833cb2c6da5d | 223 | for(int n = uiNum - 1 ; n >= 0; n--) { |
x1dmoesc | 0:833cb2c6da5d | 224 | cCmd[++uiNumByte] = cDataBytes[n]; |
x1dmoesc | 0:833cb2c6da5d | 225 | } |
x1dmoesc | 0:833cb2c6da5d | 226 | |
x1dmoesc | 0:833cb2c6da5d | 227 | |
x1dmoesc | 0:833cb2c6da5d | 228 | uiNumByte++; // char cCmd counts from 0, so the number is +1 |
x1dmoesc | 0:833cb2c6da5d | 229 | bAck = sendViaI2C(cCmd, uiNumByte, "TX via SPI"); // send via SPI |
x1dmoesc | 0:833cb2c6da5d | 230 | |
x1dmoesc | 0:833cb2c6da5d | 231 | |
x1dmoesc | 0:833cb2c6da5d | 232 | while(getInt() == not INTERRUPT); // wait until sending is finished and an interrupt occurs |
x1dmoesc | 0:833cb2c6da5d | 233 | clearInt(); |
x1dmoesc | 0:833cb2c6da5d | 234 | while(getInt() == INTERRUPT); // If there was an interrupt, wait until it is cleared |
x1dmoesc | 0:833cb2c6da5d | 235 | |
x1dmoesc | 0:833cb2c6da5d | 236 | return bAck; |
x1dmoesc | 0:833cb2c6da5d | 237 | } |
x1dmoesc | 0:833cb2c6da5d | 238 | |
x1dmoesc | 0:833cb2c6da5d | 239 | |
x1dmoesc | 0:833cb2c6da5d | 240 | |
x1dmoesc | 0:833cb2c6da5d | 241 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 242 | // returns reading data. The first byte is the status byte |
x1dmoesc | 0:833cb2c6da5d | 243 | //******************************************************************************// |
x1dmoesc | 0:833cb2c6da5d | 244 | bool SC18IS602::readViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum) |
x1dmoesc | 0:833cb2c6da5d | 245 | { |
x1dmoesc | 0:833cb2c6da5d | 246 | if((int)uiNum >= BUFFER_SIZE - 1) // If number of sending Bytes greather than BUFFER_SIZE - 1 (Register-Adress-Byte) |
x1dmoesc | 0:833cb2c6da5d | 247 | return NACK; // returns NACK (failure) |
x1dmoesc | 0:833cb2c6da5d | 248 | |
x1dmoesc | 0:833cb2c6da5d | 249 | |
x1dmoesc | 0:833cb2c6da5d | 250 | // send first time Read comand |
x1dmoesc | 0:833cb2c6da5d | 251 | uiNumByte = 0; |
x1dmoesc | 0:833cb2c6da5d | 252 | cCmd[uiNumByte] = CMD_RW_CS0; // send via SPI and CS0 (SS0) |
x1dmoesc | 0:833cb2c6da5d | 253 | cCmd[++uiNumByte] = cAdrByte; |
x1dmoesc | 0:833cb2c6da5d | 254 | |
x1dmoesc | 0:833cb2c6da5d | 255 | for(int n = uiNum - 1 ; n >= 0; n--) { |
x1dmoesc | 0:833cb2c6da5d | 256 | cCmd[++uiNumByte] = 0x00; |
x1dmoesc | 0:833cb2c6da5d | 257 | } |
x1dmoesc | 0:833cb2c6da5d | 258 | uiNumByte++; // char cCmd counts from 0, so the number is +1 |
x1dmoesc | 0:833cb2c6da5d | 259 | |
x1dmoesc | 0:833cb2c6da5d | 260 | while(getInt() == INTERRUPT); // If there was an interrupt, wait until it is cleared |
x1dmoesc | 0:833cb2c6da5d | 261 | bAck = sendViaI2C(cCmd, uiNumByte, "RX via SPI"); |
x1dmoesc | 0:833cb2c6da5d | 262 | while(getInt() == not INTERRUPT); |
x1dmoesc | 0:833cb2c6da5d | 263 | clearInt(); |
x1dmoesc | 0:833cb2c6da5d | 264 | |
x1dmoesc | 0:833cb2c6da5d | 265 | |
x1dmoesc | 0:833cb2c6da5d | 266 | // send secound time read comand (dummy) to receive data from first read command |
x1dmoesc | 0:833cb2c6da5d | 267 | uiNumByte = 0; |
x1dmoesc | 0:833cb2c6da5d | 268 | cCmd[uiNumByte++] = CMD_RW_CS0; |
x1dmoesc | 0:833cb2c6da5d | 269 | for(int n = uiNum - 1 ; n >= 0; n--) { |
x1dmoesc | 0:833cb2c6da5d | 270 | cCmd[uiNumByte++] = 0x00; |
x1dmoesc | 0:833cb2c6da5d | 271 | } |
x1dmoesc | 0:833cb2c6da5d | 272 | |
x1dmoesc | 0:833cb2c6da5d | 273 | while(getInt() == INTERRUPT); // If there was an interrupt, wait until it is cleared |
x1dmoesc | 0:833cb2c6da5d | 274 | bAck = sendViaI2C(cCmd, uiNumByte, "RX via SPI"); |
x1dmoesc | 0:833cb2c6da5d | 275 | while(getInt() == not INTERRUPT); // wait until sending is finished and an interrupt occurs |
x1dmoesc | 0:833cb2c6da5d | 276 | clearInt(); |
x1dmoesc | 0:833cb2c6da5d | 277 | |
x1dmoesc | 0:833cb2c6da5d | 278 | |
x1dmoesc | 0:833cb2c6da5d | 279 | bAck = (bool) readViaI2C(cDataBytes, uiNumByte); |
x1dmoesc | 0:833cb2c6da5d | 280 | |
x1dmoesc | 0:833cb2c6da5d | 281 | int n = 0; |
x1dmoesc | 0:833cb2c6da5d | 282 | for(int i = 0; i < int(uiNumByte/2); i++){ |
x1dmoesc | 0:833cb2c6da5d | 283 | n = uiNumByte - 1 - i; |
x1dmoesc | 0:833cb2c6da5d | 284 | //printf("%d <-> %d\n", i, n); |
x1dmoesc | 0:833cb2c6da5d | 285 | cDataBytes[i] = cDataBytes[i] ^ cDataBytes[n]; |
x1dmoesc | 0:833cb2c6da5d | 286 | cDataBytes[n] = cDataBytes[i] ^ cDataBytes[n]; |
x1dmoesc | 0:833cb2c6da5d | 287 | cDataBytes[i] = cDataBytes[i] ^ cDataBytes[n]; |
x1dmoesc | 0:833cb2c6da5d | 288 | } |
x1dmoesc | 0:833cb2c6da5d | 289 | |
x1dmoesc | 0:833cb2c6da5d | 290 | return bAck; |
x1dmoesc | 0:833cb2c6da5d | 291 | } |
x1dmoesc | 0:833cb2c6da5d | 292 | |
x1dmoesc | 0:833cb2c6da5d | 293 | |
x1dmoesc | 1:2a7edc2be6df | 294 | |
x1dmoesc | 1:2a7edc2be6df | 295 | |
x1dmoesc | 1:2a7edc2be6df | 296 | //******************************************************************************// |
x1dmoesc | 1:2a7edc2be6df | 297 | // musst modified |
x1dmoesc | 1:2a7edc2be6df | 298 | //******************************************************************************// |
x1dmoesc | 1:2a7edc2be6df | 299 | /*void SC18IS602::setIntFuncPtr( bool (*Int_ptr)(void)){ |
x1dmoesc | 1:2a7edc2be6df | 300 | getInt_ptr = Int_ptr; |
x1dmoesc | 1:2a7edc2be6df | 301 | |
x1dmoesc | 1:2a7edc2be6df | 302 | }*/ |