SPI_Mode3 causing SPI multiple device errors when using u8glib Library


I'm using an Arduino UNO with the DS3234 Real Time Clock using the Sparkfun Library and a SH1106 OLED display using the u8glib library, the RTC and OLED display both use the SPI bus of course with separate CS pins.

When I run my program which simply reads the RTC and displays the time on both the hyper terminal and on the OLED display I firstly just get a mess of numbers on the hyper-terminal like "45/25/165/18:85:85" instead of 27/08/14 19:15:05 and secondly the OLED display does not show anything.

It turns out that the RTC library obtained on Sparkfun sets the SPI-MODE to 3 which works as per normal when the OLED is not connected, but when the u8glib SH1106 driver sends the SPI commands to the display it causes the SPI_Mode to reset to the default which from that point onwards makes communicating to the RTC impossiable.

Is there a good work around for this in software as the hardware cannot be change to use SW SPI ?.

Extra info:

u8glib constructor used: U8GLIB_SH1106_128X64_2X u8g(10, 7, 5); //CS = 10, a0 = 7, RESET = 5

U8glib has an option to store and restore the state of the HW SPI registers. Have a look at this:
In some cases this may help...

Please also check whether U8glib works with SW SPI together with your RTC (with HW SPI).