stm8s I2C Communication
Interrupts are needed in your master and slave code to sync transmission and reception; your while loops wont cut it since there is no guarantee that they are both executing the proper bits of code simultaneously. You need to look at the I2C example code here on I2C data exchange between 2 STMs.