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

PSoC™ 6 Forum Discussions

SaGa_4641021
Level 4
Level 4
100 sign-ins 50 sign-ins 25 replies posted

Hi

How can I create UART ISR to respond to data received using high-level api ?

in low-level, I would write the isr and include for example:

if((UART_HW->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk ) != 0)

{..... }

How can do the same using high-level api ?

0 Likes
4 Replies
Aashita_Raj
Moderator
Moderator
Moderator
100 solutions authored 250 replies posted 250 sign-ins

Hi @SaGa_4641021 ,

Can you please elaborate your application? You can go through the link provided here : Cypress Peripheral Driver Library: UART (SCB) and under the section "Configure Interrupt", you can find the code snippets that are easy to understand as well as implement.

Also, We have a code example "UART_Using_High_Level_APIs", which I have attached here. You can through it for your reference and modify it according to your application.

Please let us know your comments and in case of further clarifications.

Best Regards.

Aashita

 

 

 

 

 

0 Likes

Hi Aashita

I am trying to use ISR with high-level API. So I learnt that I have to use callbacks. I couldn't find instructions for how to write callbacks.

Do you have any sample code to share ?

thanks

0 Likes

Hi @SaGa_4641021 ,

As shared by @MotooTanaka , you can make use of  his sample code to begin with. However, we regret to inform you that we presently do not have code examples in MTB 2.2 that can provide you the flow to write  callbacks. 

You can make use of the code snippets ,which you can find on the links already shared above in my previous response to start off your application.

Best Regards,

Aashita

 

0 Likes
MotooTanaka
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Hi,

While back, I posted a sample program "MCU Tester"

https://community.cypress.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-062-BL...

In tty_utils.c I wrote

(ISR)

==================

void tty_rx_isr(void)
{
uint8_t c ;
/* Check for "RX fifo not empty interrupt" */
if((UART_HW->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk ) != 0)
{
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
c = Cy_SCB_UART_Get(UART_HW);
if ((c != 0) && (c != 0xFF)) {
rx_buf[rx_write_index] = c ;
rx_write_index = (rx_write_index + 1) % RX_BUF_LEN ;
}
}
}

==================

(call back assign)

==================

void tty_init(int current_core)
{
if (current_core == USE_CM4) {
/* tty_rx_int */
const cy_stc_sysint_t tty_rx_int_cfg = {
.intrsrc=(IRQn_Type)tty_rx_int__INTC_NUMBER,
.intrPriority = tty_rx_int__INTC_CORTEXM4_PRIORITY
};
} else if (current_core == USE_CM0P) {
/* tty_rx_int */
const cy_stc_sysint_t tty_rx_int_cfg = {
.intrsrc=(IRQn_Type)tty_rx_int__INTC_NUMBER,
.intrPriority = tty_rx_int__INTC_CORTEXM0P_PRIORITY
};
}

Cy_SysInt_Init(&tty_rx_int_cfg, tty_rx_isr) ;
NVIC_ClearPendingIRQ(tty_rx_int_cfg.intrSrc) ;
NVIC_EnableIRQ((IRQn_Type)tty_rx_int_cfg.intrSrc) ;

UART_initVar = 0 ;
UART_Start() ;
}

==================

Since the program allows to switch cores to use, I needed to write code for both cm0+ and cm4.

moto

0 Likes