MCP23017 with NODEMCU v3 (lolin) i2c doesn't work
Where I made mistake?


I could not find any mistakes in your port of MAX6675 library to MCP23017 channel, except for questionable replacement of _delay_ms() calls.

The missing pull-ups on the I2C lines could affect the operation of MCP23017 in unpredictable way. I'd expect it not be functional at all, but it might be possible that communication works one way only, i.e. NodeMCU is able to send commands to MCP (so the LED blinking test works) but cannot read slave responses properly (so the data from MAX gets corrupted).

Where you really made a mistake, is in trying to bit-bang SPI using I2C port extender. My original estimate was incorrect. After analyzing MCP23017 library I see that it takes 8(!) I2C commands to send 1 bit. i.e. your communication is 32 times slower than it could be.

If you need more than one SPI device you can put them all on same CLK/MISO pins and use MCP23017 to switch /CS pins only. Or, even better, use SPI multiplexor (like ADG731) on the same bus to switch /CS pins.