cancel
Showing results for 
Search instead for 
Did you mean: 

I2C interfacing not working while using SPI.

uartist
Associate II

Hello.

I have been working on a project where the I2C based sensor I have chosen works by itself. When I enable a SPI based module, the I2C sensor does not seem to send any data.

The I2C lines don't even have any conflicts with other pins.

I have included this main code used during testing.

int main(void)
{
  /* USER CODE BEGIN 1 */
	int i2c, test;
	char out[70] = {"\0"};
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
  MX_LPUART1_UART_Init();
  MX_SPI1_Init();
  MX_ADC_Init();
  /* USER CODE BEGIN 2 */
 
 
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, 1);
  sprintf(out, "This is an ADC Test\r\n");
  HAL_UART_Transmit(&hlpuart1, (uint8_t*)out, sizeof(out), 200);
  HAL_Delay(2000);
  SPIMod_Reset();
 
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
	    sprintf(out, "I2C Reading: %d, Test O/P: %d\n", i2c, test);
	    HAL_UART_Transmit(&hlpuart1, (uint8_t*)out, sizeof(out), 100);
	    i2c = Read_i2c();
	    test = interpolate_func(i2c);
 
	     if(DAC_out <= UnderRange)
	     {
	       SPIMod_Set_Out_Value_uA(4000);
	     }
	  
	     else if(DAC_out >= OverRange)
	     {
	       SPIMod_Set_Out_Value_uA(20000);
	     }
	  
	     else
	     {
	       SPIMod_Set_Out_Value_uA(DAC_out);
	     }
 
	     HAL_Delay(150);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

1 ACCEPTED SOLUTION

Accepted Solutions

The problem is probably in Read_i2c() or SPIMod_Set_Out_Value_uA().

JW

View solution in original post

4 REPLIES 4

The problem is probably in Read_i2c() or SPIMod_Set_Out_Value_uA().

JW

Have you used an oscilloscope or analyser to see what's actually happening on the wires?

uartist
Associate II

I found the problem. There was some initialization issue on my side.

Thanks for solution suggestions.

@uartist​ "I found the problem"

thanks for feeding back - now please mark the solution:

0693W000008y9fZQAQ.png