This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Configuring CC3200 UART-1 Interrupt

Other Parts Discussed in Thread: CC3200

Hello,

I want to configure the UART1 interrupt for receiving data.

But, i am unable to find an example in the CC3200 SDK that demonstrates the interrupt based UART1 communication.

Kindly help me out with UART1 interrupt example.

Warm regards,

Abhishek.

  • Hi Abhishek,

    We don't have an example which uses the UART1 in interrupt mode. However we have couple of examples "udma" and "uart_dma" that use UART0 in interrupt mode. You can use that as reference.

    Thanks and Regards,
    Siddaram
  • Hello Siddaram,

    Thank you for your reply.

    I referred to both the applications.

    The UART interrupt handler of uart_demo is

    static void UARTIntHandler()
    {
        if(!bRxDone)
        {
            MAP_UARTDMADisable(UARTA0_BASE,UART_DMA_RX);
            bRxDone = true;
        }
        else
        {
            MAP_UARTDMADisable(UARTA0_BASE,UART_DMA_TX);
        }

        MAP_UARTIntClear(UARTA0_BASE,UART_INT_DMATX|UART_INT_DMARX);
    }

    Where exactly am i getting the received byte??


    The example is a bit complicated. I just need to receive data on UART-1 interrupt and store it.

    Can you help me with that ??

    Thanks and regards,

    Abhishek.

  • Hello all,
    Actually i have written the code as follows:

    #define CONSOLE1 UARTA1_BASE
    #define CONSOLE_PERIPH1 PRCM_UARTA1

    //UART-1 Initialization
    MAP_PRCMPeripheralReset(CONSOLE_PERIPH1);

    MAP_UARTConfigSetExpClk(CONSOLE1,MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH1),
    UART_BAUD_RATE,(UART_CONFIG_WLEN_8 |
    UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    //MAP_UARTDMADisable(CONSOLE1,UART_DMA_RX+UART_DMA_TX+UART_DMA_ERR_RXSTOP); //disable dma
    MAP_UARTFIFODisable(CONSOLE1); //disable fifo





    /here we will configure the UART-1 interrupt based communication
    MAP_UARTIntRegister(CONSOLE1,UART1_Handler); //enable interrupts
    MAP_UARTIntEnable(CONSOLE1,UART_INT_DMARX | UART_INT_DMATX);




    And the Handler is written as:
    void UART1_Handler()
    {
    while(( UARTData = UARTCharGetNonBlocking(CONSOLE1) ) != -1)
    {
    UARTDataBuffer[UARTDataCount] = UARTData;
    UARTDataCount++;

    if(UARTDataCount > 10)
    {UARTDataFlag = 1;}
    }
    }

    Can anybody please verify if this is correct, or any changes to be done ??
    That will be really helpful.

    Thank you in advance.

    Warm regards,
    Abhishek.
  • Hi Abhishek,

    From the above post I assume you are not interested in DMA transfer but only want to receive data on UART interrupt.

    In that case, you need to use UART_INT_RX|UART_INT_RT instead of UART_INT_DMATX|UART_INT_DMARX. This will generate interrupt on each character you receive on UART (when FIFO is disabled).

    Also you should clear the interrupt from with in the handler using UARTIntClear(CONSOLE1, UART_INT_RX|UART_INT_RT) API call.

    Thanks and Regards,
    Praveen
  • Hello Praveen,
    Thank you for replying.

    I have disabled the FIFO.
    So my interrupt handler will look like this now...

    void UART1_Handler()
    {

    UARTIntClear(CONSOLE1, UART_INT_RX|UART_INT_RT);

    while(( UARTData = UARTCharGetNonBlocking(CONSOLE1) ) != -1)
    {
    UARTDataBuffer[UARTDataCount] = UARTData;
    UARTDataCount++;

    if(UARTDataCount > 10)
    {UARTDataFlag = 1;}
    }

    UARTIntEnable(CONSOLE1, UART_INT_RX|UART_INT_RT);

    }

    Is this correct ??
    Kindly reply.

    Regards,
    Abhishek.
  • Yes, that looks OK.

    Best Regards,
    Praveen
  • Hello Praveen,
    Thank you very much for helping out.

    What changes do i need to make to enable the TX interrupt also??
    What changes should i make in the void UART1_Handler() ??

    Kindly reply.

    Warm regards,
    Abhishek.
  • Hello Praveen,

    Should i call the unsigned long UARTIntStatus(unsigned long ulBase, tBoolean bMasked) function from the void UART1_Handler() to determine whether it is TX or RX interrupt ??

    Please reply.

    Warm regards,
    Abhishek.
  • Dear Praveen,
    If possible, please reply to my query.
    That will help me complete my code.

    Thank you in advance.

    Warm regards,
    Abhishek.
  • Abhishek,

    Yes you can use UARTIntStatus(unsigned long ulBase, tBoolean bMasked) API in the interrupt handler to determine whether it is TX or RX interrupt

    Thanks and Regards,
    Praveen
  • Hello Praveen,
    Thank you very much for helping out.
    I will update my code and post here.

    Warm regards,
    Abhishek.
  • Dear Praveen,

    This is my UART-1 interrupt handler.
    Please check whether it is correct, and suggest necessary changes.


    void UART1_Handler()
    {
    UART_STATUS = UARTIntStatus(CONSOLE1, 0);

    if((UART_STATUS & UART_INT_RX) == UART_INT_RX)
    {
    while(( UARTData = UARTCharGetNonBlocking(CONSOLE1) ) != -1)
    {
    UARTDataBuffer[UARTDataCount] = UARTData;
    UARTDataCount++;

    if(UARTDataCount > 10)
    {UARTDataFlag = 1;}
    }
    }

    if((UART_STATUS & UART_INT_TX) == UART_INT_TX)
    {
    //Transmit tasks
    }


    MAP_UARTIntClear(CONSOLE1, UART_INT_RX|UART_INT_TX);

    }

    Regards,
    Abhishek.
  • Hello,

    I referred to the uart_dma example from the SDK and managed to configure the UART interrupt without the DMA.

    I have given a stream of data as input to the UART, but i am getting the UART interrupt only once.

    Here is my interrupt handler...

    void UART1_Handler()
    {
      UART_STATUS = 0;

        UART_STATUS = UARTIntStatus(CONSOLE1, 0);

        if((UART_STATUS & UART_INT_RX) == UART_INT_RX)
        {
          UARTData = UARTCharGet(CONSOLE1);

          UARTDataBuffer[UARTDataCount] =  UARTData;
          UARTDataCount++;

          if(UARTDataCount >= UART_BUFF_LEN)
            {
             UARTDataCount = 0;
             UARTDataFlag = 1;
             }
        }

        if((UART_STATUS & UART_INT_TX) == UART_INT_TX)
        {


        }
        MAP_UARTIntClear(CONSOLE1, UART_INT_RX|UART_INT_TX);
    }

    Have i cleared the interrupts correctly ??

    Kindly help !!

    Regards,

    Abhishek.

  • Hello all,

    I am still unable to configure the UART-1 interrupt without using DMA mode.

    Atleast provide me with an example which shows the interrupt based UART communication.

    Awaiting an answer.

    Regards,

    Abhishek.

  • Abhishek,

    I don't see any issue with you interrupt handler. Can you share the complete code ?

    Best Regards,
    Praveen
  • Hello Praveen,
    Thank you very much for replying...

    Here's my complete code...

    int main(void)
    {
    lRetVal = -1;

    //Board Initialization
    BoardInit();

    //
    // Initialize the uDMA
    //
    UDMAInit();

    //Pin Configuration
    PinMuxConfig();

    //Change Pin 58 Configuration from Default to Pull Down
    /*MAP_PinConfigSet(PIN_58,PIN_STRENGTH_2MA|PIN_STRENGTH_4MA,PIN_TYPE_STD_PD);*/

    //Change Pin 63 Configuration from Default to Pull Down
    MAP_PinConfigSet(PIN_63,PIN_STRENGTH_2MA|PIN_STRENGTH_4MA,PIN_TYPE_STD_PU);

    //Button_IF_Init(GPIOs3IntHandler);

    //
    // Initialize GREEN and ORANGE LED
    //
    //GPIO_IF_LedConfigure(LED1|LED2|LED3);
    //Turn Off the LEDs
    //GPIO_IF_LedOff(MCU_ALL_LED_IND);

    //UART-1 Initialization
    MAP_PRCMPeripheralReset(CONSOLE_PERIPH1);

    MAP_UARTConfigSetExpClk(CONSOLE1,MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH1),
    UART_BAUD_RATE,(UART_CONFIG_WLEN_8 |
    UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    MAP_UARTFIFODisable(CONSOLE1); //disable fifo

    //Display Application Banner on UART Terminal
    //DisplayBanner(APPLICATION_NAME);

    //
    // Creating a queue for Machine_IP_Config.
    //
    xPrintQueue =xQueueCreate( 2, sizeof( Machine_IP_Config ) );

    if( xPrintQueue == 0 )
    {
    // Queue was not created and must not be used.
    return 0;
    }


    //
    // Creating a queue for Server_IP_Config.
    //
    xPrintQueue1 =xQueueCreate( 2, sizeof( Server_IP_Config ) );

    if( xPrintQueue1 == 0 )
    {
    // Queue was not created and must not be used.
    return 0;
    }


    //
    // Creating a queue for Profile_Config.
    //
    xPrintQueue2 =xQueueCreate( 2, sizeof( Profile_Config ));

    if( xPrintQueue2 == 0 )
    {
    // Queue was not created and must not be used.
    return 0;
    }

    //
    // Creating a queue for Profile_Config.
    //
    xPrintQueue3 =xQueueCreate( 2, sizeof( Machine_Info ));

    if( xPrintQueue3 == 0 )
    {
    // Queue was not created and must not be used.
    return 0;
    }

    //
    // Simplelinkspawntask
    //
    lRetVal = VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    if(lRetVal < 0)
    {
    //UART_PRINT("Unable to start simpelink spawn task\n\r");
    LOOP_FOREVER();
    }

    //
    // Create HTTP Server Task
    //
    lRetVal = osi_TaskCreate(HTTPServerTask, (signed char*)"HTTPServerTask",
    OSI_STACK_SIZE, NULL, OOB_TASK_PRIORITY, NULL );
    if(lRetVal < 0)
    {
    //UART_PRINT("Unable to create task\n\r");
    LOOP_FOREVER();
    }

    //
    // Start OS Scheduler
    //
    osi_start();

    while (1)
    {

    }

    }




    void UART1_Handler()
    {
    UART_STATUS = 0;

    UART_STATUS = UARTIntStatus(CONSOLE1, 0);

    MAP_UARTIntClear(CONSOLE1, UART_INT_RX);

    if((UART_STATUS & UART_INT_RX) == UART_INT_RX)
    {
    UARTData = UARTCharGet(CONSOLE1);

    UARTDataBuffer[UARTDataCount] = UARTData;
    UARTDataCount++;

    if(UARTDataCount >= UART_BUFF_LEN)
    {
    UARTDataCount = 0;
    UARTDataFlag = 1;
    }
    }

    /*if((UART_STATUS & UART_INT_TX) == UART_INT_TX)
    {


    }*/

    MAP_UARTIntEnable(CONSOLE1, UART_INT_RX);
    }





    ...........
    /tcp_socket tasks

    lRetVal = ConfigureSimpleLinkToDefaultState();

    if(lRetVal < 0)
    {
    if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
    //UART_PRINT("Failed to configure the device in its default state \n\r");

    LOOP_FOREVER();
    }

    //UART_PRINT("Device is configured in default state \n\r");


    lRetVal = sl_Start(0, 0, 0);
    if (lRetVal < 0)
    {
    //UART_PRINT("Failed to start the device \n\r");
    LOOP_FOREVER();
    }

    //UART_PRINT("Device started as STATION \n\r");


    //UART_PRINT("Connecting to AP: %s ...\r\n",Profile_Config.SSID);

    // Connecting to WLAN AP - Set with static parameters defined at common.h
    // After this call we will be connected and have IP address
    lRetVal = WlanConnect();
    if(lRetVal < 0)
    {
    //UART_PRINT("Connection to AP failed \n\r");
    LOOP_FOREVER();
    }

    //UART_PRINT("Connected to AP: %s \n\r",Profile_Config.SSID);

    /*UART_PRINT("Device IP: %d.%d.%d.%d\n\r\n\r",
    SL_IPV4_BYTE(Machine_IP_Config.ipV4,3),
    SL_IPV4_BYTE(Machine_IP_Config.ipV4,2),
    SL_IPV4_BYTE(Machine_IP_Config.ipV4,1),
    SL_IPV4_BYTE(Machine_IP_Config.ipV4,0));*/

    /*UART_PRINT("Default settings: SSID Name: %s, PORT = %d, Packet Count = %d, "
    "Destination IP: %d.%d.%d.%d\n\r",
    Profile_Config.SSID, g_uiPortNum, g_ulPacketCount,
    SL_IPV4_BYTE(Server_IP_Config.ServerIP,3),
    SL_IPV4_BYTE(Server_IP_Config.ServerIP,2),
    SL_IPV4_BYTE(Server_IP_Config.ServerIP,1),
    SL_IPV4_BYTE(Server_IP_Config.ServerIP,0));*/

    //here we will configure the UART-1 interrupt based communication
    MAP_UARTIntRegister(CONSOLE1,UART1_Handler); //enable interrupts
    MAP_UARTIntEnable(CONSOLE1,UART_INT_RX);

    // open socket here
    BsdTcpClient(g_uiPortNum);
    ..................

    Kindly reply.

    Warm regards,
    Abhishek.
  • Abhishek,

    Please give me sometime to go through your code, will get back to you.

    Thanks and Regards,
    Praveen
  • Hello Praveen,
    Thank you so much for your help.

    Should i post my complete code as well ??

    Regards,
    Abhishek.
  • Abhishek,

    There is a similar post on UART1 + Interrupts with a very similar use case you have: e2e.ti.com/.../1378751

    Please try to write a simple test code to understand the code flow for UART1 + Interrupts. Then integrate that with your complete code you posted above.

    Thanks and Regards,
    Praveen
  • Ok Praveen,
    I will do that and refer to the link and get back to you...

    Thanks and regards,
    Abhishek.
  • Hello all,

    I want to configure the UART-1 without using the DMA operation.

    I want to receive single byte from the UART and store it.

    I have referred to the uart and udma examples from the SDK, but they use the DMA.

    Please provide me with an example which demonstrates the interrupt-based UART1 communication without DMA.

    Thank you in advance.

    Regards,

    Abhishek.

  • Hi Abhishek,

    Please refer the file uart_if.c which has the common UART driver which doesn't use DMA. This uses UART0 but the functionality is same for UART1 as well.

    Thanks and Regards,
    Siddaram
  • Hi Abhishek,

    In the below thread with one of the user code and some additional inputs UART in interrupt mode was working. Please see if this helps.
    e2e.ti.com/.../1378751

    Thanks and Regards,
    Siddaram
  • Hello Siddaram,

    Thank you for replying.

    I will check the link and implement the UART-1 interrupt and get back.

    Warm regards,

    Abhishek.

  • Hello Siddaram,

    I implemented the above code.

    But i was getting the UART-1 interrupt only once.

    So i enabled the interrupt in the handler, and it is working fine now.

    Here's my routine...

    void UART1_Handler()

    {

     UART_STATUS = 0;

       UART_STATUS = UARTIntStatus(CONSOLE1, true);

       MAP_UARTIntClear(CONSOLE1, UART_INT_RX);

       if((UART_STATUS & UART_INT_RX) && MAP_UARTCharsAvail(CONSOLE1))

       {

         UARTData = (unsigned char)MAP_UARTCharGetNonBlocking(CONSOLE1);

         UARTDataBuffer[UARTDataCount] =  UARTData;

         UARTDataCount++;

         if(UARTDataCount > 400)

         {

           UARTDataFlag = 1;

         }

         if(UARTDataCount > 1000)

         {

           UARTDataCount = 0x00;

         }

       }

       MAP_UARTIntEnable(CONSOLE1, UART_INT_RX);

    //Interrupt enabled again

    }

    Is is necessary to enable the interrupt again in the handler...

    Kindly reply.

    Warm regards,

    Abhishek.

  • Hello Praveen,

    I implemented the above code.

    But i was getting the UART-1 interrupt only once.

    So i enabled the interrupt in the handler, and it is working fine now.

    Here's my routine...

    void UART1_Handler()

    {

    UART_STATUS = 0;

      UART_STATUS = UARTIntStatus(CONSOLE1, true);

      MAP_UARTIntClear(CONSOLE1, UART_INT_RX);

      if((UART_STATUS & UART_INT_RX) && MAP_UARTCharsAvail(CONSOLE1))

      {

        UARTData = (unsigned char)MAP_UARTCharGetNonBlocking(CONSOLE1);

        UARTDataBuffer[UARTDataCount] =  UARTData;

        UARTDataCount++;

        if(UARTDataCount > 400)

        {

          UARTDataFlag = 1;

        }

        if(UARTDataCount > 1000)

        {

          UARTDataCount = 0x00;

        }

      }

      MAP_UARTIntEnable(CONSOLE1, UART_INT_RX);            //Interrupt enabled again

    }

    Is is necessary to enable the interrupt again in the handler...

    Kindly reply.

    Warm regards,

    Abhishek.

  • Abhishek,

    That's very strange. The interrupt will remain enabled until one explicitly calls MAP_UARTIntDisable() with appropriate parameters.

    Thanks and Regards,
    Praveen
  • Hello Praveen,
    Can you please simulate the above code on your side and check ??
    That would make things more clear for us.

    Regards,
    Abhishek.
  • Hi Abhishek,

    Sure. Let me check, will get back to you.

    Thanks and Regards,
    Praveen
  • Abhishek,


    I am not able to recreate your issue. Here is my complete code.

    #include "hw_types.h"
    #include "hw_memmap.h"
    #include "hw_ints.h"
    #include "rom.h"
    #include "rom_map.h"
    #include "prcm.h"
    #include "uart.h"
    #include "interrupt.h"
    #include "pin.h"
    
    unsigned long UART_STATUS;
    unsigned long UARTDataFlag;
    unsigned char UARTDataBuffer[1024];
    unsigned char UARTData;
    unsigned long UARTDataCount;
    
    #define CONSOLE1                UARTA1_BASE
    #define CONSOLE_PERIPH1         PRCM_UARTA1
    #define UART_BAUD_RATE          115200
    
    
    //*****************************************************************************
    //                 GLOBAL VARIABLES -- Start
    //*****************************************************************************
    #if defined(ccs)
    extern void (* const g_pfnVectors[])(void);
    #endif
    #if defined(ewarm)
    extern uVectorEntry __vector_table;
    #endif
    
    void UART1_Handler()
    
    {
    
      UART_STATUS = 0;
    
      UART_STATUS = UARTIntStatus(CONSOLE1, true);
    
      MAP_UARTIntClear(CONSOLE1, UART_INT_RX);
    
      if((UART_STATUS & UART_INT_RX) && MAP_UARTCharsAvail(CONSOLE1))
    
      {
    
        UARTData = (unsigned char)MAP_UARTCharGetNonBlocking(CONSOLE1);
    
        UARTDataBuffer[UARTDataCount] =  UARTData;
    
        UARTDataCount++;
    
        if(UARTDataCount > 400)
    
        {
    
          UARTDataFlag = 1;
    
        }
    
        if(UARTDataCount > 1000)
    
        {
    
          UARTDataCount = 0x00;
    
        }
    
      }
    }
    
    
    //*****************************************************************************
    //
    //! Board Initialization & Configuration
    //!
    //! \param  None
    //!
    //! \return None
    //
    //*****************************************************************************
    static void
    BoardInit(void)
    {
    /* In case of TI-RTOS vector table is initialize by OS itself */
    #ifndef USE_TIRTOS
        //
        // Set vector table base
        //
    #if defined(ccs)
        MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
    #endif
    #if defined(ewarm)
        MAP_IntVTableBaseSet((unsigned long)&__vector_table);
    #endif
    #endif
    
        //
        // Enable Processor
        //
        MAP_IntMasterEnable();
        MAP_IntEnable(FAULT_SYSTICK);
    
        PRCMCC3200MCUInit();
    }
    
    void main()
    {
    
      PinModeSet(PIN_55,PIN_MODE_6);
      PinModeSet(PIN_57,PIN_MODE_6);
    
      BoardInit();
    
      //UART-1 Initialization
      MAP_PRCMPeripheralClkEnable(CONSOLE_PERIPH1,PRCM_RUN_MODE_CLK);
    
      MAP_UARTConfigSetExpClk(CONSOLE1,MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH1),
      UART_BAUD_RATE,(UART_CONFIG_WLEN_8 |
      UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
      MAP_UARTFIFODisable(CONSOLE1); //disable fifo
    
      MAP_UARTIntRegister(CONSOLE1,UART1_Handler); //enable interrupts
      MAP_UARTIntEnable(CONSOLE1,UART_INT_RX);
    
      MAP_UARTCharPut(CONSOLE1,'c');
    
      while(1)
      {
    
      }
    }

    Thanks and Regards,

    Praveen

  • Hello Praveen,
    On my side, the code doesn't work if i don't enable the interrupt in the handler.

    The differences between your and my code is that you have used pins 55&57 for UART-1 while i have used pins 58&59, and i have added the statement MAP_UARTFlowControlSet(UARTA1_BASE, UART_FLOWCONTROL_NONE);.

    Does that make any difference ??

    As long as my code is working, Is there any harm in enabling the interrupt in the handler again ??
    Will it skip some samples or give me wrong results ??

    Regards,
    Abhishek.

  • Abhishek,

    I don't see any issue with pins 58&59 either.

    Skipping samples/data will depend on how fast your code can service the interrupt.

    Thanks and Regards,
    Praveen
  • Hello Praveen,
    I checked my samples on the hyper-terminal and it seems i am not missing any samples.

    Thank you for your expert advice and guidance.

    Looking forward for the same assistance in future.

    Thank you.

    Warm regards,
    Abhishek.
  • Hello Praveen,
    I had one question.
    After configuring the UART, is it necessary to put a character on the UART to initiate the transfer and start getting RX interrupts e.g. MAP_UARTCharPut(CONSOLE1,'c'); as shown by you ??

    Kindly reply.

    Warm regards,
    Abhishek.
  • No there is no such need, I was just testing whether rest of my configurations are correct.

    Thanks and Regards,
    Praveen
  • Hello,
    Why would anyone want to disable the FIFO's? What is the benefit out of this?
    Thanks in advance,
    Nick