Test Code with USB Serial / RTC / Pressure
//  Defines ---------------------------------------------------------------------------------------
//#define LCDTEST
#define CLOCK_TEST
#define DIGOUT
#define BMPTEST
#define USBTEST
//  Include ---------------------------------------------------------------------------------------
#include    "mbed.h"
#ifdef CLOCK_TEST
#include    "DS3231.h"
#endif
#ifdef LCDTEST
#include    "ST7565_SPI_LCD.h"
#endif
//#include    "_24LCXXX.h"
#ifdef BMPTEST
#include    "BMP180.h"
#endif
//#include    "Arial28x28.h"
#ifdef USBTEST
#include     "USBSerial.h"
#endif
//  Definition ------------------------------------------------------------------------------------
float delayTime = .01;
//I2C i2c(P0_5, P0_4);            // sda, scl
//  Object ----------------------------------------------------------------------------------------
    // LED
#ifdef DIGOUT
        DigitalOut  myled0(P0_23);
        DigitalOut  myled1(P0_17);
        DigitalOut  myled2(P1_19);
        DigitalOut  myled3(P0_20);
        DigitalOut  myled4(P0_2);
        DigitalOut  myled5(P0_8);
        DigitalOut  myled6(P0_7);
#endif
    // LCD
#ifdef LCDTEST
        ST7565      lcd(P0_21,P1_15,P0_10,P0_15,P0_9, ST7565::AD12864SPI); // mosi, sck, reset, a0, ncs
#endif
    // RTC Chip
#ifdef CLOCK_TEST
        DS3231      rtc(P0_5, P0_4);
#endif
    // BMP180 Sensor
#ifdef BMPTEST
        BMP180      bmp(P0_5, P0_4);
#endif
    // Internal USB Interface
#ifdef USBTEST
        USBSerial pc(USBTX, USBRX); // tx, rx
#endif
//  RAM -------------------------------------------------------------------------------------------
//  ROM / Constant data ---------------------------------------------------------------------------
    // EEPROM on DS3231 Board
    //    _24LCXXX eeprom(&i2c, 0x57);
//  Function prototypes ---------------------------------------------------------------------------
#ifdef CLOCK_TEST
void drawDigitalTime(void);
#endif
//  Main Program
int main() {
#ifdef DIGOUT
    myled0 = 0;
    myled1 = 1;
    myled2 = 0;
    myled3 = 1;
    myled4 = 0;
    myled5 = 1;
    myled6 = 0;
#endif
#ifdef LCDTEST
    lcd.cls();
    lcd.set_contrast(0x14);
    lcd.printf("Dan Brown / LM6059B\r\n" );
    lcd.printf("ABCDEFG 1234567890\r\n" );
    lcd.printf("W:%d  H:%d\r\n", lcd.width(), lcd.height());
#endif
    long temp = 1;
    long pressure = 2;
    int error = 0;
    while(1) {
#ifdef BMPTEST
        error = bmp.readTP(&temp,&pressure,OVERSAMPLING_ULTRA_HIGH_RESOLUTION);
#endif
#ifdef CLOCK_TEST
        drawDigitalTime();
#endif
#ifdef USBTEST
        pc.printf("Temp is %ld\r\n",temp);
        pc.printf("Pressure is %ld\r\n",pressure);
        pc.printf("Error is %d\r\n\r\n",error);
        wait(2);
#endif
#ifdef DIGOUT
        myled0 = 1;
        wait(delayTime);
        myled0 = 0;
        myled1 = 1;
        wait(delayTime);
        myled1 = 0;
        myled2 = 1;
        wait(delayTime);
        myled2 = 0;
        myled3 = 1;
        wait(delayTime);
        myled3 = 0;
        myled4 = 1;
        wait(delayTime);
        myled4 = 0;
        myled5 = 1;
        wait(delayTime);
        myled5 = 0;
        myled6 = 1;
        wait(delayTime);
        myled6 = 0;
#endif
    }
}
#ifdef CLOCK_TEST
void drawDigitalTime()
{
    //SetTime(); // Call only once to set date and time on DS3231
    int date, month, year, hour, minute, second, dayOfWeek;
    rtc.readDateTime(&dayOfWeek,&date,&month,&year,&hour,&minute,&second);
    year=year+100;
    
//    lcd.set_font((unsigned char*) Arial28x28);  // select the font
#ifdef LCDTEST
    if (date > 0) {
        lcd.locate(0,36);
        lcd.printf("%02i.%02i.%i  ",date,month,year);
        lcd.locate(64,36);
        lcd.printf("%02i:%02d\r\n",hour,minute);
    } else {
        lcd.locate(0,0);
        lcd.printf("Error read RTC\r\n");
    }
#endif
#ifdef USBTEST
    if (date > 0) {
        pc.printf("%02i.%02i.%i  ",date,month,year);
        pc.printf("%02i:%02d\r\n",hour,minute);
    } else {
        pc.printf("Error read RTC");
    }
#endif
}
#endif
 
                    
                
Hello all!
I am trying to use the I2C and SPI interfaces at the same time. This isn't working well for me.
If I use one or the other everything is fine. But use both and lockup.