UART interrupt on Necto studio problem

General discussion on IDE.
Post Reply
Author
Message
sam.123.address@gmail.com
Posts: 11
Joined: 01 Aug 2023 15:25

UART interrupt on Necto studio problem

#1 Post by sam.123.address@gmail.com » 20 Apr 2024 16:51

Hello guys,

I have changed my ide from Mikroc pro for ARM to Necto studio as you know in the new ide things are a bit different.

So how can use UART RX interrupt?

Using mikrosdk is a bit complicated i have no idea how would anyone please help with that i will appreciate it?

Kind regards,

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: UART interrupt on Necto studio problem

#2 Post by IvanJeremic » 22 Apr 2024 09:39

Hi,

The LOG library uses UART interrupts.

So you can use it in your project.

Most of our click board examples use the LOG library, so you can check them out for more information on how to use this library.

Regards,

Ivan.

sam.123.address@gmail.com
Posts: 11
Joined: 01 Aug 2023 15:25

Re: UART interrupt on Necto studio problem

#3 Post by sam.123.address@gmail.com » 22 Apr 2024 11:14

Hello Ivan,

I wrote this simple code for RX interrupt in necto studio but it shows one error : "Interrupt handler redefined: UART1_IRQHandler at 0x00000035"

this is the code:

Code: Select all



//include files and opjects for UART
#include "MikroSDK.Driver.UART"
#include "drv_uart.h"
#include "board.h"
uart_t uart;
uart_config_t uart_cfg;
uint8_t uart_rx_buffer[256];
uint8_t uart_tx_buffer[256];
char uart1_tmp;   //tmp will store temprory received DATA(byte)
int result = 0;
char _uart1_data_ready;  //will be set if DATA is ready in buffer
unsigned int uart1_data_len; //determines the length of buffer


//initialization function of UART
void application_init_uart ( void )
{
    uart_configure_default( &uart_cfg );

    uart.tx_ring_buffer = uart_tx_buffer;
    uart.rx_ring_buffer = uart_rx_buffer;

    uart_cfg.rx_pin = PA10;
    uart_cfg.tx_pin = PA9;
    uart_cfg.tx_ring_size = sizeof( uart_tx_buffer );
    uart_cfg.rx_ring_size = sizeof( uart_rx_buffer );

    uart_open( &uart, &uart_cfg );
    uart_print( &uart, "Hello!" );
    uart_println( &uart, "This is a simple UART example!" );
    ///////////////////////////////////
    // enable uart rx interrupt
   USART1_CR1bits.RXNEIE = 1;
   interrupt_enable(IVT_INT_USART1); // enable interrupt vector
}

void UART1_Interrupt() iv IVT_INT_USART1 ics ICS_AUTO{

   result = uart_read( &uart, uart1_tmp, sizeof( uart1_tmp ) );
   //uart1_write(uart1_tmp);   //send back data read , uncomment for debugging

   if(uart1_tmp == '\n' || uart1_tmp == '\r') //IF  LF IS FOUND
   {
     if(uart1_data_len > 1)  //and if there is data
     {
       //send CR and LF, uncomment for debugging
       /*uart1_write(_CR);
       uart1_write(_LF);*/
       uart1_rx_buff[uart1_data_len] = '\0';    //MAKE LAST ELEMENT IN BUFFER AS NULL
       _uart1_data_ready = 1;    //SET DATA READY FLAG
     }
   }
   else  //otherwise read DATA in buffer
   {
      uart1_rx_buffer[uart1_data_len] = uart1_tmp;  //READ DATA IN BUFFER
      uart1_data_len++;     //INCREMENT COUNTER TO READ NEXT BYTE
   }
}
it's a simple test that works with mikroc pro for arm but here as shown it shows an error what is the solution i hope your help with kind regards.
Attachments
UART_INTERRUPT.rar
(2.58 MiB) Downloaded 6 times

sam.123.address@gmail.com
Posts: 11
Joined: 01 Aug 2023 15:25

Re: UART interrupt on Necto studio problem

#4 Post by sam.123.address@gmail.com » 23 Apr 2024 19:21

Hello i have looked at this example from Mikrosdk help examples it uses uart interrupts:

Code: Select all



/**
 * Any initialization code needed for MCU to function properly.
 * Do not remove this line or clock might not be set correctly.
 */
#ifdef PREINIT_SUPPORTED
#include "preinit.h"
#endif


//include files and opjects for UART
#include "MikroSDK.Hal.UART"
  
static hal_uart_t hal_uart;
 
// UART HAL config structure
static hal_uart_config_t hal_uart_cfg;
 
// Be careful to have large enough buffers
static uint8_t uart_rx_buffer[128];
 
// Be careful to have large enough buffers
static uint8_t uart_tx_buffer[128];

static size_t size;


//initialization function of UART
void application_init_uart ( void )
{
  
    // Fill structure with default values
    hal_uart_configure_default( &hal_uart_cfg );//uart_configure_default( &uart_cfg );

    // Specify desired UART RX pin
    hal_uart_cfg.rx_pin = PA10;
    
    // Specify desired UART TX pin
    hal_uart_cfg.tx_pin = PA9;
    
    // Declare buffer size
    hal_uart_cfg.tx_ring_size = sizeof(uart_tx_buffer);
    
    // Declare buffer size
    hal_uart_cfg.rx_ring_size = sizeof(uart_rx_buffer);
    
    if ( hal_uart_open( &hal_uart.handle, true ) == HAL_UART_ERROR )
    {
            // Error handling strategy
    }

}

int main(void)
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif

    application_init_uart ();

    while (1)
    {
       size = hal_uart_println( &hal_uart.handle, "Hello!" ); // Print out "Hello!" with new line every second.
       Delay_ms(1000);
    }

    return 0;
}

-The program compiles with no errors but in the UART terminal it doesn't display any message ! even though i tried check all the wiring and connections with the pc and mcu but with no success!.

-Second how can i use interrupt receive on rx pin ?

please MikroE team i have been trying for almost three days with no success please any help i have searched also Mikrosdk help but it doesn't contain any working example. I have also attached the project folder.

kind regards,
Sam
Attachments
UART_INTERRUPT.rar
(2.54 MiB) Downloaded 8 times

Post Reply

Return to “IDE General”