uint8_t master_HandShake(uint8_t sci_x){ state_x_Send = false; state_x_PowerUp = false; while (!timeout && !Sci_Ready()){} if (!timeout){ read_SPI (hand_Shake_Send); if (g_RXData != hand_Shake_Rec){ // handshake fail LED(1,1,1,5,1); // Handshake fail (BLUE GREEN RED) hand_Shake_FAIL[(m + 9)] = g_RXData; m++; state_x_PowerUp = true; } } if (m > 20) // Try three times and move on to science board 2 if no handshake { state_x_Send = true; for (o = 9; o < 29; o++){ write_Buffer(hand_Shake_FAIL[o]); } } if (timeout){return 1;} else return 0; }
uint8_t SCI_Read(void){ while(Sci_Ready() && !timeout){ // Waits for GPIO to go high read_SPI (0xAA); write_Buffer(g_RXData); i++; } g_RXData = 0; // Clear variable for next science board. i = 0; if (timeout){return 1;} else return 0; }
int getData(char port) { unsigned char d[2]; char t = 0; *d = 0x0000; PEOUT ^= 0x80; send_SPI(port); // Channel 3 - vRef t=100; while(--t); // Delay >5us read_SPI(&d); PEOUT = 0xFF; return (int)*d; }
void test_SPI() { char t = 0; unsigned char d[2]; d[0] = 0x00; d[1] = 0x00; PEOUT ^= 0x80; send_SPI(0x1A); // Channel 3 - vRef waitForFullBuf(); //t=0xFF; while(--t); // Delay >5us read_SPI(&d); writeData(d[0], d[1], d[0]); PEOUT = 0xFF; }