上位机IO查询OK

This commit is contained in:
qiuxin 2025-05-26 17:04:18 +08:00
parent 38a41744b9
commit 123869efc4
8 changed files with 350 additions and 275 deletions

View File

@ -121,12 +121,12 @@ extern "C"
#define EC11_A_GPIO_Port GPIOE #define EC11_A_GPIO_Port GPIOE
#define EC11_B_Pin GPIO_PIN_11 #define EC11_B_Pin GPIO_PIN_11
#define EC11_B_GPIO_Port GPIOE #define EC11_B_GPIO_Port GPIOE
#define LED2_R_Pin GPIO_PIN_12 // #define LED2_R_Pin GPIO_PIN_12
#define LED2_R_GPIO_Port GPIOE // #define LED2_R_GPIO_Port GPIOE
#define LED2_G_Pin GPIO_PIN_13 // #define LED2_G_Pin GPIO_PIN_13
#define LED2_G_GPIO_Port GPIOE // #define LED2_G_GPIO_Port GPIOE
#define LED2_Y_Pin GPIO_PIN_14 // #define LED2_Y_Pin GPIO_PIN_14
#define LED2_Y_GPIO_Port GPIOE // #define LED2_Y_GPIO_Port GPIOE
#define ENCODE_Z_Pin GPIO_PIN_14 #define ENCODE_Z_Pin GPIO_PIN_14
#define ENCODE_Z_GPIO_Port GPIOB #define ENCODE_Z_GPIO_Port GPIOB
#define BLE2_TX_Pin GPIO_PIN_8 #define BLE2_TX_Pin GPIO_PIN_8

View File

@ -94,10 +94,14 @@ volatile uint8_t tca6416_port0_status = 0; // 第一个TCA6416的Port0状态
volatile uint8_t tca6416_port1_status = 0; // 第一个TCA6416的Port1状态 volatile uint8_t tca6416_port1_status = 0; // 第一个TCA6416的Port1状态
volatile uint8_t tca6416_port2_status = 0; // 第二个TCA6416的Port0状态 volatile uint8_t tca6416_port2_status = 0; // 第二个TCA6416的Port0状态
volatile uint8_t tca6416_port3_status = 0; // 第二个TCA6416的Port1状态 volatile uint8_t tca6416_port3_status = 0; // 第二个TCA6416的Port1状态
volatile uint8_t tca6416_port4_status = 0; // 第三个TCA6416的Port0状态
volatile uint8_t tca6416_port5_status = 0; // 第三个TCA6416的Port1状态
// 添加TCA6416测试相关的调试变量 // 添加TCA6416测试相关的调试变量
volatile uint8_t tca6416_test_step = 0; // 当前测试步骤 volatile uint8_t tca6416_test_step = 0; // 当前测试步骤
volatile uint8_t tca6416_init_result = 0xFF; // 初始化结果 volatile uint8_t tca6416_init_result = 0xFF; // 初始化结果
volatile uint8_t tca6416_init2_result = 0xFF; // 第二个芯片初始化结果
volatile uint8_t tca6416_init3_result = 0xFF; // 第三个芯片初始化结果
volatile uint8_t tca6416_write_data = 0; // 写入的数据 volatile uint8_t tca6416_write_data = 0; // 写入的数据
volatile uint8_t tca6416_read_data = 0; // 读取的数据 volatile uint8_t tca6416_read_data = 0; // 读取的数据
volatile uint8_t tca6416_error_count = 0; // 错误计数 volatile uint8_t tca6416_error_count = 0; // 错误计数
@ -574,69 +578,10 @@ void start_usart6_dma_test_task(void const *argument)
} }
/* USER CODE BEGIN Header_start_tca6416_task */
/**
* @brief Function implementing the tca6416_task thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_start_tca6416_task */
void start_tca6416_task(void const *argument)
{
/* USER CODE BEGIN start_tca6416_task */
uint8_t port0_data, port1_data;
// 初始化第一个TCA6416
if(TCA6416_Init() != 0)
{
Error_Handler();
}
// 初始化第二个TCA6416
if(TCA6416_Init2() != 0)
{
Error_Handler();
}
// 设置两个芯片的所有端口为输入
if(TCA6416_SetPortDirection(0, 0xFF) != 0) Error_Handler();
if(TCA6416_SetPortDirection(1, 0xFF) != 0) Error_Handler();
if(TCA6416_SetPortDirection2(0, 0xFF) != 0) Error_Handler();
if(TCA6416_SetPortDirection2(1, 0xFF) != 0) Error_Handler();
for(;;)
{
// 读取第一个芯片的输入状态
if(TCA6416_ReadPort(0, &port0_data) == 0)
{
tca6416_port0_status = port0_data;
}
if(TCA6416_ReadPort(1, &port1_data) == 0)
{
tca6416_port1_status = port1_data;
}
// 读取第二个芯片的输入状态
if(TCA6416_ReadPort2(0, &port0_data) == 0)
{
tca6416_port2_status = port0_data;
}
if(TCA6416_ReadPort2(1, &port1_data) == 0)
{
tca6416_port3_status = port1_data;
}
osDelay(100); // 100ms读取一次
}
/* USER CODE END start_tca6416_task */
}
void test_tca6416_task(void const *argument) void test_tca6416_task(void const *argument)
{ {
/* USER CODE BEGIN test_tca6416_task */ /* USER CODE BEGIN test_tca6416_task */
uint8_t ret = 0; uint8_t ret = 0;
uint8_t test_patterns[] = {0x00, 0xFF, 0xAA, 0x55, 0x0F, 0xF0, 0x5A, 0xA5};
uint8_t pattern_index = 0;
uint8_t addr_scan_result[8] = {0}; // 存储地址扫描结果 uint8_t addr_scan_result[8] = {0}; // 存储地址扫描结果
// 等待系统稳定 // 等待系统稳定
@ -653,7 +598,7 @@ void test_tca6416_task(void const *argument)
osDelay(10); osDelay(10);
} }
// 步骤1: 初始化TCA6416 // 步骤1: 初始化第一个TCA6416芯片
tca6416_test_step = 1; tca6416_test_step = 1;
tca6416_init_result = TCA6416_Init(); tca6416_init_result = TCA6416_Init();
@ -667,141 +612,134 @@ void test_tca6416_task(void const *argument)
} }
} }
// 初始化成功,继续测试 // 步骤2: 初始化第二个TCA6416芯片地址0x21
osDelay(50); tca6416_test_step = 2;
tca6416_init2_result = TCA6416_Init2();
if(tca6416_init2_result != 0)
{
tca6416_error_count++;
// 继续执行,不阻塞
}
// 步骤3: 初始化第三个TCA6416芯片地址0x20第二条总线
tca6416_test_step = 3;
tca6416_init3_result = TCA6416_Init3();
if(tca6416_init3_result != 0)
{
tca6416_error_count++;
// 继续执行,不阻塞
}
// 步骤4: 配置第一个芯片所有IO为输出模式并置高电平
tca6416_test_step = 4;
// 设置Port0和Port1为输出0=输出1=输入)
ret = TCA6416_SetPortDirection(0, 0x00); // Port0全部设为输出
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10);
ret = TCA6416_SetPortDirection(1, 0x00); // Port1全部设为输出
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10);
// 将第一个芯片所有IO置为高电平
ret = TCA6416_WritePort(0, 0xFF);
if(ret == 0) tca6416_port0_status = 0xFF;
osDelay(10);
ret = TCA6416_WritePort(1, 0xFF);
if(ret == 0) tca6416_port1_status = 0xFF;
osDelay(10);
// 步骤5: 配置第二、三个芯片所有IO为输入模式
tca6416_test_step = 5;
// 第二个芯片设为输入
if(tca6416_init2_result == 0)
{
TCA6416_SetPortDirection2(0, 0xFF); // Port0全部设为输入
osDelay(10);
TCA6416_SetPortDirection2(1, 0xFF); // Port1全部设为输入
osDelay(10);
}
// 第三个芯片设为输入
if(tca6416_init3_result == 0)
{
TCA6416_SetPortDirection3(0, 0xFF); // Port0全部设为输入
osDelay(10);
TCA6416_SetPortDirection3(1, 0xFF); // Port1全部设为输入
osDelay(10);
}
// 步骤6: 循环检测所有芯片状态
tca6416_test_step = 6;
for(;;) for(;;)
{ {
// 步骤2: 设置Port0为输出Port1为输入 // 刷新第一个芯片的输出状态
tca6416_test_step = 2; TCA6416_WritePort(0, 0xFF);
tca6416_port0_dir = 0x00; // 0=输出 osDelay(10);
tca6416_port1_dir = 0xFF; // 1=输入 TCA6416_WritePort(1, 0xFF);
ret = TCA6416_SetPortDirection(0, tca6416_port0_dir);
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10); osDelay(10);
ret = TCA6416_SetPortDirection(1, tca6416_port1_dir); // 读取第一个芯片状态
if(ret != 0) if(TCA6416_ReadPort(0, &tca6416_read_data) == 0)
{ {
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10);
// 步骤3: 写入测试模式到Port0
tca6416_test_step = 3;
tca6416_test_pattern = test_patterns[pattern_index];
tca6416_write_data = tca6416_test_pattern;
ret = TCA6416_WritePort(0, tca6416_write_data);
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10);
// 步骤4: 读取Port0的值验证写入
tca6416_test_step = 4;
ret = TCA6416_ReadPort(0, &tca6416_read_data);
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
else
{
// 更新状态变量
tca6416_port0_status = tca6416_read_data; tca6416_port0_status = tca6416_read_data;
} }
osDelay(10); osDelay(10);
// 步骤5: 读取Port1的输入状态 if(TCA6416_ReadPort(1, &tca6416_read_data) == 0)
tca6416_test_step = 5;
ret = TCA6416_ReadPort(1, &tca6416_read_data);
if(ret != 0)
{ {
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
else
{
// 更新状态变量
tca6416_port1_status = tca6416_read_data; tca6416_port1_status = tca6416_read_data;
} }
osDelay(10); osDelay(10);
// 步骤6: 测试单个引脚操作 // 读取第二个芯片状态(如果初始化成功)
tca6416_test_step = 6; if(tca6416_init2_result == 0)
for(uint8_t pin = 0; pin < 8; pin++)
{ {
// 设置单个引脚为高 if(TCA6416_ReadPort2(0, &tca6416_read_data) == 0)
ret = TCA6416_WritePin(0, pin, 1);
if(ret != 0)
{ {
tca6416_error_count++; tca6416_port2_status = tca6416_read_data;
tca6416_i2c_ack_status = ret;
} }
osDelay(5); osDelay(10);
// 读取验证 if(TCA6416_ReadPort2(1, &tca6416_read_data) == 0)
uint8_t pin_state = 0;
ret = TCA6416_ReadPin(0, pin, &pin_state);
if(ret != 0)
{ {
tca6416_error_count++; tca6416_port3_status = tca6416_read_data;
tca6416_i2c_ack_status = ret;
} }
osDelay(5); osDelay(10);
}
// 设置单个引脚为低 // 读取第三个芯片状态(如果初始化成功)
ret = TCA6416_WritePin(0, pin, 0); if(tca6416_init3_result == 0)
if(ret != 0) {
if(TCA6416_ReadPort3(0, &tca6416_read_data) == 0)
{ {
tca6416_error_count++; tca6416_port4_status = tca6416_read_data;
tca6416_i2c_ack_status = ret;
} }
osDelay(5); osDelay(10);
if(TCA6416_ReadPort3(1, &tca6416_read_data) == 0)
{
tca6416_port5_status = tca6416_read_data;
}
osDelay(10);
} }
// 步骤7: 测试极性反转功能 // 总延时1秒后重复
tca6416_test_step = 7; osDelay(800);
ret = TCA6416_SetPortPolarity(0, 0xFF); // 反转所有位
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10);
// 读取并验证极性反转效果
ret = TCA6416_ReadPort(0, &tca6416_read_data);
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10);
// 恢复正常极性
ret = TCA6416_SetPortPolarity(0, 0x00);
if(ret != 0)
{
tca6416_error_count++;
tca6416_i2c_ack_status = ret;
}
osDelay(10);
// 切换到下一个测试模式
pattern_index = (pattern_index + 1) % (sizeof(test_patterns) / sizeof(test_patterns[0]));
// 延时后继续下一轮测试
osDelay(500);
} }
/* USER CODE END test_tca6416_task */ /* USER CODE END test_tca6416_task */
} }

View File

@ -336,32 +336,32 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
} }
} }
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) //void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{ //{
if (GPIO_Pin == EC11_KEY_Pin) // if (GPIO_Pin == EC11_KEY_Pin)
{ // {
if (ec11_data.confirm_key_flag == 0) // if (ec11_data.confirm_key_flag == 0)
{ // {
ec11_data.confirm_key_flag = 1; // ec11_data.confirm_key_flag = 1;
} // }
else if (ec11_data.confirm_key_flag == 1) // else if (ec11_data.confirm_key_flag == 1)
{ // {
ec11_data.confirm_key_flag = 2; // ec11_data.confirm_key_flag = 2;
} // }
else if (ec11_data.confirm_key_flag == 2) // else if (ec11_data.confirm_key_flag == 2)
{ // {
ec11_data.confirm_key_flag = 3; // ec11_data.confirm_key_flag = 3;
} // }
} // }
if (GPIO_Pin == HART2_OCD_Pin) // if (GPIO_Pin == HART2_OCD_Pin)
{ // {
HAL_GPIO_TogglePin(LED2_R_GPIO_Port, LED2_R_Pin); // //HAL_GPIO_TogglePin(LED2_R_GPIO_Port, LED2_R_Pin);
} // }
if (GPIO_Pin == HART1_OCD_Pin) // if (GPIO_Pin == HART1_OCD_Pin)
{ // {
HAL_GPIO_TogglePin(LED2_Y_GPIO_Port, LED2_Y_Pin); // //HAL_GPIO_TogglePin(LED2_Y_GPIO_Port, LED2_Y_Pin);
} // }
} //}
/* USER CODE END 4 */ /* USER CODE END 4 */
/** /**

View File

@ -453,7 +453,7 @@ void ETH_IRQHandler(void)
/* USER CODE END ETH_IRQn 0 */ /* USER CODE END ETH_IRQn 0 */
HAL_ETH_IRQHandler(&heth); HAL_ETH_IRQHandler(&heth);
/* USER CODE BEGIN ETH_IRQn 1 */ /* USER CODE BEGIN ETH_IRQn 1 */
HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin); //HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin);
/* USER CODE END ETH_IRQn 1 */ /* USER CODE END ETH_IRQn 1 */
} }

View File

@ -17,6 +17,8 @@
/* TCA6416 I2C地址 */ /* TCA6416 I2C地址 */
#define TCA6416_ADDR 0x20 // 第一个芯片地址 (A0=A1=A2=GND) #define TCA6416_ADDR 0x20 // 第一个芯片地址 (A0=A1=A2=GND)
#define TCA6416_ADDR2 0x21 // 第二个芯片地址 (A0=1, A1=A2=GND) #define TCA6416_ADDR2 0x21 // 第二个芯片地址 (A0=1, A1=A2=GND)
#define TCA6416_ADDR3 0x20 // 第三个芯片地址 (与第二个芯片共用总线地址0x20)
/* 寄存器地址定义 */ /* 寄存器地址定义 */
#define TCA6416_INPUT_PORT0 0x00 // 输入端口0 #define TCA6416_INPUT_PORT0 0x00 // 输入端口0
@ -67,14 +69,19 @@
void TCA6416_GPIO_Init(void); void TCA6416_GPIO_Init(void);
uint8_t TCA6416_Init(void); uint8_t TCA6416_Init(void);
uint8_t TCA6416_Init2(void); // 第二个芯片的初始化函数 uint8_t TCA6416_Init2(void); // 第二个芯片的初始化函数
uint8_t TCA6416_Init3(void); // 第三个芯片的初始化函数
uint8_t TCA6416_WritePort(uint8_t port, uint8_t data); uint8_t TCA6416_WritePort(uint8_t port, uint8_t data);
uint8_t TCA6416_WritePort2(uint8_t port, uint8_t data); // 第二个芯片的写端口函数 uint8_t TCA6416_WritePort2(uint8_t port, uint8_t data); // 第二个芯片的写端口函数
uint8_t TCA6416_WritePort3(uint8_t port, uint8_t data); // 第三个芯片的写端口函数
uint8_t TCA6416_ReadPort(uint8_t port, uint8_t *data); uint8_t TCA6416_ReadPort(uint8_t port, uint8_t *data);
uint8_t TCA6416_ReadPort2(uint8_t port, uint8_t *data); // 第二个芯片的读端口函数 uint8_t TCA6416_ReadPort2(uint8_t port, uint8_t *data); // 第二个芯片的读端口函数
uint8_t TCA6416_ReadPort3(uint8_t port, uint8_t *data); // 第三个芯片的读端口函数
uint8_t TCA6416_SetPortDirection(uint8_t port, uint8_t direction); uint8_t TCA6416_SetPortDirection(uint8_t port, uint8_t direction);
uint8_t TCA6416_SetPortDirection2(uint8_t port, uint8_t direction); // 第二个芯片的设置方向函数 uint8_t TCA6416_SetPortDirection2(uint8_t port, uint8_t direction); // 第二个芯片的设置方向函数
uint8_t TCA6416_SetPortDirection3(uint8_t port, uint8_t direction); // 第三个芯片的设置方向函数
uint8_t TCA6416_SetPortPolarity(uint8_t port, uint8_t polarity); uint8_t TCA6416_SetPortPolarity(uint8_t port, uint8_t polarity);
uint8_t TCA6416_SetPortPolarity2(uint8_t port, uint8_t polarity); // 第二个芯片的设置极性函数 uint8_t TCA6416_SetPortPolarity2(uint8_t port, uint8_t polarity); // 第二个芯片的设置极性函数
uint8_t TCA6416_SetPortPolarity3(uint8_t port, uint8_t polarity); // 第三个芯片的设置极性函数
uint8_t TCA6416_WritePin(uint8_t port, uint8_t pin, uint8_t state); uint8_t TCA6416_WritePin(uint8_t port, uint8_t pin, uint8_t state);
uint8_t TCA6416_ReadPin(uint8_t port, uint8_t pin, uint8_t *state); uint8_t TCA6416_ReadPin(uint8_t port, uint8_t pin, uint8_t *state);

View File

@ -541,4 +541,132 @@ uint8_t TCA6416_SetPortPolarity2(uint8_t port, uint8_t polarity)
return 0; return 0;
} }
/* 第三个芯片的操作函数使用第二个芯片的I2C总线但地址为TCA6416_ADDR3 */
/**
* @brief TCA6416
* @retval 0: 1:
*/
uint8_t TCA6416_Init3(void)
{
// GPIO已在TCA6416_GPIO_Init()中初始化
// 增加延时以确保设备稳定
HAL_Delay(10);
// 默认将所有引脚设置为输入
if(TCA6416_SetPortDirection3(0, 0xFF) != 0) return 1;
if(TCA6416_SetPortDirection3(1, 0xFF) != 0) return 1;
// 设置默认输出值为0
if(TCA6416_WritePort3(0, 0x00) != 0) return 1;
if(TCA6416_WritePort3(1, 0x00) != 0) return 1;
// 设置默认极性(非反转)
if(TCA6416_SetPortPolarity3(0, 0x00) != 0) return 1;
if(TCA6416_SetPortPolarity3(1, 0x00) != 0) return 1;
return 0;
}
/**
* @brief TCA6416的端口写入数据
* @param port: 01
* @param data:
* @retval 0: 1:
*/
uint8_t TCA6416_WritePort3(uint8_t port, uint8_t data)
{
uint8_t reg_addr = (port == 0) ? TCA6416_OUTPUT_PORT0 : TCA6416_OUTPUT_PORT1;
I2C_Start2();
I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_SendByte2(reg_addr); // 寄存器地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_SendByte2(data); // 数据
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_Stop2();
return 0;
}
/**
* @brief TCA6416的端口读取数据
* @param port: 01
* @param data:
* @retval 0: 1:
*/
uint8_t TCA6416_ReadPort3(uint8_t port, uint8_t *data)
{
uint8_t reg_addr = (port == 0) ? TCA6416_INPUT_PORT0 : TCA6416_INPUT_PORT1;
I2C_Start2();
I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_SendByte2(reg_addr); // 寄存器地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_Start2();
I2C_SendByte2((TCA6416_ADDR3 << 1) | 0x01); // 读地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
*data = I2C_ReadByte2(); // 读取数据
I2C_NAck2();
I2C_Stop2();
return 0;
}
/**
* @brief TCA6416的端口方向
* @param port: 01
* @param direction: 0 = , 1 =
* @retval 0: 1:
*/
uint8_t TCA6416_SetPortDirection3(uint8_t port, uint8_t direction)
{
uint8_t reg_addr = (port == 0) ? TCA6416_CONFIG_PORT0 : TCA6416_CONFIG_PORT1;
I2C_Start2();
I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_SendByte2(reg_addr); // 寄存器地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_SendByte2(direction); // 方向设置
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_Stop2();
return 0;
}
/**
* @brief TCA6416的端口极性
* @param port: 01
* @param polarity: 0 = , 1 =
* @retval 0: 1:
*/
uint8_t TCA6416_SetPortPolarity3(uint8_t port, uint8_t polarity)
{
uint8_t reg_addr = (port == 0) ? TCA6416_POL_INV_PORT0 : TCA6416_POL_INV_PORT1;
I2C_Start2();
I2C_SendByte2(TCA6416_ADDR3 << 1); // 写地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_SendByte2(reg_addr); // 寄存器地址
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_SendByte2(polarity); // 极性设置
if(I2C_WaitAck2()) { I2C_Stop2(); return 1; }
I2C_Stop2();
return 0;
}

View File

@ -399,9 +399,11 @@ uint16_t handle_type_87(const uint8_t *body, uint16_t body_len, uint8_t *tx)
// 报文类型 // 报文类型
tx[8] = reply_type; tx[8] = reply_type;
// 填充TCA6416引脚状态到第9-10字节 // 填充地址为0x21的TCA6416芯片状态到第9-10字节
tx[9] = tca6416_port2_status; // 第二个TCA6416的Port0状态 // tx[9] = tca6416_port2_status; // 第二个TCA6416的Port0状态地址0x21外部端口8-15
tx[10] = tca6416_port3_status; // 第二个TCA6416的Port1状态 // tx[10] = tca6416_port3_status; // 第二个TCA6416的Port1状态地址0x21外部端口0-7
tx[9] = tca6416_port3_status; // 第二个TCA6416的Port0状态地址0x21外部端口0-7
tx[10] = tca6416_port2_status; // 第二个TCA6416的Port1状态地址0x21外部端口8-15
// 填充AD7124原始数据到tx[11]~tx[75]每通道4字节MSB格式 // 填充AD7124原始数据到tx[11]~tx[75]每通道4字节MSB格式
extern ad7124_analog_t ad7124_analog[AD7124_CHANNEL_EN_MAX]; extern ad7124_analog_t ad7124_analog[AD7124_CHANNEL_EN_MAX];

View File

@ -9,32 +9,32 @@ unsigned char tim_led_state = 0;
* *
* @param io LED灯的枚举值LED灯 * @param io LED灯的枚举值LED灯
*/ */
void leds_on(leds_e io) //void leds_on(leds_e io)
{ //{
switch (io) // switch (io)
{ // {
case LEDS2_RED: // case LEDS2_RED:
HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET);
break; // break;
case LEDS2_GREEN: // case LEDS2_GREEN:
HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET);
break; // break;
case LEDS2_YELLOW: // case LEDS2_YELLOW:
HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET);
break; // break;
case LEDS3_RED: // case LEDS3_RED:
HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET);
break; // break;
case LEDS3_GREEN: // case LEDS3_GREEN:
HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET);
break; // break;
case LEDS3_YELLOW: // case LEDS3_YELLOW:
HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET);
break; // break;
default: // default:
break; // break;
} // }
} //}
/** /**
* @brief LED灯 * @brief LED灯
@ -43,32 +43,32 @@ void leds_on(leds_e io)
* *
* @param io LED灯的枚举值 * @param io LED灯的枚举值
*/ */
void leds_off(leds_e io) //void leds_off(leds_e io)
{ //{
switch (io) // switch (io)
{ // {
case LEDS2_RED: // case LEDS2_RED:
HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET);
break; // break;
case LEDS2_GREEN: // case LEDS2_GREEN:
HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET);
break; // break;
case LEDS2_YELLOW: // case LEDS2_YELLOW:
HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET);
break; // break;
case LEDS3_RED: // case LEDS3_RED:
HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET);
break; // break;
case LEDS3_GREEN: // case LEDS3_GREEN:
HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET);
break; // break;
case LEDS3_YELLOW: // case LEDS3_YELLOW:
HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET);
break; // break;
default: // default:
break; // break;
} // }
} //}
/** /**
* @brief LED灯 * @brief LED灯
@ -78,30 +78,30 @@ void leds_off(leds_e io)
* GPIO端口和引脚上的电平设置为低电平GPIO_PIN_RESET * GPIO端口和引脚上的电平设置为低电平GPIO_PIN_RESET
* LED灯 * LED灯
*/ */
void leds_on_all(void) //void leds_on_all(void)
{ //{
HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET); // HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_RESET);
} //}
/** /**
* @brief LED灯 * @brief LED灯
* *
* LED灯关闭 * LED灯关闭
*/ */
void leds_off_all(void) //void leds_off_all(void)
{ //{
HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED2_R_GPIO_Port, LED2_R_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED2_G_GPIO_Port, LED2_G_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED2_Y_GPIO_Port, LED2_Y_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED3_R_GPIO_Port, LED3_R_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED3_G_GPIO_Port, LED3_G_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET); // HAL_GPIO_WritePin(LED3_Y_GPIO_Port, LED3_Y_Pin, GPIO_PIN_SET);
} //}
// void lan8720_reset(void) // void lan8720_reset(void)
// { // {