2022-06-16 10:58 PM
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 */
}
Solved! Go to Solution.
2022-06-17 01:01 AM
The problem is probably in Read_i2c() or SPIMod_Set_Out_Value_uA().
JW
2022-06-17 01:01 AM
The problem is probably in Read_i2c() or SPIMod_Set_Out_Value_uA().
JW
2022-06-17 01:13 AM
Have you used an oscilloscope or analyser to see what's actually happening on the wires?
2022-06-19 11:43 PM
I found the problem. There was some initialization issue on my side.
Thanks for solution suggestions.
2022-06-20 01:44 AM
@uartist "I found the problem"
thanks for feeding back - now please mark the solution: