I am trying use an OLED display with an atmega328p. The OLED uses an 8 pin data interface. Therefore I need to switch several pins between input and output and vice versa. If I switch one pin everything is fine but if I switch 2 or more than the controller seems to trap. I just have an STK500 clone and cannot debug the code on the controller. I toggle a LED on a separate pin to see that the controller is still running. In the user manual there is a section where it is mentioned that one must ensure that the input and the output state must fit to ensure that the pin is not in an undefined state. But it is not mentioned that this will result in a trap. Nevertheless I ensured that the pins are in the correct state before I switch them. Even if I switch a pin from output to input and back several times the controller traps. I do not use the arduino environment. The compiler I use is the avr-gcc on linux. For programming the avrdude is in use.
I've tried it with the pins connected to the OLED and not connected. It does not make a difference. I also tried it with a little delay of 1ms between the switching. That also does not make a difference
Thanks for your help.