公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

通过固件控制 PSoC 4 系列芯片的 UART Tx 和 Rx 管脚 – KBA224950 (ZH)

通过固件控制 PSoC 4 系列芯片的 UART Tx 和 Rx 管脚 – KBA224950 (ZH)

Community-Team
Employee
Employee
50 questions asked 10 questions asked 5 questions asked

Version: **

通过固件控制PSoC 4系列芯片的UART TxRx管脚 – KBA224950

问题: 对于PSoC® 4系列芯片,在运行过程中,怎样通过固件控制UART TxRx管脚?

答案:

在这篇文章中,您将掌握如何动态的改变SCB_UART Tx Rx管脚的功能。下文列出了在固件中控制管脚的原因,提供了在固件中控制管脚的步骤,用代码片段展示了如何用API实现所建议的解决方案。

固件控制UART TxRx引脚的用例:

  1. UART Rx引脚可能对噪声敏感,然而在RX引脚上启用内部上拉电阻可以解决此噪声敏感问题。
  2. 在半双工和全双工模式之间切换时,可以将TxRx引脚配置为GPIO,并在不使用SCB UART时在固件中进行控制。

固件方案:

通常情况下,管脚可以被固件或者硬件控制。默认情况下,UART接口的管脚是被SCB硬件模块控制的,所以必须将分配给UARTPin脚从SCB IP上断开,才能使能固件控制。

下面的步骤是描述如何将Tx/Rx Pins SCB IP断开以及如何使能固件控制:

  1. HSIOM_PORT_SELx 寄存器中对应Tx/Rx Pinbit位置"0"
  2. 通过固件设置Tx/Rx Pin脚的驱动模式。

更多的细节,参考Architecture Technical Reference Manual (TRM) I/O HSIOM)部分。

1:用固件控制Rx 管脚

示例将UART_Tx UART_Rx pin 分别设为P0.1P0.0

// Variable to store the default SCB_UART configuration settings

uint32 temp;

// Save the HSIOM configuration for SCB_UART

temp = CY_GET_REG32 (CYREG_HSIOM_PORT_SEL0);

// Configure UART_Rx pin to be controlled in firmware

CY_SET_REG32 (CYREG_HSIOM_PORT_SEL0, CY_GET_REG32 (CYREG_HSIOM_PORT_SEL0) & 0xFFFFFFF0);

// Set the drive mode of UART Rx pin

UART_pin_SetDriveMode(UART_pin_DM_RES_UP);

// Place your application code here

// Load the default UART functionality (i.e) Rx pin is connected to SCB block

CY_SET_REG32 (CYREG_HSIOM_PORT_SEL0, temp);

2:在全双工模式和半双工模式之间切换

示例将UART_Tx UART_Rx pin 分别设为P0.1P0.0


// Variable to store the default SCB_UART configuration settings

uint32 temp;

// Save the HSIOM duplex configuration for SCB_UART

temp = CY_GET_REG32 (CYREG_HSIOM_PORT_SEL0);

// UART Tx only mode

// Configure UART_Rx pin to be controlled in firmware

CY_SET_REG32 (CYREG_HSIOM_PORT_SEL0, CY_GET_REG32 (CYREG_HSIOM_PORT_SEL0) & 0xFFFFFFF0);

// Set the drive mode of UART Rx pin

UART_pin_SetDriveMode(UART_pin_DM_RES_UP);

// Place your application code here for UART Tx only mode of operation

// Load the default full duplex UART functionality (i.e) Rx pin is connected to SCB block

CY_SET_REG32 (CYREG_HSIOM_PORT_SEL0, temp);

// UART Rx only mode

// Configure UART_Tx pin to be controlled in firmware

CY_SET_REG32 (CYREG_HSIOM_PORT_SEL0, CY_GET_REG32 (CYREG_HSIOM_PORT_SEL0) & 0xFFFFFF0F);

// Set the drive mode of UART Tx pin

UART_pin_SetDriveMode(UART_pin_DM_RES_UP);

// Place your application code here for UART Rx only mode of operation

// Load the default full duplex UART functionality (i.e) Tx pin is connected to SCB block

sCY_SET_REG32 (CYREG_HSIOM_PORT_SEL0, temp);

0 点赞
745 次查看
贡献者