Leetut
21
// Set up everything to be ready
const uint8_t sda_mask = (1 << PIND7); // Pin11 (was D5 Pin9)
const uint8_t clk_mask = (1 << PINB0); // Pin12 (was D6 Pin10)
uint8_t prev_clk = clk_mask;
DDRB &= ~(clk_mask); // clk pin as input
DDRD &= ~(sda_mask); // sda pin as input
PORTD &= ~(sda_mask); // SDA pin is pulled low or floated up
// -> we need to set pin low only once.
// Toggling is done by setting pin to
// input (let float high) or output (pull low).
// FV-1 internal pullups are ok (tested).
uint16_t pos = 0;
uint8_t curr_byte = algo_buffer[pos];
uint8_t bit_mask = 0b10000000;
uint8_t clk_count = 0;
// Undivided attention for FV-1 requests
noInterrupts();
// Notify FV-1 of patch change by toggling the notify pin
PIND = _BV(4); // Toggle pin 4
while (clk_count < 37) // Handle the header
{
uint8_t clk = PIND & clk_mask;
if (!clk && prev_clk) { // scl went down
switch (clk_count)
{
case 8:
case 17:
case 26:
case 36:
DDRD |= sda_mask; // send ACK - pull sda pin low
break;
default:
DDRD &= ~(sda_mask); // Release
break;
}
clk_count++;
}
prev_clk = clk;
}
////Still Freezes Here////