我正在尝试从A1和A2获得电压值。正如我们看到的那样,我们必须从数据寄存器获取值,这就是为什么第一个寄存器地址为0x5C进行连续转换的原因。那么代码中的错误是什么?
#define SlaveDis HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_RESET)
#define SlaveEnable HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_SET)
uint8_t SPITx = 0x5C;
uint8_t SPIRx [3];
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
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_SPI1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
SlaveDis;
HAL_SPI_Transmit(&hspi1,&SPITx,1,5000);
SlaveEnable;
HAL_SPI_Receive_IT(&hspi1,SPIRx,3);
}
/* USER CODE END 3 */
}