Solved
I2C interfacing not working while using SPI.
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 */
}