Direct Port Manipulation Pins

  // 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////

I’m freezing alone in the darkness

what would Jesus do

My dodgy code brings all the boys to the yard

Bumping threads is discouraged here.

Current situation on planet freeze..

const uint8_t PC_NOTIFY_PIN = 4; // (Notify FV1 s0)
const uint8_t I2C_EEPROM_EMUL_SDA_PIN = 7; // (FV1 SDA) Was Pin 5
const uint8_t I2C_EEPROM_EMUL_SCL_PIN = 8; // (FV1 SCL) Was Pin 6
void setup()
{
  // 24LC32 EEPROM emulation
  pinMode(PC_NOTIFY_PIN, OUTPUT);
  pinMode(I2C_EEPROM_EMUL_SDA_PIN, INPUT);
  pinMode(I2C_EEPROM_EMUL_SCL_PIN, INPUT);
void send_algo()
{
  // Copy FV-1 algorithm from PROGMEM to ram buffer.
  // Progmem is too slow in the send loop.
  // Since we will anyway have to copy from PROGMEM,
  // it makes sense to compress the algorithms and get
  // space savings (almost 2x).

  uint8_t algo = patch_data[current_patch].algorithm;
  decompress(algo_buffer, (prog_uchar *)pgm_read_word(&(algodata[algo].prog_addr)));

  // Set up everything to be ready
  const uint8_t sda_mask = (1 << PIND7); // Pin7 (was D5)
  const uint8_t clk_mask = (1 << PINB0); // Pin8 (was D6)
  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 = PINB & 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;
  }
  
  ////Freezes Here////
  
  //// Blue Test Led //// Blue Test Led //// Blue Test Led ////
  pixels.begin();
  pixels.setPixelColor(0, 0, 0, 50); // BLUE
  pixels.show(); 
  //// Blue Test Led //// Blue Test Led //// Blue Test Led ////
  
  clk_count = 0;
  while (pos < 512)                  // Send the data
  {
    uint8_t clk = PINB & clk_mask;

    if (!clk && prev_clk) {          // scl went down

      if (clk_count != 8) {          // Sending byte

        if (curr_byte & bit_mask) {
          DDRD &= ~(sda_mask);       // Send 1 = Let High
        } else {
          DDRD  |= sda_mask;         // Send 0 = Pull Low
        }
        bit_mask >>= 1;
        clk_count++;

      } else {                       // Let reciever ACK

        DDRD &= ~(sda_mask);         // Release
        clk_count = 0;
        bit_mask = 0b10000000;
        pos++;
        curr_byte = algo_buffer[pos];
      }
    }
    prev_clk = clk;
  }

  interrupts();

}

Direct Port Manipulation innit

Forgive you?

Should this be PINB as I’ve changed the clk_mask pin?

uint8_t clk = PIND4 & clk_mask;
didn't work,
PORTB &= ~(clk_mask);
didn't work...

Please stop endlessly bumping your thread.

Enthusiast

This badge is granted for visiting 10 consecutive days. Thanks for sticking with us for over a week!

I've given @Leetut a three day suspension from the forum for unproductive and rude behavior.

@Leetut, unproductive "bumping" is poor forum etiquette, as explained in the "How to get the best out of this forum" document:

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#dont-bump

Please take the time to read that document so that you can understand the appropriate behavior while participating in the Arduino forum.

Upon your return, I hope you will behave in a more respectful manner.
Thanks in advance for your cooperation.