UART high-level api interrupt: how to receive data using isr ?

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

cross mob
SaGa_4641021
Level 4
Level 4
50 questions asked 50 replies posted 100 sign-ins

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
lock attach
Attachments are accessible only for community members.
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

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
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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