UART0的HART可以数据收发

This commit is contained in:
王绪洁 2025-03-12 15:14:33 +08:00
parent b626cbb446
commit 8a52221917
10 changed files with 4139 additions and 4039 deletions

View File

@ -5,6 +5,7 @@
"string.h": "c",
"user_fmsc.h": "c",
"fsmc.h": "c",
"ch438q.h": "c"
"ch438q.h": "c",
"ht1200m.h": "c"
}
}

View File

@ -176,10 +176,13 @@ void start_ch438_task(void const *argument)
{
/* USER CODE BEGIN start_ch438_task */
/* Infinite loop */
ch438_init();
for (;;)
{
uint8_t data[5] = {0xFF, 0x34, 0x56, 0x78, 0x9a};
ch438_test();
osDelay(1);
ch438_send_data(CH438_UART0, data, 5);
osDelay(1000);
}
/* USER CODE END start_ch438_task */
}

View File

@ -27,7 +27,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "ht1200m.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -64,9 +64,9 @@ void MX_FREERTOS_Init(void);
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
@ -86,7 +86,7 @@ int main(void)
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
@ -95,7 +95,8 @@ int main(void)
MX_SPI1_Init();
MX_FSMC_Init();
/* USER CODE BEGIN 2 */
hart_ht1200m_reset(); // 初始化HT1200M模块
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); // PWM输出用于驱动HT1200M模块
/* USER CODE END 2 */
/* Call init function for freertos objects (in freertos.c) */
@ -116,22 +117,22 @@ int main(void)
}
/**
* @brief System Clock Configuration
* @retval None
*/
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
@ -146,9 +147,8 @@ void SystemClock_Config(void)
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
@ -165,19 +165,20 @@ void SystemClock_Config(void)
/* USER CODE END 4 */
/**
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM4 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
* @brief Period elapsed callback in non blocking mode
* @note This function is called when TIM4 interrupt took place, inside
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
* a global variable "uwTick" used as application time base.
* @param htim : TIM handle
* @retval None
*/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
/* USER CODE END Callback 0 */
if (htim->Instance == TIM4) {
if (htim->Instance == TIM4)
{
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */
@ -186,9 +187,9 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
}
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
@ -200,14 +201,14 @@ void Error_Handler(void)
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */

View File

@ -148,19 +148,41 @@
<Name>-U090F00028316303030303032 -O2254 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407ZGTx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint/>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>184</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134258924</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>../Core/Src/freertos.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\valve_debugging\../Core/Src/freertos.c\184</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>reg_data</ItemText>
</Ww>
<Ww>
<count>1</count>
<WinNumber>1</WinNumber>
<ItemText>pSrcBuffer</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1>
<Mm>
<WinNumber>1</WinNumber>
<SubType>0</SubType>
<ItemText>0x60000000</ItemText>
<ItemText>pSrcBuffer</ItemText>
<AccSizeX>0</AccSizeX>
</Mm>
</MemoryWindow1>
@ -180,7 +202,7 @@
<periodic>1</periodic>
<aLwin>1</aLwin>
<aCover>0</aCover>
<aSer1>1</aSer1>
<aSer1>0</aSer1>
<aSer2>0</aSer2>
<aPa>0</aPa>
<viewmode>1</viewmode>
@ -1806,7 +1828,7 @@
<GroupNumber>10</GroupNumber>
<FileNumber>126</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\User\driver\ch438q.c</PathWithFileName>
@ -1814,6 +1836,18 @@
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
<File>
<GroupNumber>10</GroupNumber>
<FileNumber>127</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\User\driver\ht1200m.c</PathWithFileName>
<FilenameWithoutPath>ht1200m.c</FilenameWithoutPath>
<RteFlg>0</RteFlg>
<bShared>0</bShared>
</File>
</Group>
<Group>
@ -1824,7 +1858,7 @@
<RteFlg>0</RteFlg>
<File>
<GroupNumber>11</GroupNumber>
<FileNumber>127</FileNumber>
<FileNumber>128</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>

View File

@ -6605,6 +6605,11 @@
<FileType>1</FileType>
<FilePath>..\User\driver\ch438q.c</FilePath>
</File>
<File>
<FileName>ht1200m.c</FileName>
<FileType>1</FileType>
<FilePath>..\User\driver\ht1200m.c</FilePath>
</File>
</Files>
</Group>
<Group>

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
#include "ch438q.h"
#include "fsmc.h"
#include "ht1200m.h"
#define CH438_CLK 1843200 /* CH438的内部时钟频率默认外部晶振的12分频 */
const uint8_t offsetadd[] = {
@ -113,7 +113,7 @@ void ch438_test(void)
reg_data[2] = ch438_read_reg(offsetadd[0] | REG_IER_ADDR, 1);
reg_data[3] = ch438_read_reg(offsetadd[0] | REG_IIR_ADDR, 1);
reg_data[4] = ch438_read_reg(offsetadd[0] | REG_LSR_ADDR, 1);
reg_data[4] = ch438_read_reg(offsetadd[0] | REG_LCR_ADDR, 1);
}
/**
@ -203,7 +203,11 @@ void ch438_init_config(uint8_t uart_num)
void ch438_send_data(uint8_t uart_num, uint8_t *data, uint16_t len)
{
ch438_write_reg(offsetadd[uart_num] | REG_THR_ADDR, data[0], len);
HART1_RTS_SEND;
for (uint8_t i = 0; i < len; i++)
{
ch438_write_reg(offsetadd[uart_num] | REG_THR_ADDR, data[i], 1);
}
}
uint8_t ch438_recv_data(uint8_t uart_num, uint8_t *data)
@ -258,6 +262,7 @@ void ch438_interrupt_handler(void)
case INT_NOINT: /* 没有中断 */
break;
case INT_THR_EMPTY: /* THR空中断 */
HART1_RTS_RECEIVE;
break;
case INT_RCV_OVERTIME: /* 接收超时中断 */
receive_data_len = ch438_recv_data(i, receive_data_buff);
@ -279,3 +284,11 @@ void ch438_interrupt_handler(void)
}
}
}
void ch438_init(void)
{
ch438_reset_all_uart();
HAL_Delay(250);
ch438_init_uart(CH438_UART0, 1200);
ch438_init_config(CH438_UART0);
}

View File

@ -133,4 +133,5 @@ void ch438_init_config(uint8_t uart_num);
void ch438_send_data(uint8_t uart_num, uint8_t *data, uint16_t len);
uint8_t ch438_recv_data(uint8_t uart_num, uint8_t *data);
void ch438_interrupt_handler(void);
void ch438_init(void);
#endif

View File

@ -13,11 +13,8 @@
*/
extern void hart_ht1200m_reset(void)
{
HART1_RESET_ON;
HART2_RESET_ON;
HART_RESET_ON;
HAL_Delay(10);
HART1_RESET_OFF;
HART2_RESET_OFF;
HART_RESET_OFF;
HART1_RTS_RECEIVE;
HART2_RTS_RECEIVE;
}

View File

@ -3,17 +3,14 @@
#include "main.h"
#define HART1_RESET_ON HAL_GPIO_WritePin(HART1_RST_GPIO_Port, HART1_RST_Pin, GPIO_PIN_RESET) // 拉低引脚复位模块
#define HART1_RESET_OFF HAL_GPIO_WritePin(HART1_RST_GPIO_Port, HART1_RST_Pin, GPIO_PIN_SET)
#define HART2_RESET_ON HAL_GPIO_WritePin(HART2_RST_GPIO_Port, HART2_RST_Pin, GPIO_PIN_RESET) // 拉低引脚复位模块
#define HART2_RESET_OFF HAL_GPIO_WritePin(HART2_RST_GPIO_Port, HART2_RST_Pin, GPIO_PIN_SET)
#define HART_RESET_ON HAL_GPIO_WritePin(HART_ALL_RST_GPIO_Port, HART_ALL_RST_Pin, GPIO_PIN_RESET) // 拉低引脚复位模块
#define HART_RESET_OFF HAL_GPIO_WritePin(HART_ALL_RST_GPIO_Port, HART_ALL_RST_Pin, GPIO_PIN_SET)
#define HART1_RTS_RECEIVE HAL_GPIO_WritePin(HART1_RTS_GPIO_Port, HART1_RTS_Pin, GPIO_PIN_SET)
#define HART1_RTS_SEND HAL_GPIO_WritePin(HART1_RTS_GPIO_Port, HART1_RTS_Pin, GPIO_PIN_RESET) // 拉低引脚发送
#define HART2_RTS_RECEIVE HAL_GPIO_WritePin(HART2_RTS_GPIO_Port, HART2_RTS_Pin, GPIO_PIN_SET)
#define HART2_RTS_SEND HAL_GPIO_WritePin(HART2_RTS_GPIO_Port, HART2_RTS_Pin, GPIO_PIN_RESET) // 拉低引脚发送
// #define HART2_RTS_RECEIVE HAL_GPIO_WritePin(HART2_RTS_GPIO_Port, HART2_RTS_Pin, GPIO_PIN_SET)
// #define HART2_RTS_SEND HAL_GPIO_WritePin(HART2_RTS_GPIO_Port, HART2_RTS_Pin, GPIO_PIN_RESET) // 拉低引脚发送
extern void hart_ht1200m_reset(void);
#endif