diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 2fee678..1716548 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -204,9 +204,9 @@ void MX_FREERTOS_Init(void) usart6_test_taskHandle = osThreadCreate(osThread(usart6_test_task), NULL); /* TCA6416任务 */ - //osThreadDef(tca6416_task, start_tca6416_task, osPriorityNormal, 0, 128); - // tca6416_taskHandle = osThreadCreate(osThread(tca6416_task), NULL); - /* TCA6416测试任务 */ + osThreadDef(tca6416_task, test_tca6416_task, osPriorityNormal, 0, 128); + tca6416_taskHandle = osThreadCreate(osThread(tca6416_task), NULL); + /* DAC161S997测试任务 */ diff --git a/User/driver/ad7124.c b/User/driver/ad7124.c index 219d0ad..970374e 100644 --- a/User/driver/ad7124.c +++ b/User/driver/ad7124.c @@ -415,10 +415,10 @@ int32_t ad7124_setup(void) int32_t ad7124_read_write_spi(uint8_t *buff, uint8_t length) { int32_t ret; - uint8_t rx_buff[8] = {0}; // Add receive buffer - board_spi_init(AD7124); // 初始化SPI,因为DAC161的SPI要和AD7124共用,并且时序不一样,所以要先初始化SPI接口。 + board_spi_init(AD7124); board_spi_cs_on(AD7124); - ret = spi_transmit_receive(&hspi1, buff, rx_buff, length); + ret = AD7124_OUT_spi_transmit_receive(buff, length); board_spi_cs_off(AD7124); return ret; } + diff --git a/User/system/user_spi.c b/User/system/user_spi.c index 6577b91..05a0750 100644 --- a/User/system/user_spi.c +++ b/User/system/user_spi.c @@ -20,9 +20,10 @@ typedef volatile uint32_t __IO; #define SUCCESS 0 #define FAILURE -1 +#define SPI_BUFFER_SIZE 255 // 定义SPI缓冲区 static uint8_t spi_rx_buffer[256]; // 接收缓冲区 - +static uint8_t ad7124_spi_rx_buffer[SPI_BUFFER_SIZE] = {0}; // SPI句柄声明 extern SPI_HandleTypeDef hspi1; // 在spi.c中定义 extern SPI_HandleTypeDef hspi2; // 在main.c中定义 @@ -58,7 +59,7 @@ extern SPI_HandleTypeDef hspi3; // 在main.c中定义 /***************************** #defines ***************************************/ /******************************************************************************/ -#define SPI_BUFFER_SIZE 255 + /******************************************************************************/ @@ -71,6 +72,20 @@ extern SPI_HandleTypeDef hspi1; // 在spi.c中定义 /******************************************************************************/ /************************ Functions Definitions *******************************/ /******************************************************************************/ +//AD7124重要通信函数 +int32_t AD7124_OUT_spi_transmit_receive(uint8_t *data_write, uint8_t bytes_number) +{ + // 使用 HAL_SPI_TransmitReceive 函数进行 SPI 通信 + if (HAL_SPI_TransmitReceive(&hspi2, data_write, (uint8_t *)ad7124_spi_rx_buffer, bytes_number, 1000) != HAL_OK) + { + // 如果通信失败,返回 FAILURE + return FAILURE; + } + /* 将 SPI 接收缓冲区复制到提供的数据缓冲区,以便返回给调用者 */ + memcpy(data_write, ad7124_spi_rx_buffer, bytes_number); + // 返回 SUCCESS 表示通信成功 + return SUCCESS; +} int32_t spi_transmit_receive(SPI_HandleTypeDef *hspi, uint8_t *data_write, uint8_t *data_read, uint8_t bytes_number) { diff --git a/User/system/user_spi.h b/User/system/user_spi.h index 597b76d..4982741 100644 --- a/User/system/user_spi.h +++ b/User/system/user_spi.h @@ -13,6 +13,7 @@ typedef enum } chip_type_e; // 芯片类型 extern int32_t spi_transmit_receive(SPI_HandleTypeDef *hspi, uint8_t *data_write, uint8_t *data_read, uint8_t bytes_number); +extern int32_t AD7124_OUT_spi_transmit_receive(uint8_t *data_write, uint8_t bytes_number); extern SPI_HandleTypeDef hspi1; extern SPI_HandleTypeDef hspi2; extern SPI_HandleTypeDef hspi3;