Not able to get the UART interrupt to work

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Not able to get the UART interrupt to work

Jump to solution
1,903 Views
viveksrinivasan
Contributor I

Hello everyone,

First of all, I'm using the following board and OS,

                                   Board :     twrk65f180m

                                   OS     :     MQX

I'm trying to get the interrupt to work for my UART. I'm trying to use UART2 for my application.

Without interrupt, I can send data successfully. After I enable the interrupt, I can see that the interrupt is happening. It goes to _int_default_isr(void   *vector_number) in int.c file. Where the vector number reads 0x33 which is the vector number of INT_UART2_RX_TX in the vector table. The interrupt keeps happening continuously which I believe because the interrupt is not serviced. But the weird thing here is that the interrupt starts happening even before I send the data. Is this right?

My second problem is, I want to redirect the interrupt to my own ISR which I tried to do by using _int_install_isr. But the interrupt still goes to _int_default_isr. I'm not sure if I'm doing something wrong.

Below is my code  :

                                                       PORTE_PCR17 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin

                                                       PORTE_PCR16 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin    

 

                                                      uart_init (UART2_BASE_PTR, 60000, 115200); 

   

                                                      UART_C2_REG(UART2_BASE_PTR) |= UART_C2_TIE_MASK;

                                                      UART_C2_REG(UART2_BASE_PTR) |= UART_C2_TCIE_MASK;

   

                                                     _nvic_int_init(INT_UART2_RX_TX, 2, TRUE);

   

                                                     nvic_int_enable(INT_UART2_RX_TX);

   

                                                    _int_install_isr(INT_UART2_RX_TX, CLX_Tx_ISR_Handler_Debug, NULL);

Also, I don't see any examples for UART with interrupts. Can anyone direct me to a UART example using interrupt with MQX?

Your help is much appreciated. Thank you.

Regards,

Vivek

0 Kudos
Reply
1 Solution
1,528 Views
RadekS
NXP Employee
NXP Employee

Hi Vivek,

Few basic points:

1. Please disable at least one of (I)TTYC drivers. It has no sense enable both polling and interrupt drivers for the same UART. If you want use interrupt MQX driver, please set BSPCFG_ENABLE_ITTYC macro and clear BSPCFG_ENABLE_TTYC.

2.It is probably bad idea to combine MQX serial driver with your interrupt routine. This could work only in case when your interrupt routine will contain the same code as drivers ISR and maybe something additional. It is what you want?

If you want use your own UART driver, please clear both BSPCFG_ENABLE_ITTYC BSPCFG_ENABLE_TTYC macros (these macros enabling MQX serial driver).

3. Almost all interrupts in MQX are serviced by default interrupt routine and this routine call ISR function which is installed by _int_install_isr(). If you want manage interrupt routine out of MQX, you have to use int_install_kernel_isr() function when vector table is in RAM. Or modify directly vectors.c when vector table is in flash. Additionally you should call _bsp_int_init() for enabling this interrupt and set priority. Of course, since MQX do not know about this interrupt, you mustn't call MQX API in your routine.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
6 Replies
1,528 Views
viveksrinivasan
Contributor I

To add further to my message above, I have the following settings enabled in user_config.h.

#define BSPCFG_ENABLE_TTYC       1  /* OpenSDA use uart2 */

#define BSPCFG_ENABLE_ITTYC      1

0 Kudos
Reply
1,529 Views
RadekS
NXP Employee
NXP Employee

Hi Vivek,

Few basic points:

1. Please disable at least one of (I)TTYC drivers. It has no sense enable both polling and interrupt drivers for the same UART. If you want use interrupt MQX driver, please set BSPCFG_ENABLE_ITTYC macro and clear BSPCFG_ENABLE_TTYC.

2.It is probably bad idea to combine MQX serial driver with your interrupt routine. This could work only in case when your interrupt routine will contain the same code as drivers ISR and maybe something additional. It is what you want?

If you want use your own UART driver, please clear both BSPCFG_ENABLE_ITTYC BSPCFG_ENABLE_TTYC macros (these macros enabling MQX serial driver).

3. Almost all interrupts in MQX are serviced by default interrupt routine and this routine call ISR function which is installed by _int_install_isr(). If you want manage interrupt routine out of MQX, you have to use int_install_kernel_isr() function when vector table is in RAM. Or modify directly vectors.c when vector table is in flash. Additionally you should call _bsp_int_init() for enabling this interrupt and set priority. Of course, since MQX do not know about this interrupt, you mustn't call MQX API in your routine.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,528 Views
viveksrinivasan
Contributor I

Hi RadekS,

Thanks a lot for your suggestions.

I have got the default UART (ittyc) to work.

For our project we need two UARTs. One UART(ittyc) we use it for our debugger (to print debug messages) and the other UART (ittyd) (with flow control) we use it to communicate with the bluetooth module.

I got the default UART (ittyc) working by doing the following.

1. Set BSPCFG_ENABLE_ITTYC to 1 in user_config.h

2. Setting BSP_DEFAULT_IO_CHANNEL to  "ittyc:"  in twrk65f180m.h file

3. Then I used the returned file pointer to Write and Read to the UART.

But to open the other UART (ittyd) I called the _io_fopen function

_io_fopen((char *)"ittyd", (char *)NULL);

But it returns NULL. Am I missing something here. I'm setting BSPCFG_ENABLE_ITTYD to 1 in user_config.h file.

Your help is much appreciated. Thanks.

Regards,

Vivek

0 Kudos
Reply
1,528 Views
viveksrinivasan
Contributor I

Hi RadekS,

I'm so sorry. That was so stupid of me to make a mistake there to open the port. I missed a ':' there. I can open the port now.

Thank you.

Regards,

Vivek

0 Kudos
Reply
1,528 Views
RadekS
NXP Employee
NXP Employee

Thank you for notification.

I am glad that it works now.

Have a great day,
RadekS

0 Kudos
Reply
1,528 Views
albertolubeiro
Contributor III

Hi RadekS,

I am workig with KDS 3.0 and KSDK1.2.0 and over MQX

I am working with UART1 and UART3 on a K64 device.

Both UART are configured in the same way but curiously UART3 sends data and UART1 doesn't. The fact is that when data must be sent through UART1, the interrupt is not triggered.

// Initialize variable uartState of type uart_state_t

    uart_state_t uartState;

    uart_state_t uartState1;

    // Fill in uart config data

    uart_user_config_t uartConfig = {

        .bitCountPerChar = kUart8BitsPerChar,

        .parityMode      = kUartParityDisabled,

        .stopBitCount    = kUartOneStopBit,

        .baudRate        = 115200

    };

    uart_user_config_t uartConfig1 = {

        .bitCountPerChar = kUart8BitsPerChar,

        .parityMode      = kUartParityDisabled,

        .stopBitCount    = kUartOneStopBit,

        .baudRate        = 115200

    };

    CLOCK_SYS_EnablePortClock(PORTA_IDX);

    CLOCK_SYS_EnablePortClock(PORTB_IDX);

    CLOCK_SYS_EnablePortClock(PORTC_IDX);

    CLOCK_SYS_EnablePortClock(PORTD_IDX);

    CLOCK_SYS_EnablePortClock(PORTE_IDX);

    BOARD_ClockInit();

    //UART3

    GPIO_DRV_Init(eco_uart_input_pins, eco_uart_output_pins);

    PORT_HAL_SetMuxMode(PORTC,16u,kPortMuxAlt3);

    PORT_HAL_SetMuxMode(PORTC,17u,kPortMuxAlt3);

    GPIO_DRV_SetPinOutput(PTC18);     //RTS

    GPIO_DRV_SetPinOutput(PTC19);     //CTS

    //UART1

    GPIO_DRV_Init(eco_wifi_input_pins, eco_wifi_output_pins);

    PORT_HAL_SetMuxMode(PORTE,0u,kPortMuxAlt3);

    PORT_HAL_SetMuxMode(PORTE,1u,kPortMuxAlt3);

    GPIO_DRV_SetPinOutput(PTE3);     //RTS

    GPIO_DRV_SetPinOutput(PTE2);     //CTS

    // Initialize the uart module with base address and config structure

    UART_DRV_Init(BOARD_DEBUG_UART_INSTANCE, &uartState, &uartConfig);     //Uart3

    UART_DRV_Init(1, &uartState1, &uartConfig1);     //Uart1

Now it is suposed that they are ready to send and receive data, but only UART3 works fine and only its interrupt is triggered.

Please, find attached the file for more datails.

Any help will be apreciated.

Thanks and regards

0 Kudos
Reply