cancel
Showing results for 
Search instead for 
Did you mean: 

I2C & SPI not working together (STM32F303K8)

Linkpad
Associate III

Hi, I am trying to simply output information from an I2C device (DS1307 real time clock) to an SPI screen (ST7789) I have tested the code & libraries for the separate devices and they work but as soon as I try adding any SPI commands to the main.c the output just crashes (simple UART message) as below:-

"DS1307_Init(&hi2c1);
/* To test leap year correction. */
DS1307_SetTimeZone(+8, 00);
DS1307_SetDate(12);
DS1307_SetMonth(7);
DS1307_SetYear(2023);
DS1307_SetDayOfWeek(4);
DS1307_SetHour(9);
DS1307_SetMinute(00);
DS1307_SetSecond(00);
const char *DAYS_OF_WEEK[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
HAL_UART_Transmit(&huart2, "DS1307 innit", sizeof"DS1307 innit", 1000);
HAL_Delay(200);
ST7789_Init();
HAL_UART_Transmit(&huart2, "ST7789 innit", sizeof"ST7789 innit", 1000);
"

As soon as i add the 'ST7789_Init();' command everything seizes to work and all I get on the UART monitor is "DS1307 innit" not the "ST7789 innit". I have tried all the different SPI & I2C settings disabling and enabling interrupts and no luck. Is there an SPI setting which can conflict with I2C? 

 

 

5 REPLIES 5
Foued_KH
ST Employee

Hello @Linkpad

I think there isn't an SPI setting which can conflict with I2C.
You need to debug you code to catch the issue source.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

raptorhal2
Lead

Any chance the SPI uses the same pins as USART2 ?

 

######
Senior

As @raptorhal2 mentioned, the likelihood is a pin definition clash. 

According to Datasheet DS9866 Page 39:

PA14 can be either alternate function I2C1_SDA or USART2_TX as well as PA15 being I2C1_SCL, SPI1_NSS and USART2_RX.

PB3 and PB4 also has a similar clash between SPI1 and USART2.

What are your pin definitions?

Foued_KH
ST Employee

Hi @Linkpad , 

Could you please share your .ioc file ?

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Linkpad
Associate III

Hi Foued,

Not too worry the only way I have managed to get the I2C to work currently is by using both SPI & I2C in DMA mode I am guessing there needs to be either interrupts, DMA or RTOS when there are several devices talking to each other simultaneously such as I2C & SPI? I think the trouble is most of the examples I have seen just seem to show either SPI TFT screen code or I2C code and not a combination...