--- Quote Start ---
I have also tried to replace
"if clkin'event and clkin='1' then "
by
"if rising_edge(clkin)"
--- Quote End ---
These are just synonyms.
--- Quote Start ---
I can not follow the value of bit_number anymore
--- Quote End ---
Variables are not accessible by the simulator. Although the compiler is generating registered signals for variables in some cases, signals should be used for data that is intended to keep it's value between clock cycles.
Some details of your code are too complicated in my opinion and can be replaced by more simple code. E.g.
sdio<=frame(bit_number);
can be replaced by a shift operation
But your multplexer way should work as well.