我目前正在开发一个涉及 PSoC6 微控制器并使用 Modustoolbox 开发环境的项目。 我遇到了一些技术问题,希望您能协助解决,以确保我的项目顺利进行。
我正试图使用作为工具箱一部分提供的 HAL 库,通过 GPIO 引脚实现两个微控制器之间的 UART
通信。 我使用
"cyhal_uart_write"函数成功传输了一个数据数组。 但是,当我尝试使用
"cyhal_uart_read "函数接收数据时, ,我遇到了一些问题。 在接收部分,我没有使用任何中断。 我的项目的主要脚本附在下面。
/*****************************
xml-ph-0000@deepl.internal ******************************
xml-ph-0001@deepl.internal ********************
。
******************************
xml-ph-0000@deepl.internal ******************************
xml-ph-0001@deepl.internal *******************/
#include"rtc.h"
#include"rtc.h"
/*****************************
xml-ph-0000@deepl.internal ******************************
xml-ph-0001@deepl.internal ********************
* 全局变量
******************************
xml-ph-0000@deepl.internal ******************************
xml-ph-0001@deepl.internal *******************/
#defineDATA_BITS_8 8
#defineSTOP_BITS_1 1
#defineBAUD_RATE 115200
#defineUART_DELAY 10u
#defineRX_BUF_SIZE 4
#defineTX_BUF_SIZE 4
/*****************************
xml-ph-0000@deepl.internal ******************************
xml-ph-0001@deepl.internal ********************
* 函数名称:主函数
******************************
xml-ph-0000@deepl.internal ******************************
xml-ph-0001@deepl.internal *********************
* 摘要:
* 这是 CPU 的主要功能。 它...
* 1.
* 2.
*
* 参数:
* 无效
*
* 返回:
* int
*
******************************
xml-ph-0000@deepl.internal ******************************
xml-ph-0001@deepl.internal *******************/
int main(void)
{
wwd_result_t result;
cyhal_uart_tuart_obj;
uint32_t ocp_cur;
uint8_ttx_buf[TX_BUF_SIZE] = { '1', '2','3','4'};
uint8_trx_buf[RX_BUF_SIZE];
size_t tx_length = TX_BUF_SIZE;
size_trx_length = RX_BUF_SIZE;
uint32_tvalue ='A';
// 初始化 UART 配置结构
const cyhal_uart_cfg_tuart_config =
{
.data_bits = DATA_BITS_8、
.stop_bits = STOP_BITS_1、
.parity =CYHAL_UART_PARITY_NONE、
.rx_buffer = rx_buf、
.rx_buffer_size = RX_BUF_SIZE
};
#ifdefined (CY_DEVICE_SECURE)
cyhal_wdt_t wdt_obj;
/* 清除 看门狗定时器,使其不会触发复位 */
result = cyhal_wdt_init( wdt_obj, cyhal_wdt_get_max_
timeout_ms());
CY_ASSERT(CY_RSLT_SUCCESS == result);
cyhal_wdt_free( wdt_obj);
#endif
/* 初始化设备和
电路板外设 */
result = cybsp_init();
// 初始化 UART 块
result = cyhal_uart_init( uart_obj,CYBSP_DEBUG_UART_TX,CYBSP_DEBUG_UART_RX,NC,NC,NULL、
uart_config);
// 设置波特率
result = cyhal_uart_set_baud( uart_obj, BAUD_RATE, actualbaud);
/* 板 启动失败。停止程序执行 */
如果(result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
/* 启用全局中断 */
__enable_irq ();
为(;;)
{
// 开始 Tx传输
cyhal_uart_write( uart_obj,(void*)tx_buf, tx_length);
cyhal_system_delay_ms(UART_DELAY);
// 开始 Rx传输
cyhal_uart_read( uart_obj,(void*)rx_buf, rx_length);
cyhal_system_delay_ms(UART_DELAY);
}
}
在调试这段代码时,执行在'cyhal_uart_read'处暂停。
cyhal_uart_read函数处暂停执行。我遇到的确切错误如下:
由于这个错误,我无法继续操作。 我无法准确接收我传送的数据。