stabilize comms timing

This commit is contained in:
Morgan Redfield 2019-09-07 19:40:22 -07:00
parent 777a56d131
commit aa14035c94
1 changed files with 8 additions and 0 deletions

View File

@ -69,16 +69,20 @@ int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data)
temp = ((regAddr & (0x80 >> i)) != 0); temp = ((regAddr & (0x80 >> i)) != 0);
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
digitalWrite(dat_pin, temp); digitalWrite(dat_pin, temp);
HSdelayMicroseconds(1);
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); // digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
HSdelayMicroseconds(1);
} }
// change direction of dat_pin // change direction of dat_pin
pinMode(dat_pin, INPUT); // DDRC &= ~(1<<4); // pinMode(dat_pin, INPUT); // DDRC &= ~(1<<4); //
for (int i = 15; i >= 0; i--) { for (int i = 15; i >= 0; i--) {
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
HSdelayMicroseconds(1);
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); // digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
temp_dat = digitalRead(dat_pin); //((PINC & (1<<4)) != 0); temp_dat = digitalRead(dat_pin); //((PINC & (1<<4)) != 0);
temp_dat = temp_dat << i; temp_dat = temp_dat << i;
*data |= temp_dat; *data |= temp_dat;
HSdelayMicroseconds(1);
} }
digitalWrite(devAddr, 1); //PORTC |= (1<<1);// CS digitalWrite(devAddr, 1); //PORTC |= (1<<1);// CS
@ -127,13 +131,17 @@ bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data)
temp_reg = ((regAddr & (0x80 >> i)) != 0); temp_reg = ((regAddr & (0x80 >> i)) != 0);
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
digitalWrite(dat_pin, regAddr & (0x80 >> i)); digitalWrite(dat_pin, regAddr & (0x80 >> i));
HSdelayMicroseconds(1);
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); // digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
HSdelayMicroseconds(1);
} }
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {
temp_dat = ((data & (0x8000 >> i)) != 0); temp_dat = ((data & (0x8000 >> i)) != 0);
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
digitalWrite(dat_pin, temp_dat); digitalWrite(dat_pin, temp_dat);
HSdelayMicroseconds(1);
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); // digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
HSdelayMicroseconds(1);
} }
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS